- if (! disqual) {
- if (delta > 0) {
- gameManager.addToGameSummary("Troll walks right.");
- model.trollPosition++;
- }
- else if (delta < 0) {
- gameManager.addToGameSummary("Troll walks left.");
- model.trollPosition--;
- }
- else {
- gameManager.addToGameSummary("Troll stands still.");
- // XXX animate
- }
- view.moveTroll();
+ /* If a player cheated, delta is unusable as is.
+ * (Consider the case the player on the right sent
+ * INT_MIN. INT_MIN * (-1) = INT_MIN, so that player
+ * would both glean the stones *and* push the troll away.
+ * It would be unfair to have a cheating player "win"
+ * (earn the opponent castle destruction animation) this
+ * way.
+ */
+ boolean cheat0 = gameManager.getPlayer(0).isActive()
+ && gameManager.getPlayer(0).stoneThrow < 0;
+ boolean cheat1 = gameManager.getPlayer(1).isActive()
+ && gameManager.getPlayer(1).stoneThrow < 0;
+ if (cheat0 && cheat1); // here we can actually keep delta's value
+ else if (cheat0) delta = -1;
+ else if (cheat1) delta = 1;
+
+ if (delta > 0) {
+ model.trollPosition++;
+ view.moveTroll(View.Dir.RIGHT);
+ }
+ else if (delta < 0) {
+ model.trollPosition--;
+ view.moveTroll(View.Dir.LEFT);
+ }
+ else {
+ view.moveTroll(View.Dir.STILL);
+ // XXX animate
+ }