diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java index 4c0a5ee..c294e05 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java @@ -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; } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java index d412b0b..bd7c92b 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -93,15 +93,21 @@ public class Tournament implements Serializable { private void calcGameSchedule() { Collections.shuffle(participants); - List 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 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() { diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java index 8622137..9ba380f 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -126,9 +126,15 @@ public class TournamentDecorator implements IsObservable{ } } + public void refreshGameParticipants() { + getTournament().refreshGameParticipants(); + informListener(); + } + public void informListener() { for(IsObserver observer : listener) { observer.update(); } } + } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java index ac12946..0bb6f35 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameController.java @@ -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(); }