如何查看谁赢了比赛?

时间:2015-11-09 00:40:59

标签: java

我有一个游戏,让玩家从行李中挑选代币,直到行李空了,最后一个从任何行李中挑选一个代币的玩家获胜。但我不确定如何判断谁获胜。

我的代码基本上是:

while (the game hasn't finished){
    Player 1 goes and then player 2 etc until the last token is drawn from the bag
}

我该如何检查最后一位谁?

1 个答案:

答案 0 :(得分:0)

如果没有一些代码,提供特定帮助并不可行。但是你想要做的是在你的主循环中添加一些逻辑

currentPlayer = player1;
while (the game is not over) {
   currentPlayer draws;
   if (bag is empty) {
     currentPlayer wins;
     break;
   }
   if (currentPlayer is player1) { currentPlayer = player2; }
   else { currentPlayer = player1;
}
相关问题