Skip to content
Snippets Groups Projects
Commit b6ec98de authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Added status label for showing messages... and taunts!

parent 5108ccd1
No related branches found
No related tags found
No related merge requests found
......@@ -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());
......
......@@ -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;
......
<?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>
......
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