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