你应该看看我关于更改玩家号码的问题。我认为这正是您正在寻找的东西(或类似的东西):Java:更改玩家编号
本质上,我使用了一个布尔数组来跟踪谁还在玩,其中数组索引对应于玩家编号 a[0] = 玩家 0,a[1] = 玩家 1 等。如果玩家被淘汰,则标记相应的索引带假:a[i] = false;
然后您可以使用以下方法(取自我的问题)将玩家编号切换到下一个仍在玩的玩家:
public static int switchPlayer(int currentPlayer, boolean[] playerList) {
// if the current player + 1 = length (size) of array,
// start back at the beginning and find the first player still playing
if(currentPlayer + 1 == playerList.length) {
for(int i = 0; i < playerList.length; i++) {
if(playerList[i] == true) { // if player is still in the game
currentPlayer = i; // currentPlayer = current index of array
break;
}
}
}
// otherwise the current player number + 1 is not at the end of the array
// i.e. it is less than the length (size) of the array, so find the next player
// still playing
else {
for(int i = (currentPlayer+1); i < playerList.length; i++) {
if(playerList[i] == true) {
currentPlayer = i;
break;
}
}
}
return currentPlayer;
}
如果您对我的代码等有任何疑问,请告诉我。