Messaging
[troll.git] / src / main / java / com / codingame / game / Referee.java
index 5b6ec3a..7efe7b3 100644 (file)
@@ -134,6 +134,16 @@ public class Referee extends AbstractReferee {
                 .setFillColor(0x7f3f00)
                 .setAnchor(0.5);
 
+            player.message = graphicEntityModule.createText()
+                .setX(p0 ? 15 : 1920-15)
+                .setY(680)
+                .setZIndex(1)
+                .setFontSize(40)
+                .setStrokeColor(0x000000)
+                .setFillColor(0xffbf7f)
+                .setAnchorX(p0 ? 0 : 1)
+                .setAnchorY(1);
+
             player.castle = graphicEntityModule.createSprite()
                 .setImage("castle.png")
                 .setTint(player.getColorToken())
@@ -150,7 +160,6 @@ public class Referee extends AbstractReferee {
                 .setFillColor(0x12322a)
                 .setAnchor(0.5)
                 .setAlpha(0);
-
         }
     }
 
@@ -266,6 +275,11 @@ public class Referee extends AbstractReferee {
                 player.setScore(-1);
                 endGame();
             }
+
+            player.message
+                .setText(player.getMessageString());
+            //  .setAnchorX(/*player == p0 ? 0 : */ 1);
+            graphicEntityModule.commitEntityState(0, player.message);
         }
 
         if (delta > 0) {
@@ -304,23 +318,25 @@ public class Referee extends AbstractReferee {
     }
 
     private void endGame() {
-        gameManager.endGame();
+        if (! gameManager.isGameEnd()) {
+            gameManager.endGame();
 
-        if (p0.getScore() > p1.getScore()) {
-            gameManager.addToGameSummary(GameManager.formatSuccessMessage(p0.getNicknameToken() + " wins"));
-            destroyPlayer(p1);
-        }
-        else if (p0.getScore() < p1.getScore()) {
-            gameManager.addToGameSummary(GameManager.formatSuccessMessage(p1.getNicknameToken() + " wins"));
-            destroyPlayer(p0);
-        }
-        else if (p0.getScore() < 0) {
-            gameManager.addToGameSummary(GameManager.formatErrorMessage("Everybody loses!"));
-            destroyPlayer(p0);
-            destroyPlayer(p1);
-        }
-        else {
-            gameManager.addToGameSummary("Draw.");
+            if (p0.getScore() > p1.getScore()) {
+                gameManager.addToGameSummary(GameManager.formatSuccessMessage(p0.getNicknameToken() + " wins"));
+                destroyPlayer(p1);
+            }
+            else if (p0.getScore() < p1.getScore()) {
+                gameManager.addToGameSummary(GameManager.formatSuccessMessage(p1.getNicknameToken() + " wins"));
+                destroyPlayer(p0);
+            }
+            else if (p0.getScore() < 0) {
+                gameManager.addToGameSummary(GameManager.formatErrorMessage("Everybody loses!"));
+                destroyPlayer(p0);
+                destroyPlayer(p1);
+            }
+            else {
+                gameManager.addToGameSummary("Draw.");
+            }
         }
     }
 }