make createTournament create all future games with null object for participant
This commit is contained in:
parent
4dc7db7590
commit
e5dc6a913a
|
@ -6,10 +6,9 @@ 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, int index1, int index2) {
|
public Game(Participant participant1, Participant participant2) {
|
||||||
this.participant1 = participant1;
|
this.participant1 = participant1;
|
||||||
this.participant2 = participant2;
|
this.participant2 = participant2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,15 +93,21 @@ public class Tournament implements Serializable {
|
||||||
|
|
||||||
private void calcGameSchedule() {
|
private void calcGameSchedule() {
|
||||||
Collections.shuffle(participants);
|
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(firstGameRound);
|
gameList.add(gameRound);
|
||||||
|
} else {
|
||||||
|
for (int j = 0; j < (participants.size() / Math.pow(2,i)); j++) {
|
||||||
|
gameRound.add(new Game(null,null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshGameParticipants(){
|
public void refreshGameParticipants(){
|
||||||
|
@ -117,7 +123,6 @@ public class Tournament implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -126,9 +126,15 @@ public class TournamentDecorator implements IsObservable{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshGameParticipants() {
|
||||||
|
getTournament().refreshGameParticipants();
|
||||||
|
informListener();
|
||||||
|
}
|
||||||
|
|
||||||
public void informListener() {
|
public void informListener() {
|
||||||
for(IsObserver observer : listener) {
|
for(IsObserver observer : listener) {
|
||||||
observer.update();
|
observer.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class GameController {
|
||||||
gameDecorator.setPoints1(Integer.parseInt(pointsTeamOne.getText()));
|
gameDecorator.setPoints1(Integer.parseInt(pointsTeamOne.getText()));
|
||||||
gameDecorator.setPoints2(Integer.parseInt(pointsTeamTwo.getText()));
|
gameDecorator.setPoints2(Integer.parseInt(pointsTeamTwo.getText()));
|
||||||
gameDecorator.setLocation(placesChoiceBox.getValue());
|
gameDecorator.setLocation(placesChoiceBox.getValue());
|
||||||
gameDecorator.getTournamentDecorator().getTournament().refreshGameParticipants();
|
gameDecorator.getTournamentDecorator().refreshGameParticipants();
|
||||||
loadContent();
|
loadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue