嘿,即時通訊嘗試創建一個隨機的方式,從鏈表中選擇一個4人組,並想知道這個代碼是否可以工作。從列表中創建一個球員隊伍
下面有一個示例代碼
public static void enterGame(Client c) {
int n = teamSize;
boolean startNewGame = false;
if(waitingPlayers.size() <= 3) {
return; // not enough players
}
startNewGame = true;
if(startNewGame) {
System.out.println("Starting new game");
for(int i=0; i<n; i++) {
Collections.shuffle(waitingPlayers);
System.out.println("Picking random player");
waitingPlayers.remove(c);
System.out.println("removing from random player list");
players.add(c);
System.out.println("adding player to ingame list");
}
}
}
歡迎來到Stack Overflow!請不要在未來的其他地方發佈您的代碼。另外,請閱讀[FAQ](http://stackoverflow.com/faq)。 –