make createTournament create all future games with null object for participant

This commit is contained in:
Andrin Fassbind 2022-05-06 19:12:14 +02:00
parent 4dc7db7590
commit e5dc6a913a
4 changed files with 21 additions and 11 deletions

View File

@ -6,10 +6,9 @@ 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, int index1, int index2) {
public Game(Participant participant1, Participant participant2) {
this.participant1 = participant1;
this.participant2 = participant2;
}

View File

@ -93,15 +93,21 @@ public class Tournament implements Serializable {
private void calcGameSchedule() {
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), 0, i));
//TODO PRINT
System.out.println("I: " + i + " " + participants.get(i).getName() +" vs " +participants.get(i+1).getName());
for (int i = 0; i < (Math.log(participants.size()) / Math.log(2)); i++) {
List<Game> gameRound = new ArrayList<>();
if (i == 0) {
for (int j = 0; j < participants.size() - 1; j += 2) {
gameRound.add(new Game(participants.get(j), participants.get(j+1)));
}
gameList.add(gameRound);
} else {
for (int j = 0; j < (participants.size() / Math.pow(2,i)); j++) {
gameRound.add(new Game(null,null));
}
}
}
gameList.add(firstGameRound);
}
public void refreshGameParticipants(){
@ -117,7 +123,6 @@ public class Tournament implements Serializable {
}
}
}
}
public String getName() {

View File

@ -126,9 +126,15 @@ public class TournamentDecorator implements IsObservable{
}
}
public void refreshGameParticipants() {
getTournament().refreshGameParticipants();
informListener();
}
public void informListener() {
for(IsObserver observer : listener) {
observer.update();
}
}
}

View File

@ -32,7 +32,7 @@ public class GameController {
gameDecorator.setPoints1(Integer.parseInt(pointsTeamOne.getText()));
gameDecorator.setPoints2(Integer.parseInt(pointsTeamTwo.getText()));
gameDecorator.setLocation(placesChoiceBox.getValue());
gameDecorator.getTournamentDecorator().getTournament().refreshGameParticipants();
gameDecorator.getTournamentDecorator().refreshGameParticipants();
loadContent();
}