aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/esieequest/controller/Interpreter.java9
-rw-r--r--src/esieequest/controller/Parser.java2
-rw-r--r--src/esieequest/controller/Performer.java41
-rw-r--r--src/esieequest/controller/Utils.java40
-rw-r--r--src/esieequest/model/Game.java8
-rw-r--r--src/esieequest/model/Player.java44
-rw-r--r--src/esieequest/model/Side.java5
-rw-r--r--src/esieequest/model/command/package-info.java5
-rw-r--r--src/esieequest/model/commands/Command.java (renamed from src/esieequest/model/command/Command.java)2
-rw-r--r--src/esieequest/model/commands/CommandWord.java (renamed from src/esieequest/model/command/CommandWord.java)2
-rw-r--r--src/esieequest/model/commands/package-info.java5
-rw-r--r--src/esieequest/model/entities/Player.java83
-rw-r--r--src/esieequest/model/entities/package-info.java5
-rw-r--r--src/esieequest/model/events/Quest.java (renamed from src/esieequest/model/Quest.java)2
-rw-r--r--src/esieequest/model/events/package-info.java5
-rw-r--r--src/esieequest/model/items/Inventory.java57
-rw-r--r--src/esieequest/model/items/Item.java (renamed from src/esieequest/model/Item.java)9
-rw-r--r--src/esieequest/model/items/package-info.java5
-rw-r--r--src/esieequest/model/map/Room.java (renamed from src/esieequest/model/Room.java)78
-rw-r--r--src/esieequest/model/map/Side.java5
-rw-r--r--src/esieequest/model/map/package-info.java5
-rw-r--r--src/esieequest/view/View.java11
-rw-r--r--src/esieequest/view/app/UserInterface.java8
-rw-r--r--src/esieequest/view/text/TextInterface.java17
-rw-r--r--src/esieequest/view/web/WebInterface.java8
25 files changed, 320 insertions, 141 deletions
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java
index 586b329..8d0f703 100644
--- a/src/esieequest/controller/Interpreter.java
+++ b/src/esieequest/controller/Interpreter.java
@@ -1,7 +1,7 @@
1package esieequest.controller; 1package esieequest.controller;
2 2
3import esieequest.model.Game; 3import esieequest.model.Game;
4import esieequest.model.command.Command; 4import esieequest.model.commands.Command;
5import esieequest.view.View; 5import esieequest.view.View;
6 6
7/** 7/**
@@ -72,6 +72,12 @@ class Interpreter {
72 case "eat": 72 case "eat":
73 this.performer.eat(); 73 this.performer.eat();
74 return; 74 return;
75 case "take":
76 this.performer.take(command.getOption());
77 return;
78 case "drop":
79 this.performer.drop(command.getOption());
80 return;
75 case "help": 81 case "help":
76 this.performer.showHelp(); 82 this.performer.showHelp();
77 return; 83 return;
@@ -83,4 +89,5 @@ class Interpreter {
83 this.performer.echo("Unknown command."); 89 this.performer.echo("Unknown command.");
84 return; 90 return;
85 } 91 }
92
86} 93}
diff --git a/src/esieequest/controller/Parser.java b/src/esieequest/controller/Parser.java
index 0f97fd1..452c27c 100644
--- a/src/esieequest/controller/Parser.java
+++ b/src/esieequest/controller/Parser.java
@@ -1,6 +1,6 @@
1package esieequest.controller; 1package esieequest.controller;
2 2
3import esieequest.model.command.Command; 3import esieequest.model.commands.Command;
4 4
5/** 5/**
6 * The command parser. 6 * The command parser.
diff --git a/src/esieequest/controller/Performer.java b/src/esieequest/controller/Performer.java
index 96a95df..1abc887 100644
--- a/src/esieequest/controller/Performer.java
+++ b/src/esieequest/controller/Performer.java
@@ -1,7 +1,8 @@
1package esieequest.controller; 1package esieequest.controller;
2 2
3import esieequest.model.Game; 3import esieequest.model.Game;
4import esieequest.model.Room; 4import esieequest.model.items.Inventory;
5import esieequest.model.map.Room;
5import esieequest.view.View; 6import esieequest.view.View;
6 7
7/** 8/**
@@ -130,4 +131,42 @@ class Performer {
130 this.echo(this.game.getEatMessage()); 131 this.echo(this.game.getEatMessage());
131 } 132 }
132 133
134 /**
135 * Moves an item from the current Room to the Player's inventory.
136 *
137 * @param itemName
138 * the item's name
139 */
140 public void take(final String itemName) {
141 this.moveItem(this.game.getPlayer().getCurrentRoom(), this.game.getPlayer(), itemName);
142 }
143
144 /**
145 * Moves an item from the Player's inventory to the current Room.
146 *
147 * @param itemName
148 * the item's name
149 */
150 public void drop(final String itemName) {
151 this.moveItem(this.game.getPlayer(), this.game.getPlayer().getCurrentRoom(), itemName);
152 }
153
154 /**
155 * Moves a given item referred by its name from an inventory to another.
156 *
157 * @param source
158 * the source inventory
159 * @param dest
160 * the destination inventory
161 * @param itemName
162 * the item's name
163 */
164 private void moveItem(final Inventory source, final Inventory dest, final String itemName) {
165 if (!source.hasItem(itemName)) {
166 this.echo("No such item.");
167 return;
168 }
169 dest.putItem(itemName, source.takeItem(itemName));
170 }
171
133} 172}
diff --git a/src/esieequest/controller/Utils.java b/src/esieequest/controller/Utils.java
new file mode 100644
index 0000000..139798c
--- /dev/null
+++ b/src/esieequest/controller/Utils.java
@@ -0,0 +1,40 @@
1package esieequest.controller;
2
3import java.util.Set;
4
5public class Utils {
6
7 /**
8 *
9 * @param elements
10 * the elements
11 * @param prefix
12 * the prefix of the list
13 * @param emptyText
14 * the text that will be returned if the Set is empty
15 * @return the list
16 */
17 public static String list(final Set<String> elements, final String prefix, final String emptyText) {
18 if (!elements.isEmpty()) {
19 return prefix + Utils.buildListString(elements) + ".";
20 }
21 return emptyText;
22 }
23
24 /**
25 * Builds a list in the form of a String from a given Set.
26 *
27 * @param elements
28 * the Set of Strings
29 *
30 * @return the list
31 */
32 private static String buildListString(final Set<String> elements) {
33 final StringBuilder list = new StringBuilder();
34 for (final String string : elements) {
35 list.append(" ").append(string);
36 }
37 return list.toString();
38 }
39
40}
diff --git a/src/esieequest/model/Game.java b/src/esieequest/model/Game.java
index 0a9aa01..5ef4c22 100644
--- a/src/esieequest/model/Game.java
+++ b/src/esieequest/model/Game.java
@@ -2,6 +2,10 @@ package esieequest.model;
2 2
3import java.util.HashMap; 3import java.util.HashMap;
4 4
5import esieequest.model.entities.Player;
6import esieequest.model.items.Item;
7import esieequest.model.map.Room;
8
5/** 9/**
6 * Represents the game. 10 * Represents the game.
7 * 11 *
@@ -187,8 +191,8 @@ public class Game {
187 * Creates and adds items into rooms. 191 * Creates and adds items into rooms.
188 */ 192 */
189 private void createItems() { 193 private void createItems() {
190 this.rooms.get("Cafeteria").addItem("Banana", new Item("A yellow banana", 12)); 194 this.rooms.get("Cafeteria").putItem("banana", new Item("A yellow banana", 12));
191 this.rooms.get("Cafeteria").addItem("Orange", new Item("An orange orange", 15)); 195 this.rooms.get("Cafeteria").putItem("orange", new Item("An orange orange", 15));
192 } 196 }
193 197
194 /** 198 /**
diff --git a/src/esieequest/model/Player.java b/src/esieequest/model/Player.java
deleted file mode 100644
index e28edaf..0000000
--- a/src/esieequest/model/Player.java
+++ /dev/null
@@ -1,44 +0,0 @@
1package esieequest.model;
2
3import java.util.Stack;
4
5public class Player {
6
7 private Room currentRoom;
8 private final Stack<Room> previousRooms;
9
10 public Player() {
11 this.currentRoom = null;
12 this.previousRooms = new Stack<Room>();
13 }
14
15 /**
16 * Returns the current room.