aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-05-03 22:24:11 +0200
committerPacien TRAN-GIRARD2014-05-03 22:24:11 +0200
commitca0d48a06332161be61356f5252cb5efea849046 (patch)
tree3bd42c4241d3d858ebfe6a1f656768a70b5d53c8
parent4f3bc9bc43dac5da14d0d6604359deca5e3a3b0c (diff)
downloadesieequest-ca0d48a06332161be61356f5252cb5efea849046.tar.gz
Implement "new" command that creates a new game
-rwxr-xr-xsrc/esieequest/Main.java2
-rw-r--r--src/esieequest/controller/commands/NewCommand.java7
-rw-r--r--src/esieequest/model/Game.java26
-rw-r--r--src/esieequest/model/Player.java16
4 files changed, 24 insertions, 27 deletions
diff --git a/src/esieequest/Main.java b/src/esieequest/Main.java
index 974a6be..6e7c0f2 100755
--- a/src/esieequest/Main.java
+++ b/src/esieequest/Main.java
@@ -63,7 +63,7 @@ public class Main extends JApplet {
63 } 63 }
64 64
65 if (arguments.contains("--challenge")) { 65 if (arguments.contains("--challenge")) {
66 game = new Game(50); 66 game = new Game(true);
67 } else { 67 } else {
68 game = new Game(); 68 game = new Game();
69 } 69 }
diff --git a/src/esieequest/controller/commands/NewCommand.java b/src/esieequest/controller/commands/NewCommand.java
index dcb4f8f..00fe2fa 100644
--- a/src/esieequest/controller/commands/NewCommand.java
+++ b/src/esieequest/controller/commands/NewCommand.java
@@ -2,8 +2,6 @@ package esieequest.controller.commands;
2 2
3import esieequest.model.Game; 3import esieequest.model.Game;
4import esieequest.model.Text; 4import esieequest.model.Text;
5import esieequest.model.map.Direction;
6import esieequest.model.map.Room;
7import esieequest.view.Viewable; 5import esieequest.view.Viewable;
8 6
9/** 7/**
@@ -16,11 +14,10 @@ public class NewCommand implements Executable {
16 @Override 14 @Override
17 public void execute(final String argument, final Game game, final Viewable view) { 15 public void execute(final String argument, final Game game, final Viewable view) {
18 16
19 // TODO: load a new game 17 game.newGame();
20 game.getPlayer().setCurrentDirection(Direction.NORTH);
21 game.getPlayer().setCurrentRoom(Room.AMPHITHEATER_SEAT);
22 18
23 view.enable(); 19 view.enable();
20
24 view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); 21 view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide());
25 view.echo(Text.WELCOME.getText()); 22 view.echo(Text.WELCOME.getText());
26 23
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 6267d1a..6571d3f 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -18,7 +18,14 @@ import esieequest.model.map.Room;
18 */ 18 */
19public class Game { 19public class Game {
20 20
21 private final Player player; 21 private static final int DEFAULT_INVENTORY_LIMIT = 10;
22 private static final int DEFAULT_STEPS_LIMIT = 0;
23 private static final int CHALLENGE_STEPS_LIMIT = 50;
24 private static final Direction DEFAULT_DIRECTION = Direction.NORTH;
25 private static final Room DEFAULT_ROOM = Room.AMPHITHEATER_SEAT;
26
27 private final boolean challenge;
28 private Player player;
22 29
23 /** 30 /**
24 * Creates a Game with a step limit for the Player. 31 * Creates a Game with a step limit for the Player.
@@ -26,18 +33,25 @@ public class Game {
26 * @param maxNbSteps 33 * @param maxNbSteps
27 * the step limit for the Player 34 * the step limit for the Player
28 */ 35 */
29 public Game(final int maxNbSteps) { 36 public Game(final boolean challenge) {
30 this.player = new Player(10, maxNbSteps); 37 this.challenge = challenge;
31 this.connectRooms(); 38 this.connectRooms();
32 this.addItems();
33 this.addCharacters();
34 } 39 }
35 40
36 /** 41 /**
37 * Creates a Game. 42 * Creates a Game.
38 */ 43 */
39 public Game() { 44 public Game() {
40 this(0); 45 this(false);
46 }
47
48 /**
49 * Initialises a new Game.
50 */
51 public void newGame() {
52 this.player = new Player(Game.DEFAULT_ROOM, Game.DEFAULT_DIRECTION, Game.DEFAULT_INVENTORY_LIMIT, this.challenge ? Game.CHALLENGE_STEPS_LIMIT : Game.DEFAULT_STEPS_LIMIT);
53 this.addItems();
54 this.addCharacters();
41 } 55 }
42 56
43 /** 57 /**
diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java
index 2ab8190..ec7b0b5 100644
--- a/src/esieequest/model/Player.java
+++ b/src/esieequest/model/Player.java
@@ -1,7 +1,6 @@
1package esieequest.model; 1package esieequest.model;
2 2
3import java.util.ArrayList; 3import java.util.ArrayList;
4import java.util.List;
5import java.util.Stack; 4import java.util.Stack;
6 5
7import net.pacien.util.IntrinsicMap; 6import net.pacien.util.IntrinsicMap;
@@ -42,7 +41,7 @@ public class Player {
42 * @param nbStepsLimit 41 * @param nbStepsLimit
43 * the maximum number of steps 42 * the maximum number of steps
44 */ 43 */
45 private Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) { 44 public Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) {
46 this.currentRoom = currentRoom; 45 this.currentRoom = currentRoom;
47 this.previousRooms = new Stack<>(); 46 this.previousRooms = new Stack<>();
48 this.currentDirection = currentDirection; 47 this.currentDirection = currentDirection;
@@ -53,19 +52,6 @@ public class Player {
53 } 52 }
54 53
55 /** 54 /**
56 * Creates a Player with limits (inventory weight and number of steps),
57 * without a default location (Room and Direction)
58 *
59 * @param carryWeightLimit
60 * the inventory weight limit
61 * @param nbStepsLimit
62 * the maximum number of steps
63 */
64 public Player(final int carryWeightLimit, final int nbStepsLimit) {
65 this(null, null, carryWeightLimit, nbStepsLimit);
66 }
67
68 /**
69 * @return the current Room 55 * @return the current Room
70 */ 56 */
71 public Room getCurrentRoom() { 57 public Room getCurrentRoom() {