made GameScheduleController and GameDecorator
first gameround gets loaded in gamescheduleview
This commit is contained in:
		
							parent
							
								
									9a3a9f3b53
								
							
						
					
					
						commit
						4dc7db7590
					
				| 
						 | 
					@ -1,8 +1,11 @@
 | 
				
			||||||
package ch.zhaw.projekt2.turnierverwaltung;
 | 
					package ch.zhaw.projekt2.turnierverwaltung;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController;
 | 
				
			||||||
 | 
					import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator;
 | 
				
			||||||
import ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController;
 | 
					import ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController;
 | 
				
			||||||
import javafx.fxml.FXMLLoader;
 | 
					import javafx.fxml.FXMLLoader;
 | 
				
			||||||
import javafx.scene.layout.BorderPane;
 | 
					import javafx.scene.layout.BorderPane;
 | 
				
			||||||
 | 
					import javafx.scene.layout.VBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.net.URL;
 | 
					import java.net.URL;
 | 
				
			||||||
| 
						 | 
					@ -54,6 +57,19 @@ public class Factory {
 | 
				
			||||||
        setCenterOfBorderPane(pane, getClass().getResource("gameScheduleView/GameSchedule.fxml"), factoryDecorator);
 | 
					        setCenterOfBorderPane(pane, getClass().getResource("gameScheduleView/GameSchedule.fxml"), factoryDecorator);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void loadGameView(VBox box, Game game, FactoryDecorator factoryDecorator) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml"));
 | 
				
			||||||
 | 
					            box.getChildren().add(loader.load());
 | 
				
			||||||
 | 
					            GameController controller = loader.getController();
 | 
				
			||||||
 | 
					            controller.setup(new GameDecorator(game, tournamentDecorator));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        } catch (IOException e) {
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					            //TODO LOGGER
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private FXController setCenterOfBorderPane(BorderPane pane, URL location, FactoryDecorator factoryDecorator) {
 | 
					    private FXController setCenterOfBorderPane(BorderPane pane, URL location, FactoryDecorator factoryDecorator) {
 | 
				
			||||||
        FXController controller = null;
 | 
					        FXController controller = null;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,9 @@
 | 
				
			||||||
package ch.zhaw.projekt2.turnierverwaltung;
 | 
					package ch.zhaw.projekt2.turnierverwaltung;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator;
 | 
				
			||||||
import javafx.scene.layout.BorderPane;
 | 
					import javafx.scene.layout.BorderPane;
 | 
				
			||||||
import javafx.scene.layout.Pane;
 | 
					import javafx.scene.layout.Pane;
 | 
				
			||||||
 | 
					import javafx.scene.layout.VBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
| 
						 | 
					@ -65,6 +67,10 @@ public class FactoryDecorator implements IsObservable{
 | 
				
			||||||
        factory.loadGameScheduler((BorderPane) pane, this);
 | 
					        factory.loadGameScheduler((BorderPane) pane, this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void openGameView(VBox vBox, Game game) {
 | 
				
			||||||
 | 
					        factory.loadGameView(vBox ,game, this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void informListener() {
 | 
					    public void informListener() {
 | 
				
			||||||
        for(IsObserver observer : listener) {
 | 
					        for(IsObserver observer : listener) {
 | 
				
			||||||
            observer.update();
 | 
					            observer.update();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,6 +70,7 @@ public class Tournament implements Serializable {
 | 
				
			||||||
    creates a complete new GameSchedule
 | 
					    creates a complete new GameSchedule
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void createGameSchedule() throws NumberOfParticipantInvalidException {
 | 
					    public void createGameSchedule() throws NumberOfParticipantInvalidException {
 | 
				
			||||||
 | 
					        gameList = new ArrayList<>();
 | 
				
			||||||
        if (type == Type.KO) {
 | 
					        if (type == Type.KO) {
 | 
				
			||||||
            if (numberOfParticipantValid()) {
 | 
					            if (numberOfParticipantValid()) {
 | 
				
			||||||
                calcGameSchedule();
 | 
					                calcGameSchedule();
 | 
				
			||||||
| 
						 | 
					@ -87,9 +88,7 @@ public class Tournament implements Serializable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private boolean numberOfParticipantValid() {
 | 
					    private boolean numberOfParticipantValid() {
 | 
				
			||||||
        double res = Math.log(participants.size()) / Math.log(2);
 | 
					        double res = Math.log(participants.size()) / Math.log(2);
 | 
				
			||||||
        return (res * 10) % 10 == 0;
 | 
					        return (res * 10) % 10 == 0 && participants.size() >=4;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        //TODO min 4
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void calcGameSchedule() {
 | 
					    private void calcGameSchedule() {
 | 
				
			||||||
| 
						 | 
					@ -97,6 +96,10 @@ public class Tournament implements Serializable {
 | 
				
			||||||
        List<Game> firstGameRound = new ArrayList<>();
 | 
					        List<Game> firstGameRound = new ArrayList<>();
 | 
				
			||||||
        for (int i = 0; i < participants.size() - 1; i += 2) {
 | 
					        for (int i = 0; i < participants.size() - 1; i += 2) {
 | 
				
			||||||
            firstGameRound.add(new Game(participants.get(i), participants.get(i+1), 0, i));
 | 
					            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());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        gameList.add(firstGameRound);
 | 
					        gameList.add(firstGameRound);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -114,6 +117,7 @@ public class Tournament implements Serializable {
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String getName() {
 | 
					    public String getName() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -79,13 +79,9 @@ public class TournamentDecorator implements IsObservable{
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void createNewGameSchedule() {
 | 
					    public void createNewGameSchedule() throws Tournament.NumberOfParticipantInvalidException {
 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
        tournament.createGameSchedule();
 | 
					        tournament.createGameSchedule();
 | 
				
			||||||
        informListener();
 | 
					        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){
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,13 +1,15 @@
 | 
				
			||||||
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.*;
 | 
				
			||||||
import javafx.event.ActionEvent;
 | 
					import javafx.event.ActionEvent;
 | 
				
			||||||
import javafx.fxml.FXML;
 | 
					import javafx.fxml.FXML;
 | 
				
			||||||
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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GameController extends FXController {
 | 
					public class GameController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private GameDecorator gameDecorator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private Label participantNameOne;
 | 
					    private Label participantNameOne;
 | 
				
			||||||
| 
						 | 
					@ -16,7 +18,7 @@ public class GameController extends FXController {
 | 
				
			||||||
    private Label participantNameTwo;
 | 
					    private Label participantNameTwo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private ChoiceBox<?> placesChoiceBox;
 | 
					    private ChoiceBox<Place> placesChoiceBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private TextField pointsTeamOne;
 | 
					    private TextField pointsTeamOne;
 | 
				
			||||||
| 
						 | 
					@ -24,13 +26,27 @@ public class GameController extends FXController {
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    private TextField pointsTeamTwo;
 | 
					    private TextField pointsTeamTwo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    void saveGamerResult(ActionEvent event) {
 | 
					    void saveGamerResult(ActionEvent event) {
 | 
				
			||||||
 | 
					        gameDecorator.setPoints1(Integer.parseInt(pointsTeamOne.getText()));
 | 
				
			||||||
 | 
					        gameDecorator.setPoints2(Integer.parseInt(pointsTeamTwo.getText()));
 | 
				
			||||||
 | 
					        gameDecorator.setLocation(placesChoiceBox.getValue());
 | 
				
			||||||
 | 
					        gameDecorator.getTournamentDecorator().getTournament().refreshGameParticipants();
 | 
				
			||||||
 | 
					        loadContent();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					
 | 
				
			||||||
    public void loadContent() {
 | 
					    public void loadContent() {
 | 
				
			||||||
 | 
					        participantNameOne.setText(gameDecorator.getParticipantOne());
 | 
				
			||||||
 | 
					        participantNameTwo.setText(gameDecorator.getParticipantTwo());
 | 
				
			||||||
 | 
					        pointsTeamOne.setText(String.valueOf(gameDecorator.getPoints1()));
 | 
				
			||||||
 | 
					        pointsTeamTwo.setText(String.valueOf(gameDecorator.getPoints2()));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setup(GameDecorator gameDecorator) {
 | 
				
			||||||
 | 
					        this.gameDecorator = gameDecorator;
 | 
				
			||||||
 | 
					        loadContent();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,55 @@
 | 
				
			||||||
 | 
					package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ch.zhaw.projekt2.turnierverwaltung.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class GameDecorator {
 | 
				
			||||||
 | 
					    private Game game;
 | 
				
			||||||
 | 
					    private TournamentDecorator tournamentDecorator;
 | 
				
			||||||
 | 
					    private List<IsObserver> listener = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public GameDecorator (Game game, TournamentDecorator tournamentDecorator) {
 | 
				
			||||||
 | 
					        this.game = game;
 | 
				
			||||||
 | 
					        this.tournamentDecorator = tournamentDecorator;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public TournamentDecorator getTournamentDecorator() {
 | 
				
			||||||
 | 
					        return tournamentDecorator;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setPoints1(int points1) {
 | 
				
			||||||
 | 
					        game.setPoints1(points1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setPoints2(int points2) {
 | 
				
			||||||
 | 
					        game.setPoints2(points2);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getPoints1() {
 | 
				
			||||||
 | 
					       return String.valueOf(game.getPoints1());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getPoints2() {
 | 
				
			||||||
 | 
					        return String.valueOf(game.getPoints2());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getParticipantOne() {
 | 
				
			||||||
 | 
					        return game.getParticipant1().getName();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getParticipantTwo() {
 | 
				
			||||||
 | 
					        return game.getParticipant2().getName();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Place getLocation() {
 | 
				
			||||||
 | 
					        return game.getPlace();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setLocation(Place place) {
 | 
				
			||||||
 | 
					        game.setLocation(place);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -2,11 +2,17 @@ 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 ch.zhaw.projekt2.turnierverwaltung.Game;
 | 
				
			||||||
 | 
					import ch.zhaw.projekt2.turnierverwaltung.Tournament;
 | 
				
			||||||
import javafx.event.ActionEvent;
 | 
					import javafx.event.ActionEvent;
 | 
				
			||||||
import javafx.fxml.FXML;
 | 
					import javafx.fxml.FXML;
 | 
				
			||||||
 | 
					import javafx.fxml.FXMLLoader;
 | 
				
			||||||
import javafx.scene.control.Button;
 | 
					import javafx.scene.control.Button;
 | 
				
			||||||
import javafx.scene.layout.HBox;
 | 
					import javafx.scene.layout.HBox;
 | 
				
			||||||
 | 
					import javafx.scene.layout.Pane;
 | 
				
			||||||
 | 
					import javafx.scene.layout.VBox;
 | 
				
			||||||
 | 
					import org.checkerframework.checker.units.qual.C;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GameScheduleController extends FXController {
 | 
					public class GameScheduleController extends FXController {
 | 
				
			||||||
| 
						 | 
					@ -25,7 +31,12 @@ public class GameScheduleController extends FXController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
    void createNewSchedule(ActionEvent event) {
 | 
					    void createNewSchedule(ActionEvent event) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
            getTournamentDecorator().createNewGameSchedule();
 | 
					            getTournamentDecorator().createNewGameSchedule();
 | 
				
			||||||
 | 
					        } catch (Tournament.NumberOfParticipantInvalidException e) {
 | 
				
			||||||
 | 
					            //TODO Method in FactoryDecorater to show msg
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @FXML
 | 
					    @FXML
 | 
				
			||||||
| 
						 | 
					@ -40,11 +51,16 @@ public class GameScheduleController extends FXController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void loadContent() {
 | 
					    public void loadContent() {
 | 
				
			||||||
 | 
					        hBoxCenter.getChildren().clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<List<Game>> gameList = getTournamentDecorator().getTournament().getGameList();
 | 
					        List<List<Game>> gameList = getTournamentDecorator().getTournament().getGameList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int i = 0; i < gameList.size(); i++) {
 | 
					        for (int i = 0; i < gameList.size(); i++) {
 | 
				
			||||||
            //hBoxCenter.
 | 
					            VBox vBox = new VBox();
 | 
				
			||||||
 | 
					            for (int j = 0; j < gameList.get(i).size(); j++) {
 | 
				
			||||||
 | 
					                getFactoryDecorator().openGameView(vBox,gameList.get(i).get(j));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            hBoxCenter.getChildren().add(vBox);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@
 | 
				
			||||||
<?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="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController">
 | 
				
			||||||
   <children>
 | 
					   <children>
 | 
				
			||||||
      <Label fx:id="participantNameOne" text="Participant One" />
 | 
					      <Label fx:id="participantNameOne" text="Participant One" />
 | 
				
			||||||
      <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
 | 
					      <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue