From 5411f947e8f2b4a409bca3c81c958c066f0f428c Mon Sep 17 00:00:00 2001
From: Francesco Bariatti <francesco.bariatti@insa-rennes.fr>
Date: Sun, 1 May 2016 15:43:24 +0200
Subject: [PATCH] Modified GUI end of game function

---
 gui/src/controller/UpdateThread.java | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/gui/src/controller/UpdateThread.java b/gui/src/controller/UpdateThread.java
index 5a318f0..9a2e539 100644
--- a/gui/src/controller/UpdateThread.java
+++ b/gui/src/controller/UpdateThread.java
@@ -41,18 +41,21 @@ public class UpdateThread extends Thread
 				System.out.println(line);
 				if (line == null)
 				{
-					Platform.runLater(() ->
-					{
-						Player computer = Player.Red;
-						if (humanPlayer.equals(Player.Red))
-							computer = Player.Blue;
-						Alert alert = new Alert(Alert.AlertType.INFORMATION);
-						if (gameState.getScore(humanPlayer) > gameState.getScore(computer))
-							alert.setHeaderText("You won!!!!");
-						else if (gameState.getScore(humanPlayer) == gameState.getScore(computer))
-							alert.setHeaderText("That's a draw. Not bad!");
+					gameRunning = false;
+				}
+				else if(line.startsWith(Player.Red+" won") || line.startsWith(Player.Blue+" won") || line.startsWith("draw"))
+				{
+					//System.out.println("======= END OF GAME=======");
+					Platform.runLater(() -> {
+						Player computer = humanPlayer.equals(Player.Red) ? Player.Blue : Player.Red;
+						String message = "";
+						if (line.startsWith(humanPlayer.toString())) //Human won
+							message = "You won!!! I can't believe it!";
+						else if (line.startsWith(computer.toString()))
+							message = "You just lost the penguin game.";
 						else
-							alert.setHeaderText("You just lost the penguin game.");
+							message = "That's a draw. Not bad!";
+						Alert alert  = new Alert(Alert.AlertType.INFORMATION, message, ButtonType.OK);
 						alert.showAndWait();
 					});
 					gameRunning = false;
-- 
GitLab