我试图确保在我的记忆游戏中,一旦一个人选择了两张牌。它们是可见的,一旦他们选择了第三张卡,前两张卡就不再可见了。
以下是我对ActionPerformed方法的实现。
public void actionPerformed(ActionEvent e){
cardsSelected++;
int row=0;
int column=0;
int row2=0;
int column2=0;
if(cardsSelected == 3){
card1.setSelected(false);
card2.setSelected(false);
card1 = null;
card2 = null;
cardsSelected = 1;
}
if(card1 == null){
card1 = (Cell) e.getSource();
card1.setSelected(true);
row = card1.getRow();
column = card1.getColumn();
board[row][column].setIcon2();
}
else if(card2 == null){
card2 = (Cell) e.getSource();
card2.setSelected(true);
row = card2.getRow();
column = card2.getColumn();
board[row][column].setIcon2();
}
if(card1 != null && card2 != null){
numTries++;
if(card1.sameType(card2) ){
row = card1.getRow();
column = card1.getColumn();
row2 = card2.getRow();
column2 = card2.getRow();
if(row != row2 && column != column2){
board[row][column].setVisible(false);
board[row2][column2].setVisible(false);
card1=null;
card2=null;
}
}
}
}
非常欢迎任何见解! 谢谢大家! Mjall2