From b0709c8a9de47169bbee25eed895d06fbeead12a Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 19 Apr 2014 14:55:34 +0200 Subject: Move the challenge mode logic --- src/esieequest/controller/commands/GoCommand.java | 3 +-- src/esieequest/model/Player.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/esieequest/controller/commands/GoCommand.java b/src/esieequest/controller/commands/GoCommand.java index 06260b2..61718a1 100644 --- a/src/esieequest/controller/commands/GoCommand.java +++ b/src/esieequest/controller/commands/GoCommand.java @@ -42,8 +42,7 @@ public class GoCommand implements CommandInterface { view.updateRoom(game.getPlayer().getCurrentRoom()); // handle challenge mode - game.getPlayer().setNbSteps(game.getPlayer().getNbSteps() + 1); - if (game.getPlayer().getNbSteps() == game.getPlayer().getNbStepsLimit()) { + if (game.getPlayer().walk()) { view.echo(Text.CHALLENGE_FAILED.getText()); view.disable(); } diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java index a35a776..3851c44 100644 --- a/src/esieequest/model/Player.java +++ b/src/esieequest/model/Player.java @@ -285,4 +285,14 @@ public class Player { return item; } + /** + * Increments the step counter. + * + * @return if the maximum number of steps has been reached + */ + public boolean walk() { + this.nbSteps++; + return this.nbSteps == this.nbStepsLimit; + } + } -- cgit v1.2.3