Hey everyone. I'm trying to make a Java Swing memory game program and I'm quite stuck when it comes to making the Computer be a player.
This is the code for the GamePanel where I check if the two cards chosen are the same or not (starts on Line 90).
Note: I have removed some stuff like imports etc to make the code a bit smaller.
Right now if start the program and successfully make pairs(when it's the Player's turn) it works normally. Computer chooses 2 random cards, if they're a pair they're replaced with the Empty image. Otherwise, they're flipped back to normal. If I make a wrong pair though all cards get flipped and the game is unplayable.
I know this is a lot I'm asking, but I'm getting pretty desperate right here. Some guidance would be greatly appreciated.
Anyway, thanks in advance for your time. If there are parts that aren't clear enough let me know.
Thank you for posting nicely indented code, but please leave the imports in the code; then readers can copy and paste the code and run it immediately.
I am afraid I think you have gone round this the wrong way. I think you should have a version of the game that you can run from the terminal/command line, and only write the GUI as a display when that is working.
Don't use Strings for difficulty. Use an enum instead.
Never write == true or == false. Both are poor style and error‑prone if you write = by mistake.
boolean b = ...; Never if (b == false) ... Always if (!b) ... Never if (b == true) ... Always if (b) ... Don't use setXXX() and getXXX() methods like that. It isn't object‑oriented to add scores like that. Write a scorePoints() method and call player.scorePoints(10);