Develope game branch #33

Merged
schrom01 merged 23 commits from develope_Game_branch into main 2022-05-12 13:44:47 +02:00
2 changed files with 47 additions and 2 deletions
Showing only changes of commit 593bcdc872 - Show all commits

View File

@ -6,10 +6,14 @@ public class Game implements Serializable {
private Participant participant1, participant2; private Participant participant1, participant2;
private int points1, points2; private int points1, points2;
private Place place; 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.participant1 = participant1;
this.participant2 = participant2; this.participant2 = participant2;
this.index1 = index1;
this.index2 = index2;
} }
public Place getLocation() { public Place getLocation() {
@ -48,6 +52,32 @@ public class Game implements Serializable {
return participant2; 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) { public void setParticipant2(Participant participant2) {
this.participant2 = participant2; this.participant2 = participant2;
} }

View File

@ -96,11 +96,26 @@ public class Tournament implements Serializable {
Collections.shuffle(participants); Collections.shuffle(participants);
List<Game> firstGameRound = new ArrayList<>(); List<Game> firstGameRound = new ArrayList<>();
for (int i = 0; i < participants.size() - 1; i += 2) { 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); 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() { public String getName() {
return name; return name;
} }