From 2b47d764583ebf6e355162e52d5f35d94cdb2a21 Mon Sep 17 00:00:00 2001 From: Francesco Bariatti <francesco.bariatti@insa-rennes.fr> Date: Sat, 30 Apr 2016 19:31:03 +0200 Subject: [PATCH] Added choice for the color with which we want to play --- gui/src/controller/Controller.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/gui/src/controller/Controller.java b/gui/src/controller/Controller.java index 6c4c6d7..865ceca 100644 --- a/gui/src/controller/Controller.java +++ b/gui/src/controller/Controller.java @@ -5,11 +5,13 @@ import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; +import javafx.scene.control.ChoiceDialog; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.paint.Color; import javafx.scene.shape.Polygon; import model.GameState; +import model.Player; import model.Tile; import view.TileView; @@ -27,6 +29,7 @@ public class Controller implements Initializable private PrintWriter gameInput; private Tile[] board; private TileView[] boardView; + private Player humanPlayer; @FXML private Polygon tile0, tile1, tile2, tile3, tile4, tile5, tile6, tile7, tile8, tile9, tile10, tile11, tile12, tile13, tile14, tile15, tile16, tile17, tile18, tile19, tile20, tile21, tile22, tile23, tile24, tile25, tile26, tile27, tile28, tile29, tile30, tile31, tile32, tile33, tile34, tile35, tile36, tile37, tile38, tile39, tile40, tile41, tile42, tile43, tile44, tile45, tile46, tile47, tile48, tile49, tile50, tile51, tile52, tile53, tile54, tile55, tile56, tile57, tile58, tile59; @@ -69,8 +72,23 @@ public class Controller implements Initializable upT.setDaemon(true); upT.start(); - //We tell the game that we will start - gameInput.println("h"); + //Choice: who will start? + ChoiceDialog<Player> playerChoice = new ChoiceDialog<>(Player.Red, Player.Red, Player.Blue); + playerChoice.setTitle("Penguin game!"); + playerChoice.setHeaderText("Choose your color (red starts)"); + playerChoice.showAndWait(); + humanPlayer = playerChoice.getResult(); + if (humanPlayer == null) + { + System.exit(0); + } + else + { + if (humanPlayer.equals(Player.Red)) + gameInput.println("h"); + else + gameInput.println("c"); + } } -- GitLab