Hey everybody I’m making a memory game where it’s a 4×4 board and you click the tiles to reveal what’s underneath and you have to find the corresponding picture. I’m having trouble with the logic behind the mouse clicking and assigning them to a guess1 and guess2.
the Joption panel is how I’m testing to see if guess 1 and guess 2 register. Every time guess1 works fine, but I don’t know how to make the second guess work
Here is my attempt.
public void displayHit(Graphics g)
{
//earlier on in the code mouseClicked provides the x and y indexes for the place where you click
if (mouseClicked)
{
//method I coded to assign whereever you clicked on the 400x400 board to match the 4x4 array
centerClick(x1,y1);
guess1 = board[row][column];
board[row][column] = board[x1][y1];
guess1 = board[x1][y1];
JOptionPane.showInputDialog(guess1 + "this is guess1");
guess2 = -1;
setColor(g);
centerHit(xMouse, yMouse);
g.fillOval(xMouse, yMouse, 40, 40);
mouseClicked = false;
if ((guess2 == -1) && (mouseClicked))
{
centerClick(x1,y1);
guess2 = board[row][column];
board[row][column] = board[x1][y1];
guess2 = board[x1][y1];
JOptionPane.showInputDialog(guess2 + "this is guess2");
}
}
Try this