2015-12-13 118 views
0

后,我想比赛结束后,显示的结果,但它第三次点击事件发生后进行比较:记忆游戏显示结果匹配

(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); 
        } 
      } 
     } 
+0

请问您可以重新配置吗? –

回答

0

记住,你增加每次点击的按钮全局的clickCount变量。然后说如果(clickCount%2 == 0)当点击数可以被2整除时返回true。