Repository navigation
Expand file tree
/
Copy pathTournament.java
More file actions
163 lines (130 loc) · 4.18 KB
/
Copy pathTournament.java
File metadata and controls
163 lines (130 loc) · 4.18 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import java.util.ArrayList;
import java.util.List;
public class Tournament {
private String name;
private List<Team> teams = new ArrayList<>();
private List<Match> matches = new ArrayList<>();
private List<Matchweek> matchweek = new ArrayList<>();
private String[] winners = new String[3];
private int[] prizes = new int[3];
private boolean endOfTournament = false;
private boolean isGold;
private String results = "";
public Tournament(String name,List<Team> teams,int[] prizes,boolean isGold){
this.name = name;
this.teams = teams;
this.prizes = prizes;
this.isGold = isGold;
for(int i = 0; i < teams.size();i = i + 2){
this.matches.add(new Match(teams.get(i),teams.get(i+1)));
}
this.matchweek.add(new Matchweek("Quarterfinals", this.matches));
}
public String getName() {
return this.name;
}
public List<Team> getTeams(){
return this.teams;
}
public void addMatchweek(String name,List<Team> teams){
List<Match> temp = new ArrayList<>();
for(int i = 0; i < teams.size();i++){
temp.add(new Match(teams.get(i),teams.get(i+1)));
++i;
}
this.matchweek.add(new Matchweek(name, temp));
}
private String getMatchweekName(Matchweek mw){
return mw.getName();
}
public List<Match> getMatchweekMatches(Matchweek mw){
return mw.getMatches();
}
public void showRanking() {
if(endOfTournament) {
System.out.println("POS \t TEAM \t PRIZE");
for(int i=0; i < winners.length;i++) {
System.out.println((i + 1) + "\t" + winners[i] + "\t" + prizes[i]);
}
}
else
System.out.println("The tournament isn't finished yet");
}
public String getResults(Matchweek m) {
results = "";
results += m.getName() + "\n" + m.getResults();
return results;
}
public List<Matchweek> getMatchweek() {
return this.matchweek;
}
public void addMatchResult(String matchweekName, String team1, String team2, int goalTeam1, int goalTeam2) {
List<Matchweek> temporaryList = new ArrayList<>();
for(int i= 0 ; i < matchweek.size(); i++){
temporaryList.add(matchweek.get(i));
}
for (Matchweek m : temporaryList) {
if(m.getName().equals(matchweekName)) {
boolean endOfMatchweek = true;
for (Match mt : m.getMatches()) {
if(mt.getTeam1().getName().equals(team1) && mt.getTeam2().getName().equals(team2)) {
mt.setResult(goalTeam1, goalTeam2);
}
if(mt.getGoalTeam1() < 0 && mt.getGoalTeam2() < 0) {
endOfMatchweek = false;
}
}
if(endOfMatchweek) {
List<Team> teamNextMw = new ArrayList<>();
List<Team> teamLosers = new ArrayList<>();
for (Match mt : m.getMatches()) {
if(mt.getGoalTeam1() > mt.getGoalTeam2()) {
teamNextMw.add(mt.getTeam1());
teamLosers.add(mt.getTeam2());
mt.getTeam1().addMatchWon();
}
else {
teamNextMw.add(mt.getTeam2());
teamLosers.add(mt.getTeam1());
mt.getTeam2().addMatchWon();
}
}
if(m.getName().equals("Quarterfinals"))
addMatchweek("Semifinals", teamNextMw);
else if(m.getName().equals("Semifinals")) {
addMatchweek("Final", teamNextMw);
addMatchweek("Final 3rd place", teamLosers);
}
else if(m.getName().equals("Final")) {
Team winner = teamNextMw.get(0);
winner.addTournamentWon(this);
winners[0] = winner.getName();
winners[1] = teamLosers.get(0).getName();
if(winners[2] != null)
endOfTournament = true;
}
else if(m.getName().equals("Final 3rd place")) {
winners[2] = teamNextMw.get(0).getName();
if(winners[0] != null)
endOfTournament = true;
}
}
}
}
}
public void getTournamentResults() {
for (Matchweek mw : this.getMatchweek()) {
System.out.println(mw.getName());
System.out.println(mw.getResults());
System.out.println();
}
}
public void getMatchweekResults(String matchweekName) {
String result = "";
for(Matchweek m : this.getMatchweek()) {
if(m.getName().equals(matchweekName))
result = m.getResults();
}
System.out.println(result);
}
}