added indexes to Game.java
This commit is contained in:
parent
ebc0b64cb7
commit
593bcdc872
|
@ -6,10 +6,14 @@ public class Game implements Serializable {
|
|||
private Participant participant1, participant2;
|
||||
private int points1, points2;
|
||||
private Place place;
|
||||
private int index1, index2;
|
||||
|
||||
public Game(Participant participant1, Participant participant2) {
|
||||
|
||||
public Game(Participant participant1, Participant participant2, int index1, int index2) {
|
||||
this.participant1 = participant1;
|
||||
this.participant2 = participant2;
|
||||
this.index1 = index1;
|
||||
this.index2 = index2;
|
||||
}
|
||||
|
||||
public Place getLocation() {
|
||||
|
@ -48,6 +52,32 @@ public class Game implements Serializable {
|
|||
return participant2;
|
||||
}
|
||||
|
||||
public void setPlace(Place place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
public Place getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public int getIndex1() {
|
||||
return index1;
|
||||
}
|
||||
|
||||
public int getIndex2() {
|
||||
return index2;
|
||||
}
|
||||
|
||||
public Participant getWinner(){
|
||||
if(points1 > points2){
|
||||
return participant1;
|
||||
} else if(points2 > points1){
|
||||
return participant2;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setParticipant2(Participant participant2) {
|
||||
this.participant2 = participant2;
|
||||
}
|
||||
|
|
|
@ -96,11 +96,26 @@ public class Tournament implements Serializable {
|
|||
Collections.shuffle(participants);
|
||||
List<Game> firstGameRound = new ArrayList<>();
|
||||
for (int i = 0; i < participants.size() - 1; i += 2) {
|
||||
firstGameRound.add(new Game(participants.get(i), participants.get(i+1)));
|
||||
firstGameRound.add(new Game(participants.get(i), participants.get(i+1), 0, i));
|
||||
}
|
||||
gameList.add(firstGameRound);
|
||||
}
|
||||
|
||||
public void refreshGameParticipants(){
|
||||
for(int i = 1; i < gameList.size(); i++){
|
||||
for(int j = 0; j/2 < gameList.get(i).size(); j ++){
|
||||
Participant winner = gameList.get(i-1).get(j).getWinner();
|
||||
if(winner != null){
|
||||
if(j % 2 == 0){
|
||||
gameList.get(i).get(j/2).setParticipant1(winner);
|
||||
} else{
|
||||
gameList.get(i).get(j/2).setParticipant2(winner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue