diff --git a/gui/src/controller/Controller.java b/gui/src/controller/Controller.java index c17fdf65fff3d3b972dc5a221ce5c077eb578624..1d648743f577f17428136e715d1fee853c1904ac 100644 --- a/gui/src/controller/Controller.java +++ b/gui/src/controller/Controller.java @@ -29,6 +29,7 @@ import java.util.ResourceBundle; public class Controller implements Initializable { + private static final String iaProgramPath = "../bin/theturk"; private static final String introMusicFile = "./resource/pingu_theme.wav"; private static final String clickSoundFile = "./resource/clic.wav"; @@ -50,7 +51,7 @@ public class Controller implements Initializable private BorderPane mainPane; @FXML - private Label scoreRedLabel, scoreBlueLabel, turnLabel; + private Label scoreRedLabel, scoreBlueLabel, turnLabel, statusLabel; @Override public void initialize(URL location, ResourceBundle resources) @@ -67,7 +68,7 @@ public class Controller implements Initializable this.gameState = new GameState(); try { - this.gameProcess = new ProcessBuilder("../bin/theturk").start(); + this.gameProcess = new ProcessBuilder(iaProgramPath).start(); gameInput = new PrintWriter(new OutputStreamWriter(gameProcess.getOutputStream()), true); Runtime.getRuntime().addShutdownHook(new Thread() { @@ -76,7 +77,7 @@ public class Controller implements Initializable gameProcess.destroy(); } }); - UpdateThread upT = new UpdateThread(gameProcess, this.gameState, this.board, this.boardView, scoreRedLabel, scoreBlueLabel, turnLabel); + UpdateThread upT = new UpdateThread(gameProcess, this.gameState, this.board, this.boardView, scoreRedLabel, scoreBlueLabel, turnLabel, statusLabel); upT.setDaemon(true); upT.start(); } catch (IOException e) @@ -135,6 +136,7 @@ public class Controller implements Initializable t.getFxTile().setOnMouseClicked(phandl); t.getFishLabel().setOnMouseClicked(phandl); } + statusLabel.setText("Click to place RED penguins"); } } @@ -189,6 +191,16 @@ public class Controller implements Initializable boardView[tileNumber].update(); } penguinGenCounter++; + if(penguinGenCounter < 4) + statusLabel.setText("Red penguins left: "+Integer.toString(4-penguinGenCounter)); + else if (penguinGenCounter == 4) + statusLabel.setText("Click to place BLUE penguins"); + else if (penguinGenCounter < 8) + statusLabel.setText("Blue penguins left: "+Integer.toString(8-penguinGenCounter)); + else + statusLabel.setText(""); + + //If we placed all penguins if (penguinGenCounter >= 8) { gameInput.println(gameState.toGameInputJSON()); diff --git a/gui/src/controller/UpdateThread.java b/gui/src/controller/UpdateThread.java index 995e1c48eb2967d69dc28e8fdf147252b41f9d71..5aefad0dcc18e62982b1839269216e2aac8ea640 100644 --- a/gui/src/controller/UpdateThread.java +++ b/gui/src/controller/UpdateThread.java @@ -18,9 +18,9 @@ public class UpdateThread extends Thread GameState gameState; Tile[] board; TileView[] boardView; - Label scoreRed, scoreBlue, turnLabel; + Label scoreRed, scoreBlue, turnLabel, statusLabel; - public UpdateThread(Process program, GameState gameState, Tile[] board, TileView[] boardView, Label scoreRed, Label scoreBlue, Label turnLabel) + public UpdateThread(Process program, GameState gameState, Tile[] board, TileView[] boardView, Label scoreRed, Label scoreBlue, Label turnLabel, Label statusLabel) { this.reader = new BufferedReader(new InputStreamReader(program.getInputStream())); this.writer = new PrintWriter(new OutputStreamWriter(program.getOutputStream()), true); @@ -30,6 +30,7 @@ public class UpdateThread extends Thread this.scoreRed = scoreRed; this.scoreBlue = scoreBlue; this.turnLabel = turnLabel; + this.statusLabel = statusLabel; } public void run() @@ -97,6 +98,29 @@ public class UpdateThread extends Thread } } } + else if (line.startsWith("(") && line.contains("value:")) //lines with values (estimation) of the computer winning chances + { //We want to show a little message to the user depending on if we win or not + Platform.runLater(() -> { + try + { + float value = Float.valueOf(line.substring(line.indexOf("value:") + 7, line.indexOf(")"))); + if (value > 0.8) + statusLabel.setText("Are you sure you don't want to give up?"); + else if (value > 0.3) + statusLabel.setText("You may want to think harder..."); + else if (value > -0.3) + statusLabel.setText("I will win, in the end"); + else if (value > -0.8) + statusLabel.setText("You may think you are winning... but you are not really"); + else + statusLabel.setText("I can not believe it... Human too strong... Segmentation fault."); + } + catch (Exception e) //This is not a core function, so if there is an exception we just ignore it + { + e.printStackTrace(); + } + }); + } } catch (IOException e) { gameRunning = false; diff --git a/gui/src/view/view.fxml b/gui/src/view/view.fxml index eefa9ef5eb6064106acbe06709929d8c790e153a..ca2ba6f4db0176f4a2e6fb1fb8531472de91242f 100644 --- a/gui/src/view/view.fxml +++ b/gui/src/view/view.fxml @@ -1,20 +1,16 @@ <?xml version="1.0" encoding="UTF-8"?> -<?import javafx.scene.image.*?> -<?import javafx.geometry.*?> -<?import javafx.scene.text.*?> -<?import java.lang.*?> -<?import javafx.scene.control.*?> -<?import javafx.scene.layout.*?> -<?import javafx.scene.shape.*?> <?import java.lang.Double?> +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Label?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.BorderPane?> <?import javafx.scene.shape.Polygon?> +<?import javafx.scene.text.Font?> -<BorderPane fx:id="mainPane" xmlns="http://javafx.com/javafx/8.0.92" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.Controller"> +<BorderPane fx:id="mainPane" xmlns="http://javafx.com/javafx/8.0.91" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.Controller"> <center> - <AnchorPane prefHeight="487.0" prefWidth="557.0" BorderPane.alignment="CENTER"> + <AnchorPane prefHeight="576.0" prefWidth="597.0" BorderPane.alignment="CENTER"> <children> <Polygon fx:id="tile7" fill="#1f93ff" layoutX="39.0" layoutY="434.0" stroke="BLACK" strokeType="INSIDE"> <points> @@ -1077,6 +1073,11 @@ <Label fx:id="nbFish22" layoutX="34.0" layoutY="337.0" text="0" /> <Label fx:id="nbFish37" layoutX="34.0" layoutY="247.0" text="0" /> <Label fx:id="nbFish52" layoutX="34.0" layoutY="157.0" text="0" /> + <Label fx:id="statusLabel" alignment="CENTER" layoutX="29.0" layoutY="484.0" prefHeight="87.0" prefWidth="383.0" text="Good luck!" textAlignment="CENTER" wrapText="true"> + <font> + <Font size="22.0" /> + </font> + </Label> </children> </AnchorPane> </center>