From ca0d48a06332161be61356f5252cb5efea849046 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 3 May 2014 22:24:11 +0200 Subject: Implement "new" command that creates a new game --- src/esieequest/Main.java | 2 +- src/esieequest/controller/commands/NewCommand.java | 7 ++---- src/esieequest/model/Game.java | 26 +++++++++++++++++----- src/esieequest/model/Player.java | 16 +------------ 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 { } if (arguments.contains("--challenge")) { - game = new Game(50); + game = new Game(true); } else { game = new Game(); } 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; import esieequest.model.Game; import esieequest.model.Text; -import esieequest.model.map.Direction; -import esieequest.model.map.Room; import esieequest.view.Viewable; /** @@ -16,11 +14,10 @@ public class NewCommand implements Executable { @Override public void execute(final String argument, final Game game, final Viewable view) { - // TODO: load a new game - game.getPlayer().setCurrentDirection(Direction.NORTH); - game.getPlayer().setCurrentRoom(Room.AMPHITHEATER_SEAT); + game.newGame(); view.enable(); + view.updateLocation(game.getPlayer().getCurrentRoom(), game.getPlayer().getCurrentDirection(), game.getPlayer().getCurrentSide()); view.echo(Text.WELCOME.getText()); 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; */ public class Game { - private final Player player; + private static final int DEFAULT_INVENTORY_LIMIT = 10; + private static final int DEFAULT_STEPS_LIMIT = 0; + private static final int CHALLENGE_STEPS_LIMIT = 50; + private static final Direction DEFAULT_DIRECTION = Direction.NORTH; + private static final Room DEFAULT_ROOM = Room.AMPHITHEATER_SEAT; + + private final boolean challenge; + private Player player; /** * Creates a Game with a step limit for the Player. @@ -26,18 +33,25 @@ public class Game { * @param maxNbSteps * the step limit for the Player */ - public Game(final int maxNbSteps) { - this.player = new Player(10, maxNbSteps); + public Game(final boolean challenge) { + this.challenge = challenge; this.connectRooms(); - this.addItems(); - this.addCharacters(); } /** * Creates a Game. */ public Game() { - this(0); + this(false); + } + + /** + * Initialises a new Game. + */ + public void newGame() { + this.player = new Player(Game.DEFAULT_ROOM, Game.DEFAULT_DIRECTION, Game.DEFAULT_INVENTORY_LIMIT, this.challenge ? Game.CHALLENGE_STEPS_LIMIT : Game.DEFAULT_STEPS_LIMIT); + this.addItems(); + this.addCharacters(); } /** 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 @@ package esieequest.model; import java.util.ArrayList; -import java.util.List; import java.util.Stack; import net.pacien.util.IntrinsicMap; @@ -42,7 +41,7 @@ public class Player { * @param nbStepsLimit * the maximum number of steps */ - private Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) { + public Player(final Room currentRoom, final Direction currentDirection, final int carryWeightLimit, final int nbStepsLimit) { this.currentRoom = currentRoom; this.previousRooms = new Stack<>(); this.currentDirection = currentDirection; @@ -52,19 +51,6 @@ public class Player { this.nbStepsLimit = nbStepsLimit; } - /** - * Creates a Player with limits (inventory weight and number of steps), - * without a default location (Room and Direction) - * - * @param carryWeightLimit - * the inventory weight limit - * @param nbStepsLimit - * the maximum number of steps - */ - public Player(final int carryWeightLimit, final int nbStepsLimit) { - this(null, null, carryWeightLimit, nbStepsLimit); - } - /** * @return the current Room */ -- cgit v1.2.3