diff options
author | Benoît LUBRANO DI SBARAGLIONE | 2014-04-09 11:26:33 +0200 |
---|---|---|
committer | Benoît LUBRANO DI SBARAGLIONE | 2014-04-09 11:26:33 +0200 |
commit | 2fee72805e1025a298295e6d86de18e48de4b52a (patch) | |
tree | 7fc17f17dcb09d9630bd1d4f22272b9b845a1310 | |
parent | 23e37421c22c5f3dd1a9b6402a2fa7571f065717 (diff) | |
download | esieequest-2fee72805e1025a298295e6d86de18e48de4b52a.tar.gz |
Add challenge mode with walk method.
-rwxr-xr-x | src/esieequest/Main.java | 4 | ||||
-rw-r--r-- | src/esieequest/controller/Performer.java | 10 | ||||
-rw-r--r-- | src/esieequest/model/entities/Player.java | 34 |
3 files changed, 48 insertions, 0 deletions
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 { | |||
62 | view = new Window(); | 62 | view = new Window(); |
63 | } | 63 | } |
64 | 64 | ||
65 | if(arguments.contains("--challenge")) { | ||
66 | game.getPlayer().setMaxNbSteps(50); | ||
67 | } | ||
68 | |||
65 | new GameEngine(game, view); | 69 | new GameEngine(game, view); |
66 | } | 70 | } |
67 | 71 | ||
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 { | |||
110 | if (nextRoom != null) { | 110 | if (nextRoom != null) { |
111 | this.game.getPlayer().goToRoom(nextRoom); | 111 | this.game.getPlayer().goToRoom(nextRoom); |
112 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); | 112 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); |
113 | this.walk(); | ||
113 | } else { | 114 | } else { |
114 | this.echo(this.game.getNoExitMessage()); | 115 | this.echo(this.game.getNoExitMessage()); |
115 | } | 116 | } |
@@ -121,6 +122,15 @@ class Performer { | |||
121 | public void goBack() { | 122 | public void goBack() { |
122 | this.game.getPlayer().goToPreviousRoom(); | 123 | this.game.getPlayer().goToPreviousRoom(); |
123 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); | 124 | this.view.updateRoom(this.game.getPlayer().getCurrentRoom()); |
125 | this.walk(); | ||
126 | } | ||
127 | |||
128 | private void walk() { | ||
129 | this.game.getPlayer().setNbSteps(this.game.getPlayer().getNbSteps() + 1); | ||
130 | if (this.game.getPlayer().getNbSteps() == this.game.getPlayer().getMaxNbSteps()) { | ||
131 | this.echo("You died of exhaustion..."); | ||
132 | this.quitGame(); | ||
133 | } | ||
124 | } | 134 | } |
125 | 135 | ||
126 | /** | 136 | /** |
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 { | |||
12 | 12 | ||
13 | private final Inventory inventory; | 13 | private final Inventory inventory; |
14 | private final int maxCarryWeight; | 14 | private final int maxCarryWeight; |
15 | |||
16 | private int nbSteps; | ||
17 | private int maxNbSteps; | ||
15 | 18 | ||
16 | public Player(final int maxCarryWeight) { | 19 | public Player(final int maxCarryWeight) { |
17 | this.currentRoom = null; | 20 | this.currentRoom = null; |
@@ -19,6 +22,9 @@ public class Player { | |||
19 | 22 | ||
20 | this.inventory = new Inventory(); | 23 | this.inventory = new Inventory(); |
21 | this.maxCarryWeight = maxCarryWeight; | 24 | this.maxCarryWeight = maxCarryWeight; |
25 | |||
26 | this.nbSteps = 0; | ||
27 | this.maxNbSteps = 0; | ||
22 | } | 28 | } |
23 | 29 | ||
24 | /** | 30 | /** |
@@ -66,4 +72,32 @@ public class Player { | |||
66 | return this.maxCarryWeight; | 72 | return this.maxCarryWeight; |
67 | } | 73 | } |
68 | 74 | ||
75 | /** | ||
76 | * @return the nbSteps | ||
77 | */ | ||
78 | public int getNbSteps() { | ||
79 | return nbSteps; | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * @param nbSteps the nbSteps to set | ||
84 | */ | ||
85 | public void setNbSteps(int nbSteps) { | ||
86 | this.nbSteps = nbSteps; | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * @return the maxNbSteps | ||
91 | */ | ||
92 | public int getMaxNbSteps() { | ||
93 | return maxNbSteps; | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * @param maxNbSteps the maxNbSteps to set | ||
98 | */ | ||
99 | public void setMaxNbSteps(int maxNbSteps) { | ||
100 | this.maxNbSteps = maxNbSteps; | ||
101 | } | ||
102 | |||
69 | } | 103 | } |