-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTourney.java
77 lines (75 loc) · 1.82 KB
/
Tourney.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.util.*;
public class Tourney{
LinkedList<Player> players;
LinkedList<Player> active;
LinkedList<Round> rounds;
String format;
String description;
int roundNum, playerId;
public Tourney(){
players = new LinkedList<Player>();
playerId = 0;
}
public boolean startTournament(){
if(players.stream().count() > 3){
active = players;
Collections.shuffle(active);
rounds = new LinkedList<Round>();
roundNum = 1;
rounds.add(new Round(roundNum, active));
return true;
} else {
return false;
}
}
public boolean roundFinished(){
if(rounds.get(roundNum - 1).roundFinished()){
return true;
} else {
return false;
}
}
public void nextRound(){
Collections.shuffle(active);
rounds.add(new Round(++roundNum, active));
}
public boolean finishMatch(int table, int win, int loss, int draw){
return rounds.get(roundNum - 1).finishMatch(table, win, loss, draw);
}
public void registerPlayer(String name){
players.add(new Player(name, ++playerId));
}
public void removePlayer(int id){
if(id != -1) players.remove(players.stream().filter(a -> a.getId() == id).iterator().next());
}
public void dropPlayer(int id){
if(id != -1) active.remove(active.stream().filter(a -> a.getId() == id).iterator().next());
}
public LinkedList<Player> getPlayers(){
return players;
}
public LinkedList<Player> getActive(){
return active;
}
public Round getRound(){
return rounds.get(roundNum-1);
}
public int numOfPlayers(){
int sum = 0;
for(Player p : active){
sum++;
}
return sum;
}
//DEBUG CODE
public void printPlayers(){
Iterator<Player> plit = players.stream().iterator();
while(plit.hasNext()){
Player pl = plit.next();
System.out.println("Player name: " + pl.getName() + " ID: " + pl.getId());
}
}
public void printMatches(){
rounds.get(roundNum-1).printMatches();
}
}