Don't destroy the castle if the troll doesn't reach it
authorJBM <jbm@codingame.com>
Mon, 25 May 2020 08:52:55 +0000 (10:52 +0200)
committerJBM <jbm@codingame.com>
Wed, 27 May 2020 14:53:54 +0000 (16:53 +0200)
config/statement_en.html
src/main/java/com/codingame/game/Referee.java
src/main/java/com/codingame/game/View.java

index 3145916..2f674bc 100644 (file)
        <span>Change Log</span>
      </h2>
      <ul>
        <span>Change Log</span>
      </h2>
      <ul>
+       <li>
+         Don't destroy the castle if the troll doesn't reach it.
+       </li>
+       <li>
+         Ensure proper troll movement direction in all cases of
+         cheating.
+       </li>
        <li>
          Fixed the road length fencepost non-issue.
        </li>
        <li>
          Fixed the road length fencepost non-issue.
        </li>
index eaac5fb..0c87bbf 100644 (file)
@@ -168,6 +168,7 @@ public class Referee extends AbstractReferee {
             if (model.haveWinner()) {
                 int loser = model.getLoser();
                 gameManager.addToGameSummary(GameManager.formatErrorMessage("Troll destroys " + gameManager.getPlayer(loser).getNicknameToken()) + ".");
             if (model.haveWinner()) {
                 int loser = model.getLoser();
                 gameManager.addToGameSummary(GameManager.formatErrorMessage("Troll destroys " + gameManager.getPlayer(loser).getNicknameToken()) + ".");
+                gameManager.getPlayer(loser).view.destroy();
                 victory = true;
             }
             else if (model.exhausted()) exhausted = true;
                 victory = true;
             }
             else if (model.exhausted()) exhausted = true;
@@ -187,16 +188,16 @@ public class Referee extends AbstractReferee {
 
         if (s0 > s1) {
             gameManager.addToGameSummary(GameManager.formatSuccessMessage(p0.getNicknameToken() + " wins."));
 
         if (s0 > s1) {
             gameManager.addToGameSummary(GameManager.formatSuccessMessage(p0.getNicknameToken() + " wins."));
-            p1.view.destroy();
+            p1.view.markLoser();
         }
         else if (s0 < s1) {
             gameManager.addToGameSummary(GameManager.formatSuccessMessage(p1.getNicknameToken() + " wins."));
         }
         else if (s0 < s1) {
             gameManager.addToGameSummary(GameManager.formatSuccessMessage(p1.getNicknameToken() + " wins."));
-            p0.view.destroy();
+            p0.view.markLoser();
         }
         else if (s0 < 0) {
             gameManager.addToGameSummary(GameManager.formatErrorMessage("Everybody loses!"));
         }
         else if (s0 < 0) {
             gameManager.addToGameSummary(GameManager.formatErrorMessage("Everybody loses!"));
-            p0.view.destroy();
-            p1.view.destroy();
+            p0.view.markLoser();
+            p1.view.markLoser();
         }
         else {
             gameManager.addToGameSummary("Draw.");
         }
         else {
             gameManager.addToGameSummary("Draw.");
index b8d42c4..21489ff 100644 (file)
@@ -165,11 +165,13 @@ class View {
             graphicEntityModule.commitEntityState(0, message);
         }
 
             graphicEntityModule.commitEntityState(0, message);
         }
 
-        void destroy() {
+        void markLoser() {
             graphicEntityModule.commitEntityState(0.5, avatar);
             int dir = random.nextInt(2) == 1 ? 1 : -1;
             avatar.setRotation(dir * 170 * Math.PI / 180, Curve.ELASTIC);
             graphicEntityModule.commitEntityState(0.5, avatar);
             int dir = random.nextInt(2) == 1 ? 1 : -1;
             avatar.setRotation(dir * 170 * Math.PI / 180, Curve.ELASTIC);
+        }
 
 
+        void destroy() {
             graphicEntityModule.commitEntityState(0.5, castle);
             castle.setX(castle.getX(), Curve.ELASTIC);
             castle.setScaleY(-0.2, Curve.EASE_IN);
             graphicEntityModule.commitEntityState(0.5, castle);
             castle.setX(castle.getX(), Curve.ELASTIC);
             castle.setScaleY(-0.2, Curve.EASE_IN);