Create gameList in Tournament
Create method to calc gameList and create random first round Started to develope view of gameSchedule
This commit is contained in:
parent
47b53033c4
commit
ebc0b64cb7
|
@ -3,10 +3,15 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class Game implements Serializable {
|
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;
|
||||||
|
|
||||||
|
public Game(Participant participant1, Participant participant2) {
|
||||||
|
this.participant1 = participant1;
|
||||||
|
this.participant2 = participant2;
|
||||||
|
}
|
||||||
|
|
||||||
public Place getLocation() {
|
public Place getLocation() {
|
||||||
return place;
|
return place;
|
||||||
}
|
}
|
||||||
|
@ -40,10 +45,10 @@ public class Game implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Participant getParticipant2() {
|
public Participant getParticipant2() {
|
||||||
return Participant2;
|
return participant2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParticipant2(Participant participant2) {
|
public void setParticipant2(Participant participant2) {
|
||||||
Participant2 = participant2;
|
this.participant2 = participant2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,14 @@ import javafx.collections.ObservableList;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Tournament implements Serializable {
|
public class Tournament implements Serializable {
|
||||||
private String name;
|
private String name;
|
||||||
private Type type;
|
private Type type;
|
||||||
private List<Participant> participants;
|
private List<Participant> participants;
|
||||||
private List<Place> places;
|
private List<Place> places;
|
||||||
|
private List<List<Game>> gameList;
|
||||||
|
|
||||||
|
|
||||||
public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException {
|
public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException {
|
||||||
|
@ -29,6 +26,7 @@ public class Tournament implements Serializable {
|
||||||
setType(type);
|
setType(type);
|
||||||
participants = new ArrayList<>();
|
participants = new ArrayList<>();
|
||||||
places = new ArrayList<>();
|
places = new ArrayList<>();
|
||||||
|
gameList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
|
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
|
||||||
|
@ -67,6 +65,42 @@ public class Tournament implements Serializable {
|
||||||
return placesObservable;
|
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<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)));
|
||||||
|
}
|
||||||
|
gameList.add(firstGameRound);
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +117,10 @@ public class Tournament implements Serializable {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<List<Game>> getGameList() {
|
||||||
|
return gameList;
|
||||||
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
KO("KO-System"), GROUPS("Gruppenspiele");
|
KO("KO-System"), GROUPS("Gruppenspiele");
|
||||||
|
|
||||||
|
@ -159,5 +197,14 @@ public class Tournament implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class NumberOfParticipantInvalidException extends Exception {
|
||||||
|
public NumberOfParticipantInvalidException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NumberOfParticipantInvalidException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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){
|
public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
|
||||||
try {
|
try {
|
||||||
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
||||||
|
|
|
@ -1,11 +1,33 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
|
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
|
||||||
|
|
||||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
||||||
|
import ch.zhaw.projekt2.turnierverwaltung.Game;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class GameScheduleController extends FXController {
|
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
|
@FXML
|
||||||
void openPlacesFormular(ActionEvent event) {
|
void openPlacesFormular(ActionEvent event) {
|
||||||
getFactoryDecorator().openPlacesFormular();
|
getFactoryDecorator().openPlacesFormular();
|
||||||
|
@ -19,6 +41,12 @@ public class GameScheduleController extends FXController {
|
||||||
@Override
|
@Override
|
||||||
public void loadContent() {
|
public void loadContent() {
|
||||||
|
|
||||||
|
List<List<Game>> gameList = getTournamentDecorator().getTournament().getGameList();
|
||||||
|
|
||||||
|
for (int i = 0; i < gameList.size(); i++) {
|
||||||
|
//hBoxCenter.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.ButtonBar;
|
import javafx.scene.control.ButtonBar;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class AlertDelete extends Alert {
|
public class AlertDelete extends Alert {
|
||||||
ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES);
|
ButtonType yesButton = new ButtonType("Ja", ButtonBar.ButtonData.YES);
|
||||||
ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO);
|
ButtonType noButton = new ButtonType("Nein", ButtonBar.ButtonData.NO);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.ChoiceBox?>
|
<?import javafx.scene.control.ChoiceBox?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.TextField?>
|
<?import javafx.scene.control.TextField?>
|
||||||
<?import javafx.scene.layout.HBox?>
|
<?import javafx.scene.layout.HBox?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
|
<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GameContoller">
|
||||||
<VBox alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="150.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GameContoller">
|
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="teamNameOne" text="Team One" />
|
<Label fx:id="teamNameOne" text="Team One" />
|
||||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
|
@ -41,6 +41,14 @@
|
||||||
</Label>
|
</Label>
|
||||||
<ChoiceBox fx:id="placesChoiceBox" prefWidth="150.0" />
|
<ChoiceBox fx:id="placesChoiceBox" prefWidth="150.0" />
|
||||||
</children>
|
</children>
|
||||||
|
<VBox.margin>
|
||||||
|
<Insets top="10.0" />
|
||||||
|
</VBox.margin>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
<Button mnemonicParsing="false" text="Speichern">
|
||||||
|
<VBox.margin>
|
||||||
|
<Insets bottom="10.0" top="10.0" />
|
||||||
|
</VBox.margin>
|
||||||
|
</Button>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|
|
@ -5,17 +5,21 @@
|
||||||
<?import javafx.scene.layout.BorderPane?>
|
<?import javafx.scene.layout.BorderPane?>
|
||||||
<?import javafx.scene.layout.HBox?>
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
|
||||||
|
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameScheduleController">
|
||||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameScheduleController">
|
|
||||||
<top>
|
<top>
|
||||||
<HBox alignment="CENTER_RIGHT" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
<HBox alignment="TOP_RIGHT" prefHeight="100.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||||
<children>
|
<children>
|
||||||
<Button mnemonicParsing="false" onAction="#openParticipantFormular" text="Teilnehmer bearbeiten">
|
<Button fx:id="createScheduleBtn" mnemonicParsing="false" onAction="#createNewSchedule" text="Create New Game Schedule">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets right="20.0" />
|
<Insets right="20.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
</Button>
|
</Button>
|
||||||
<Button mnemonicParsing="false" onAction="#openPlacesFormular" text="Orte bearbeiten">
|
<Button fx:id="editParticipantBtn" mnemonicParsing="false" onAction="#openParticipantFormular" text="Teilnehmer bearbeiten">
|
||||||
|
<HBox.margin>
|
||||||
|
<Insets right="20.0" />
|
||||||
|
</HBox.margin>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="editLocBtn" mnemonicParsing="false" onAction="#openPlacesFormular" text="Orte bearbeiten">
|
||||||
<HBox.margin>
|
<HBox.margin>
|
||||||
<Insets right="40.0" />
|
<Insets right="40.0" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
|
@ -23,4 +27,7 @@
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
</top>
|
</top>
|
||||||
|
<center>
|
||||||
|
<HBox fx:id="hBoxCenter" prefHeight="324.0" prefWidth="600.0" BorderPane.alignment="CENTER" />
|
||||||
|
</center>
|
||||||
</BorderPane>
|
</BorderPane>
|
||||||
|
|
Loading…
Reference in New Issue