记忆游戏在比赛后显示结果

时间:2015-12-13 00:00:03

标签: java arrays

我试图在匹配后显示结果,但在第三次点击事件后进行比较:

(this.aHracieTlactika[i] == e.getSource())

我希望在第二次点击事件后进行比较。

    private int aPocitadlo = 1;

这是检查两个数组匹配的方法:

    public boolean zhoda() {
            if (this.aHodnotaTlac[0] == this.aHodnotaTlac[1]) {
                return true;
            }
            return false;
        }


    public void actionPerformed(ActionEvent e) {
    int pom = 0;
    for (int i = 0; i < this.aHracieTlactika.length; i++) {

                if (this.aHracieTlactika[i] == e.getSource()) {
                    this.aHracieTlactika[i].setText("" + this.aHodnoty.get(i));
                    this.aHracieTlactika[i].setEnabled(false);
                    this.aPocitadlo++;
                    this.aPocetTahov += 1;

                    if (this.aPocitadlo == 3) {

                        if (this.zhoda()) {

                            this.aHracieTlactika[this.aTlacitkoIden[0]].setEnabled(false);
                            this.aHracieTlactika[this.aTlacitkoIden[1]].setEnabled(false);
pom += 1;    
  if (pom == 1) {
      System.out.println("You win");
                        }                             
                        } else {

                            this.aHracieTlactika[this.aTlacitkoIden[0]].setEnabled(true);
                            this.aHracieTlactika[this.aTlacitkoIden[0]].setText("");
                            this.aHracieTlactika[this.aTlacitkoIden[1]].setEnabled(true);
                            this.aHracieTlactika[this.aTlacitkoIden[1]].setText("");     
                        }

                        this.aPocitadlo = 1;

                    }

                     if (this.aPocitadlo == 1) {
                        this.aTlacitkoIden[0] = i;
                        this.aHodnotaTlac[0] = this.aHodnoty.get(i);
                    }

                    if (this.aPocitadlo == 2) {
                        this.aTlacitkoIden[1] = i;
                        this.aHodnotaTlac[1] = this.aHodnoty.get(i);
                    }  
            }
        }

1 个答案:

答案 0 :(得分:0)

保留一个全局clickCount变量,每当有人单击该按钮时,该变量就会递增。然后说if(clickCount%2 == 0)当点击计数可以被2整除时返回true。