0
我正在嘗試爲我的文本遊戲創建一個贏條件。我有兩種方法可以決定一個球員是否建立了勝利或失敗的標準。這些方法在一個類中,而我想在我的控制器類中使用它們。該變量是hitTimes和nonHits:將變量從類方法傳遞到另一個類
的Class1:
if(choiceC > 0 || choiceR > 0)
{
Character currentCharacter;
currentCharacter= grid[choiceR][choiceC];
gameBoard[choiceR][choiceC] = currentCharacter;
loseTest(currentCharacter);
winTest(currentCharacter);
}
}
}
}
public int loseTest(Character currentCharacter)
{
int hitTimes = 0;
if(currentCharacter.minePresent == true)
{
hitTimes = 1;
}
return hitTimes;
}
public int winTest(Character currentCharacter)
{
int nonHits = 0;
if(currentCharacter.minePresent == false)
{
nonHits++;
}
return nonHits;
}
等級2:
Grid grid = new Grid();
double notMines = grid.notMine;
View view = new View();
result = grid.toString();
view.display(result);
final int ITERATIONS = 13;
final int numGames = 1000;
for (int i=0;i <= numGames; i++)
{
while (hitTimes != 1 || nonHits != notMines)
{
grid.runGame();
result2 = grid.toString();
view.display(result2);
if(nonHits == ITERATIONS)
{
System.out.println("You Win!");
}
if(hitTimes == 1)
{
System.out.println("You Lose!");
}
}
}
什麼問題? –
你想要使用什麼變量?什麼是第一類名字? – user2277872