From 2fee72805e1025a298295e6d86de18e48de4b52a Mon Sep 17 00:00:00 2001 From: Benoît LUBRANO DI SBARAGLIONE Date: Wed, 9 Apr 2014 11:26:33 +0200 Subject: Add challenge mode with walk method. --- src/esieequest/Main.java | 4 ++++ src/esieequest/controller/Performer.java | 10 +++++++++ src/esieequest/model/entities/Player.java | 34 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) (limited to 'src') diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java index 59ac568..e8cff08 100755 --- a/src/esieequest/Main.java +++ b/src/esieequest/Main.java @@ -62,6 +62,10 @@ public class Main extends JApplet { view = new Window(); } + if(arguments.contains("--challenge")) { + game.getPlayer().setMaxNbSteps(50); + } + new GameEngine(game, view); } diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java index 7ba8c94..63cf75b 100644 --- a/src/esieequest/controller/Performer.java +++ b/src/esieequest/controller/Performer.java @@ -110,6 +110,7 @@ class Performer { if (nextRoom != null) { this.game.getPlayer().goToRoom(nextRoom); this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); + this.walk(); } else { this.echo(this.game.getNoExitMessage()); } @@ -121,6 +122,15 @@ class Performer { public void goBack() { this.game.getPlayer().goToPreviousRoom(); this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); + this.walk(); + } + + private void walk() { + this.game.getPlayer().setNbSteps(this.game.getPlayer().getNbSteps() + 1); + if (this.game.getPlayer().getNbSteps() == this.game.getPlayer().getMaxNbSteps()) { + this.echo("You died of exhaustion..."); + this.quitGame(); + } } /** diff --git a/src/esieequest/model/entities/Player.java b/src/esieequest/model/entities/Player.java index 91888eb..16ac612 100644 --- a/src/esieequest/model/entities/Player.java +++ b/src/esieequest/model/entities/Player.java @@ -12,6 +12,9 @@ public class Player { private final Inventory inventory; private final int maxCarryWeight; + + private int nbSteps; + private int maxNbSteps; public Player(final int maxCarryWeight) { this.currentRoom = null; @@ -19,6 +22,9 @@ public class Player { this.inventory = new Inventory(); this.maxCarryWeight = maxCarryWeight; + + this.nbSteps = 0; + this.maxNbSteps = 0; } /** @@ -66,4 +72,32 @@ public class Player { return this.maxCarryWeight; } + /** + * @return the nbSteps + */ + public int getNbSteps() { + return nbSteps; + } + + /** + * @param nbSteps the nbSteps to set + */ + public void setNbSteps(int nbSteps) { + this.nbSteps = nbSteps; + } + + /** + * @return the maxNbSteps + */ + public int getMaxNbSteps() { + return maxNbSteps; + } + + /** + * @param maxNbSteps the maxNbSteps to set + */ + public void setMaxNbSteps(int maxNbSteps) { + this.maxNbSteps = maxNbSteps; + } + } -- cgit v1.2.3