0

大家好,我正在制作一个记忆游戏,它是一个 4x4 棋盘,您单击图块以显示下面的内容,您必须找到相应的图片。我在鼠标单击并将它们分配给guess1 和guess2 背后的逻辑时遇到问题。

Joption 面板是我测试猜测 1 和猜测 2 是否注册的方式。每次guess1都能正常工作,但我不知道如何让第二个猜测起作用这是我的尝试。

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");
    }
    }
4

2 回答 2

0

而(鼠标点击)

这看起来很糟糕。它要么意味着您要么没有释放 UI 线程来获得第二次点击,要么您正在非 UI 线程中调用图形操作。

于 2012-04-26T18:11:24.440 回答
0

尝试这个

 boolean guess2Flag;    
 if (mouseClicked)
{

    if(!guess2Flag) 
    {
    centerClick(x1,y1);
    guess1 = board[row][column];
    board[row][column] = board[x1][y1];
    guess1 = board[x1][y1];
    JOptionPane.showInputDialog(guess1 + "this is guess1");
    guess2Flag = true;
    setColor(g);
    centerHit(xMouse, yMouse);
    g.fillOval(xMouse, yMouse, 40, 40);
    mouseClicked = false;
    }

    else if (guess2Flag)
    {
    centerClick(x1,y1);
    guess2 = board[row][column];
    board[row][column] = board[x1][y1];
    guess2 = board[x1][y1];
    JOptionPane.showInputDialog(guess2 + "this is guess2");
    guess2Flag = false;
    mouseClicked = false;
    }
}
于 2012-04-26T18:15:02.410 回答