-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurnOrderManager.cs
36 lines (32 loc) · 1.26 KB
/
TurnOrderManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace liveorlive_server {
public class TurnOrderManager {
public string CurrentTurn {
get {
if (this.currentTurnIndex < 0) {
return "";
}
return this.turnOrder[this.currentTurnIndex];
}
}
private List<string> turnOrder = []; // Usernames
private int currentTurnIndex = -1;
public void Populate(List<Player> players) {
this.turnOrder = players.Where(player => player.inGame == true).Select(player => player.username).ToList();
}
public void Advance() {
this.currentTurnIndex = (this.currentTurnIndex + 1) % this.turnOrder.Count;
}
public void EliminatePlayer(string username) {
int index = this.turnOrder.IndexOf(username);
if (index != -1) {
this.turnOrder.RemoveAt(index);
if (index < this.currentTurnIndex) {
this.currentTurnIndex--;
} else if (index == this.currentTurnIndex) {
// If the current player is eliminated, adjust to the next player's turn
this.currentTurnIndex %= this.turnOrder.Count;
}
}
}
}
}