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;
}
在底部附近的空'else'語句上可能會有另外兩個編譯錯誤。如果你解決這些問題有什麼改變嗎? (例如,將{}放在它們後面)編譯器可能會對您的方法中的重要內容感到困惑。 – 2012-01-15 20:56:35
這實際上解決了這個問題!謝謝!我想知道爲什麼我沒有想到這件事...... ^^; – frozenxdreamer 2012-01-15 21:03:17
@RussellZahniser你應該發佈這個答案,以便他可以接受它。 – 2012-01-15 21:41:57