Skip to content
Snippets Groups Projects
Commit ed8bc835 authored by Jakob Behrens's avatar Jakob Behrens
Browse files

Implemented the 4 player bracket maker, yet to implement the 8 and 32

parent 475dabb6
No related branches found
No related tags found
No related merge requests found
package no.ntnu.idatg1002.idatg1002_2022_group6;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import no.ntnu.idatg1002.idatg1002_2022_group6.model.FileHandler;
import no.ntnu.idatg1002.idatg1002_2022_group6.model.Player;
import java.io.IOException;
import java.nio.file.Path;
//TODO: I have no idea what i am doing
/**
* Controller for the Bracket View GUI. Handles all user interaction with the GUI.
*
* @author Group6
* @version 1.0
*/
public class BracketViewController4 extends TournamentController {
@FXML
private TextField textFieldPlayer1;
@FXML
private TextField textFieldPlayer2;
@FXML
private TextField textFieldPlayer3;
@FXML
private TextField textFieldPlayer4;
/**
* button to go back to the previous scene
* @throws IOException IOException
*/
public void onPressBackToTournamentView() throws IOException {
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("tournament-view.fxml");
}
//Input all players, place them in a list, play all the matches, loser gets deleted
//Do it again till you reach the winner
//Need to go but should be a relatively simple task, and switch all the places to labels or non editable textfields
public void onPressAdd() {
if(textFieldPlayer1.getText().isBlank() || textFieldPlayer2.getText().isBlank()) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("Please enter a name into the text field before proceeding!");
alert.setTitle("WARNING");
alert.showAndWait();
} else {
try {
BracketViewController.tournamentRegister.clear();
BracketViewController.tournamentRegister.addPlayer(new Player(textFieldPlayer1.getText()));
BracketViewController.tournamentRegister.addPlayer(new Player(textFieldPlayer2.getText()));
BracketViewController.tournamentRegister.addPlayer(new Player(textFieldPlayer3.getText()));
BracketViewController.tournamentRegister.addPlayer(new Player(textFieldPlayer4.getText()));
}
catch (Exception e)
{
System.err.println(e);
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("You need to use letters and only letters!");
alert.setTitle("UNABLE TO CREATE BRACKET");
alert.showAndWait();
}
}
}
public void onPressLoad() {
try
{
BracketViewController.tournamentRegister.clear();
BracketViewController.tournamentRegister.addPlayers(FileHandler.readCsv(Path.of("NEWTOURNAMENT.csv")));
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("tournament-match-view.fxml");
}catch (Exception e){
System.err.println(e);
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setContentText("No save found!");
alert.setTitle("UNABLE TO CREATE BRACKET");
alert.showAndWait();
}
}
public void onPressPlay() throws IOException{
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("create-tournament-match.fxml");
}
}
......@@ -29,8 +29,12 @@ public class CreateTournamentMatchController implements Initializable {
* @throws IOException
*/
public void onPressPlayMatch() throws IOException {
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("tournament-match-view.fxml");
try {
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("tournament-match-view.fxml");
}catch (Exception e){
System.err.println(e);
}
}
@Override
......
......@@ -84,16 +84,51 @@ public class TournamentController {
return tournamentRegister;
}
/**
* Creates a 4 player tournament
* @param actionEvent
* @throws IOException
*/
public void create4PlayerTournament(ActionEvent actionEvent) throws IOException{
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("create-bracket-view4.fxml");
}
/**
* Creates an 8 player tournament
* @param actionEvent
* @throws IOException
*/
public void create8PlayerTournament(ActionEvent actionEvent) throws IOException{
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("create-bracket-view8.fxml");
}
/**
* creates a test bracket for 16 players
* @param actionEvent currently this method parameter does not take any input
* @throws IOException
*/
public void createTest(ActionEvent actionEvent) throws IOException {
public void create16PlayerTournament(ActionEvent actionEvent) throws IOException {
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("create-bracket-view.fxml");
}
/**
* Creates a 32 player tournament
* @param actionEvent
* @throws IOException
*/
public void create32PlayerTournament(ActionEvent actionEvent) throws IOException{
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("create-bracket-view32.fxml");
}
/**
* Loads in the most recently saved game
* @param actionEvent
* @throws IOException
*/
public void onLoadPressed(ActionEvent actionEvent) throws IOException{
try
{
......
......@@ -4,7 +4,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatg1002.idatg1002_2022_group6.BracketViewController">
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatg1002.idatg1002_2022_group6.BracketViewController4">
<children>
<Pane fx:id="pane1" layoutX="22.0" layoutY="14.0" prefHeight="250.0" prefWidth="350.0">
<children>
......
......@@ -11,7 +11,7 @@
<Font name="JetBrains Mono Light" size="48.0" />
</font>
</Label>
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="54.0" layoutY="79.0" prefHeight="51.0" prefWidth="692.0" text="Enter up to 32 players" textAlignment="CENTER">
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="54.0" layoutY="79.0" prefHeight="51.0" prefWidth="692.0" text="Choose which tournament you want:" textAlignment="CENTER">
<font>
<Font name="JetBrains Mono Light" size="24.0" />
</font>
......@@ -21,19 +21,13 @@
<Font size="24.0" />
</font>
</Button>
<ScrollPane layoutX="287.0" layoutY="200.0" prefHeight="200.0" prefWidth="200.0">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: white;">
<children>
<TextField fx:id="textField1" layoutX="26.0" layoutY="14.0" />
<TextField fx:id="textField2" layoutX="26.0" layoutY="75.0" />
</children></AnchorPane>
</content>
</ScrollPane>
<Button layoutX="14.0" layoutY="504.0" mnemonicParsing="false" onAction="#onPressBackToMenu" style="-fx-background-color: #297ca6;" text="Back to main menu" textFill="WHITE" />
<Button layoutX="347.0" layoutY="419.0" mnemonicParsing="false" onAction="#onPressAddPlayers" text="Add players" />
<Label fx:id="playersAddedLabel" layoutX="347.0" layoutY="173.0" />
<Button layoutX="361.0" layoutY="561.0" mnemonicParsing="false" onAction="#createTest" text="Test" />
<Button layoutX="361.0" layoutY="561.0" mnemonicParsing="false" onAction="#create16PlayerTournament" text="Test" />
<Button fx:id="loadSaved" layoutX="487.0" layoutY="561.0" mnemonicParsing="false" onAction="#onLoadPressed" text="Load saved match" />
<Button layoutX="120.0" layoutY="222.0" mnemonicParsing="false" onAction="#create4PlayerTournament" text="4 Player tournament " />
<Button layoutX="120.0" layoutY="259.0" mnemonicParsing="false" onAction="#create8PlayerTournament" text="8 Player tournament" />
<Button layoutX="120.0" layoutY="288.0" mnemonicParsing="false" onAction="#create16PlayerTournament" text="16 Player tournament" />
<Button layoutX="120.0" layoutY="313.0" mnemonicParsing="false" onAction="#create32PlayerTournament" text="32 Player tournament" />
</children>
</Pane>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment