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

Write for tournament works now, have not figured out the read yet

parent e5e79791
No related branches found
No related tags found
No related merge requests found
......@@ -109,19 +109,19 @@ public class BracketViewController extends TournamentController {
}
public void onPressLoad() {
try
{
tournamentRegister.addPlayers(FileHandler.readCsv(Path.of("TEMPOTOURNAMENT")));
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("tournament-match-view.fxml");
try
{
TableTennisApplication tableTennisApplication = new TableTennisApplication();
BracketViewController.tournamentRegister.addPlayers(FileHandler.readCsv(Path.of("NEWTOURNAMENT.csv")));
tableTennisApplication.changeScene("tournament-match-view.fxml");
}catch (Exception e){
}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{
......
......@@ -96,7 +96,7 @@ public class MatchController extends TournamentController implements Initializab
public void onPressSaveMatch() throws IOException{
FileHandler.writeCsv(tournamentRegister.getParticipants(), "TEMPONAME");
FileHandler.writeCsv(tournamentRegister.getParticipants(), "SINGLELOAD");
TournamentController.tournamentRegister.clear();
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("table-tennis-view.fxml");
......
......@@ -97,7 +97,7 @@ public class TournamentController {
public void onLoadPressed(ActionEvent actionEvent) throws IOException{
try
{
tournamentRegister.addPlayers(FileHandler.readCsv(Path.of("TEMPONAME")));
tournamentRegister.addPlayers(FileHandler.readCsv(Path.of("SINGLELOAD.csv")));
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("create_single_match_view.fxml");
......
......@@ -56,8 +56,6 @@ public class TournamentMatchController extends TournamentController implements I
if(BracketViewController.tournamentRegister.getParticipants().size() >= 2){
player1 = BracketViewController.tournamentRegister.getPlayer(0);
player2 = BracketViewController.tournamentRegister.getPlayer(1);
BracketViewController.tournamentRegister.removePlayer(player1);
BracketViewController.tournamentRegister.removePlayer(player2);
matchPlayer1label.setText(
player1.toString());
matchPlayer2label.setText(
......@@ -84,6 +82,8 @@ public class TournamentMatchController extends TournamentController implements I
scorePlayer1.setText(String.valueOf(Integer.parseInt((scorePlayer1.getText())) + 1));
try{
if (Integer.parseInt(scorePlayer1.getText()) >= 11) {
BracketViewController.tournamentRegister.removePlayer(player1);
BracketViewController.tournamentRegister.removePlayer(player2);
pointPlayer1.setOpacity(0);
pointPlayer1.setDisable(true);
pointPlayer2.setOpacity(0);
......@@ -110,6 +110,8 @@ public class TournamentMatchController extends TournamentController implements I
match.scorePLayer2();
scorePlayer2.setText(String.valueOf(Integer.parseInt((scorePlayer2.getText())) + 1));
if (Integer.parseInt(scorePlayer2.getText()) >= 11) {
BracketViewController.tournamentRegister.removePlayer(player1);
BracketViewController.tournamentRegister.removePlayer(player2);
pointPlayer1.setOpacity(0);
pointPlayer2.setOpacity(0);
pointPlayer1.setDisable(true);
......@@ -150,7 +152,7 @@ public class TournamentMatchController extends TournamentController implements I
*/
public void onPressSaveMatch() throws IOException{
//TODO: Unsure if this works, should be a relatively easy fix however
FileHandler.writeCsv(tournamentRegister.getParticipants(), "TEMPOTOURNAMENT");
FileHandler.writeCsv(BracketViewController.tournamentRegister.getParticipants(), "NEWTOURNAMENT");
BracketViewController.tournamentRegister.clear();
TableTennisApplication tableTennisApplication = new TableTennisApplication();
tableTennisApplication.changeScene("table-tennis-view.fxml");
......
......@@ -29,6 +29,7 @@ public class FileHandler {
BufferedWriter buffer = new BufferedWriter(file);
for (Player player : playerList) {
buffer.write(player.toString());
buffer.write("\n");
}
buffer.close();
}
......
......@@ -40,5 +40,6 @@
<Button fx:id="mainMenu" layoutX="348.0" layoutY="541.0" mnemonicParsing="false" onAction="#onPressBackToMenu" text="Return to main menu" />
<Button fx:id="saveButton" layoutX="705.0" layoutY="541.0" mnemonicParsing="false" onAction="#onPressSaveMatch" text="Save game" />
<Button fx:id="nextMatch" layoutX="541.0" layoutY="541.0" mnemonicParsing="false" onAction="#onNextMatchPress" text="Next match" />
<Button layoutX="322.0" layoutY="46.0" mnemonicParsing="false" text="Your mom" />
</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