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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Participant> participants;
|
||||
private List<Place> places;
|
||||
|
||||
private List<List<Game>> 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<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() {
|
||||
return name;
|
||||
}
|
||||
|
@ -83,6 +117,10 @@ public class Tournament implements Serializable {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public List<List<Game>> 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<Type> getObservableList(){
|
||||
public static ObservableList<Type> getObservableList() {
|
||||
ObservableList<Type> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -1,11 +1,33 @@
|
|||
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) {
|
||||
getFactoryDecorator().openPlacesFormular();
|
||||
|
@ -19,6 +41,12 @@ public class GameScheduleController extends FXController {
|
|||
@Override
|
||||
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.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);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ChoiceBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
|
||||
<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">
|
||||
<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">
|
||||
<children>
|
||||
<Label fx:id="teamNameOne" text="Team One" />
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||
|
@ -41,6 +41,14 @@
|
|||
</Label>
|
||||
<ChoiceBox fx:id="placesChoiceBox" prefWidth="150.0" />
|
||||
</children>
|
||||
<VBox.margin>
|
||||
<Insets top="10.0" />
|
||||
</VBox.margin>
|
||||
</HBox>
|
||||
<Button mnemonicParsing="false" text="Speichern">
|
||||
<VBox.margin>
|
||||
<Insets bottom="10.0" top="10.0" />
|
||||
</VBox.margin>
|
||||
</Button>
|
||||
</children>
|
||||
</VBox>
|
||||
|
|
|
@ -5,17 +5,21 @@
|
|||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?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/17" 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/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameScheduleController">
|
||||
<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>
|
||||
<Button mnemonicParsing="false" onAction="#openParticipantFormular" text="Teilnehmer bearbeiten">
|
||||
<Button fx:id="createScheduleBtn" mnemonicParsing="false" onAction="#createNewSchedule" text="Create New Game Schedule">
|
||||
<HBox.margin>
|
||||
<Insets right="20.0" />
|
||||
</HBox.margin>
|
||||
</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>
|
||||
<Insets right="40.0" />
|
||||
</HBox.margin>
|
||||
|
@ -23,4 +27,7 @@
|
|||
</children>
|
||||
</HBox>
|
||||
</top>
|
||||
<center>
|
||||
<HBox fx:id="hBoxCenter" prefHeight="324.0" prefWidth="600.0" BorderPane.alignment="CENTER" />
|
||||
</center>
|
||||
</BorderPane>
|
||||
|
|
Loading…
Reference in New Issue