Skip to content
Snippets Groups Projects
Commit 18e266fd authored by Joachim Olerud Milward's avatar Joachim Olerud Milward
Browse files

Fixed the main menu view. Refactored the MatchController to use the static...

Fixed the main menu view. Refactored the MatchController to use the static changeScene() method. Javadoc, and minor changes to the table-tennis-view
parent e901295a
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,8 @@ import no.ntnu.idatg1002.idatg1002_2022_group6.model.FileHandler;
import no.ntnu.idatg1002.idatg1002_2022_group6.model.Match;
/**
* Represents the match controller.
* Represents the match controller. This class is responsible for handling the match view, and
* displaying information about an ongoing game.
*
* @author Group6
* @version 1.0
......@@ -37,7 +38,7 @@ public class MatchController extends TournamentController implements Initializab
private final Match match = new Match();
/**
* initializes the match, retrieves the players from the register
* Initializes the match, retrieves the players from the register
* @param url url
* @param resourceBundle ResourceBundle
*/
......@@ -50,15 +51,14 @@ public class MatchController extends TournamentController implements Initializab
}
/**
* Adds a point to player 1, stops displaying the button when the score reaches 12
* Adds a point to player 1. When any player has a score equal to 11, the game is over.
* As a visual feedback the button is disabled.
*/
public void onPressPointPlayer1() {
match.scorePlayer1();
scorePlayer1.setText(String.valueOf(Integer.parseInt((scorePlayer1.getText())) + 1));
if (Integer.parseInt(scorePlayer1.getText()) >= 11) {
pointPlayer1.setOpacity(0);
pointPlayer1.setDisable(true);
pointPlayer2.setOpacity(0);
pointPlayer2.setDisable(true);
winnerLabel.setText(
"Winner: " + TournamentController.tournamentRegister.getPlayer(0).toString());
......@@ -67,14 +67,13 @@ public class MatchController extends TournamentController implements Initializab
}
/**
* Adds a point to player 2, stops displaying the button when the score reaches 12
* Adds a point to player 2. When any player has a score equal to 11, the game is over.
* As a visual feedback the button is disabled.
*/
public void onPressPointPlayer2() {
match.scorePLayer2();
scorePlayer2.setText(String.valueOf(Integer.parseInt((scorePlayer2.getText())) + 1));
if (Integer.parseInt(scorePlayer2.getText()) >= 11) {
pointPlayer1.setOpacity(0);
pointPlayer2.setOpacity(0);
pointPlayer1.setDisable(true);
pointPlayer2.setDisable(true);
winnerLabel.setText(
......@@ -90,15 +89,17 @@ public class MatchController extends TournamentController implements Initializab
*/
@Override
public void onPressReturnToMenu() throws IOException {
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("table-tennis-view.fxml");
TableTennisApplication.changeScene("table-tennis-view.fxml");
}
/**
* When the save match button is pressed, the match is saved to the file.
*
* @throws IOException If the file cannot be saved.
*/
public void onPressSaveMatch() throws IOException{
FileHandler.writeCsv(tournamentRegister.getParticipants(), "SINGLELOAD");
TournamentController.tournamentRegister.clear();
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("table-tennis-view.fxml");
TableTennisApplication.changeScene("table-tennis-view.fxml");
}
}
......@@ -22,6 +22,11 @@ public class TableTennisApplication extends Application {
public static void main(String[] args) {launch();}
/**
* Sets the stage of the application.
* @param stage The main stage of the application.
* @throws IOException if the fxml file cannot be found.
*/
@Override
public void start(Stage stage) throws IOException {
TableTennisApplication.stage = stage;
......@@ -33,7 +38,6 @@ public class TableTennisApplication extends Application {
stage.show();
}
/**
* Changes the scene shown to the user to a given scene.
* @param fxml The name of the fxml file to be loaded.
......
......@@ -7,24 +7,24 @@
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatg1002.idatg1002_2022_group6.TableTennisController">
<children>
<Button fx:id="infoButton" layoutX="289.0" layoutY="429.0" mnemonicParsing="false" onAction="#onClickShowInfo" prefHeight="51.0" prefWidth="89.0" text="Info">
<Button fx:id="infoButton" layoutX="179.0" layoutY="403.0" mnemonicParsing="false" onAction="#onClickShowInfo" prefHeight="51.0" prefWidth="210.0" text="Info">
<font>
<Font size="24.0" />
<Font size="18.0" />
</font>
</Button>
<Button fx:id="rulesButton" layoutX="422.0" layoutY="429.0" mnemonicParsing="false" onAction="#onClickShowRules" prefHeight="51.0" prefWidth="89.0" text="Rules">
<Button fx:id="rulesButton" layoutX="405.0" layoutY="403.0" mnemonicParsing="false" onAction="#onClickShowRules" prefHeight="51.0" prefWidth="210.0" text="Rules">
<font>
<Font size="24.0" />
<Font size="18.0" />
</font>
</Button>
<Button fx:id="exitButton" layoutX="302.0" layoutY="488.0" mnemonicParsing="false" onAction="#onClickExitApp" text="Exit Application">
<Button fx:id="exitButton" layoutX="179.0" layoutY="463.0" mnemonicParsing="false" onAction="#onClickExitApp" prefHeight="77.0" prefWidth="435.0" text="Exit Application">
<font>
<Font size="24.0" />
<Font size="30.0" />
</font>
</Button>
<Button fx:id="friendlyMatchButton" layoutX="250.0" layoutY="342.0" mnemonicParsing="false" onAction="#onClickFriendlyMatch" prefHeight="77.0" prefWidth="292.0" text="Friendly Match">
<Button fx:id="friendlyMatchButton" layoutX="179.0" layoutY="344.0" mnemonicParsing="false" onAction="#onClickFriendlyMatch" prefHeight="51.0" prefWidth="210.0" text="Quick Match">
<font>
<Font size="36.0" />
<Font size="18.0" />
</font>
</Button>
<ImageView fx:id="mainMenuLogo" fitHeight="300" fitWidth="300" layoutX="250.0" layoutY="-61.0" pickOnBounds="true" preserveRatio="true" />
......@@ -33,6 +33,9 @@
<Font size="48.0" />
</font>
</Button>
<Button layoutX="163.0" layoutY="368.0" mnemonicParsing="false" onAction="#onLoadPressed" text="Load saved" />
<Button layoutX="405.0" layoutY="344.0" mnemonicParsing="false" onAction="#onLoadPressed" prefHeight="51.0" prefWidth="210.0" text="Load saved">
<font>
<Font size="18.0" />
</font></Button>
</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