2012-01-15 119 views
0

我正在嘗試檢查棋子是否合法。當我使用它正在檢查的變量時,我爲每個循環使用了一次(僅一次),它給了我一個'無法解決的錯誤'。我在這發生的地方粗體顯示。誰能幫忙? (是的,我知道這些代碼還沒有完成,我試圖擺脫這種錯誤的第一次。)沒有身體爲什麼在此代碼中出現「無法解決」錯誤?

public boolean isLegal(Location loc1) 
{ 
    String currentColor = currentPlayer.getColor(); 
    boolean isLegal = false; 
    int row = loc1.getRow(); 
    int col = loc1.getCol(); 
    if(board.isValid(loc1)) 
    { 
     if(board.get(loc1) == null) 
     { 
      for(Location tempLoc : board.getValidAdjacentLocations(loc1)) 
      { 
       if(!board.get(tempLoc).equals(currentColor)) 
       { 
        int tempRow = tempLoc.getRow(); 

        if((row != tempLoc.getRow()) && (col == tempLoc.getCol())) 
        { 
         //count up column 
         if(**tempLoc.getRow()** < row) 
         { 
          for(int i = row; i > 1;) 
          { 
           Location tempLoc2 = new Location(i-2, col); 
           if(!board.get(tempLoc2).equals(currentColor)) 
           { 
            i--; 
           } 
           else 
           { 
            i=-1; 
            isLegal = true; 
           } 
          } 
         } 
         //count down column 
         else 
         { 
          for(int i = row; i < 6;) 
          { 
           Location tempLoc2 = new Location(i+2, lcol); 
           if(!board.get(tempLoc2).equals(currentColor)) 
           { 
            i++; 
           } 
           else 
            i=9; 
           isLegal = true; 
          } 
         } 
        } 
        else if(col != tempLoc.getCol() && row == tempLoc.getRow()) 
        { 
         //count left/right row 
         if(col > tempLoc.getCol()) 
         { 

         } 
         else 
        } 
        else 
        { //count up/right & down/left diag 
         if(1!=0) 
         { 

         } 
         //count up/left & down/right diag 
         else 
        } 
       } 
      } 
     } 
    } 
    return isLegal; 
} 
+0

在底部附近的空'else'語句上可能會有另外兩個編譯錯誤。如果你解決這些問題有什麼改變嗎? (例如,將{}放在它們後面)編譯器可能會對您的方法中的重要內容感到困惑。 – 2012-01-15 20:56:35

+0

這實際上解決了這個問題!謝謝!我想知道爲什麼我沒有想到這件事...... ^^; – frozenxdreamer 2012-01-15 21:03:17

+0

@RussellZahniser你應該發佈這個答案,以便他可以接受它。 – 2012-01-15 21:41:57

回答

0

的「其他人」語句在你的代碼的底部撲朔迷離編譯器瞭解循環內什麼是重要的。如果你修復這個錯誤,另一個就會消失。

相關問題