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 18e317b..487e50e 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java @@ -3,10 +3,15 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.Serializable; public class Game implements Serializable { - private Participant participant1, Participant2; + private Participant participant1, participant2; private int points1, points2; private Place place; + public Game(Participant participant1, Participant participant2) { + this.participant1 = participant1; + this.participant2 = participant2; + } + public Place getLocation() { return place; } @@ -40,10 +45,10 @@ public class Game implements Serializable { } public Participant getParticipant2() { - return Participant2; + return participant2; } public void setParticipant2(Participant participant2) { - Participant2 = participant2; + 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 b4097d5..4041ee6 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Tournament.java @@ -5,23 +5,20 @@ import javafx.collections.ObservableList; import java.io.File; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; +import java.util.*; public class Tournament implements Serializable { private String name; private Type type; private List participants; private List places; - + private List> gameList; public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException { - if(!name.matches("[\\w]{1,20}")){ + if (!name.matches("[\\w]{1,20}")) { throw new InvalidNameException("Invalid Name entered"); //TODO handle en logging. - } else if(!Arrays.asList(Type.values()).contains(type)){ + } else if (!Arrays.asList(Type.values()).contains(type)) { throw new InvalidTypeException("Invalid Type selected"); //TODO handle en logging. } @@ -29,6 +26,7 @@ public class Tournament implements Serializable { setType(type); participants = new ArrayList<>(); places = new ArrayList<>(); + gameList = new ArrayList<>(); } public void addParticipant(Participant newParticipant) throws ParticipantExistsException { @@ -37,7 +35,7 @@ public class Tournament implements Serializable { } public void removeParticipant(Participant participant) throws ParticipantNotExistsException { - if(!participants.contains(participant)){ + if (!participants.contains(participant)) { throw new ParticipantNotExistsException("The given Participant is not part of this Tournament"); } participants.remove(participant); @@ -55,7 +53,7 @@ public class Tournament implements Serializable { } public void removePlace(Place place) throws PlaceNotExistsException { - if(!places.contains(place)){ + if (!places.contains(place)) { throw new PlaceNotExistsException("The given Place is not part of this Tournament"); } places.remove(place); @@ -67,6 +65,42 @@ public class Tournament implements Serializable { return placesObservable; } + + /* + creates a complete new GameSchedule + */ + public void createGameSchedule() throws NumberOfParticipantInvalidException { + if (type == Type.KO) { + if (numberOfParticipantValid()) { + calcGameSchedule(); + //TODO Logging + } else { + throw new NumberOfParticipantInvalidException("Can not Create Game Schedule for KO Modus"); + //TODO Logging + } + + + } else { + //TODO for Type Group + } + } + + private boolean numberOfParticipantValid() { + double res = Math.log(participants.size()) / Math.log(2); + return (res * 10) % 10 == 0; + + //TODO min 4 + } + + 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))); + } + gameList.add(firstGameRound); + } + public String getName() { return name; } @@ -83,6 +117,10 @@ public class Tournament implements Serializable { this.type = type; } + public List> getGameList() { + return gameList; + } + public enum Type { KO("KO-System"), GROUPS("Gruppenspiele"); @@ -97,7 +135,7 @@ public class Tournament implements Serializable { return name; } - public static ObservableList getObservableList(){ + public static ObservableList getObservableList() { ObservableList items = FXCollections.observableArrayList(); items.addAll(values()); return items; @@ -159,5 +197,14 @@ public class Tournament implements Serializable { } + public class NumberOfParticipantInvalidException extends Exception { + public NumberOfParticipantInvalidException() { + super(); + } + + public NumberOfParticipantInvalidException(String msg) { + super(msg); + } + } } 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 dcb3112..219cd73 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/TournamentDecorator.java @@ -79,6 +79,15 @@ public class TournamentDecorator implements IsObservable{ } } + public void createNewGameSchedule() { + try { + tournament.createGameSchedule(); + informListener(); + } catch (Tournament.NumberOfParticipantInvalidException e) { + e.printStackTrace(); + } + } + public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){ try { tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth)); diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java index ab82179..c1bb5b1 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/gameScheduleView/GameScheduleController.java @@ -1,10 +1,32 @@ package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; import ch.zhaw.projekt2.turnierverwaltung.FXController; +import ch.zhaw.projekt2.turnierverwaltung.Game; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.layout.HBox; + +import java.util.List; public class GameScheduleController extends FXController { + + @FXML + private Button createScheduleBtn; + + @FXML + private Button editLocBtn; + + @FXML + private Button editParticipantBtn; + + @FXML + private HBox hBoxCenter; + + @FXML + void createNewSchedule(ActionEvent event) { + getTournamentDecorator().createNewGameSchedule(); + } @FXML void openPlacesFormular(ActionEvent event) { @@ -19,6 +41,12 @@ public class GameScheduleController extends FXController { @Override public void loadContent() { + List> gameList = getTournamentDecorator().getTournament().getGameList(); + + for (int i = 0; i < gameList.size(); i++) { + //hBoxCenter. + } + } } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java index e440807..6c400dd 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/main/tournamentList/AlertDelete.java @@ -4,8 +4,6 @@ import javafx.scene.control.Alert; import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonType; -import java.io.IOException; - public class AlertDelete extends Alert { ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES); ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO); diff --git a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/Game.fxml b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/Game.fxml index 83fcb91..815b2db 100644 --- a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/Game.fxml +++ b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/Game.fxml @@ -1,14 +1,14 @@ + - - + + + + + diff --git a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml index cd88c6a..6c824a7 100644 --- a/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml +++ b/app/src/main/resources/ch/zhaw/projekt2/turnierverwaltung/gameScheduleView/GameSchedule.fxml @@ -5,17 +5,21 @@ - - + - + - - +