aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/esieequest/controller/Interpreter.java13
-rw-r--r--src/esieequest/controller/Parser.java2
-rw-r--r--src/esieequest/controller/Performer.java68
-rw-r--r--src/esieequest/controller/Utils.java40
-rw-r--r--src/esieequest/model/Game.java69
-rw-r--r--src/esieequest/model/Player.java5
-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.java69
-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.java96
-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)72
-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/Console.java4
-rw-r--r--src/esieequest/view/text/FileReader.java4
-rw-r--r--src/esieequest/view/text/TextInterface.java34
-rw-r--r--src/esieequest/view/web/WebInterface.java8
27 files changed, 387 insertions, 171 deletions
diff --git a/src/esieequest/controller/Interpreter.java b/src/esieequest/controller/Interpreter.java
index 586b329..5c60f6d 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/**
@@ -69,8 +69,14 @@ class Interpreter {
69 case "look": 69 case "look":
70 this.performer.look(); 70 this.performer.look();
71 return; 71 return;
72 case "eat": 72 case "inventory":
73 this.performer.eat(); 73 this.performer.listItems();
74 return;
75 case "take":
76 this.performer.take(command.getOption());
77 return;
78 case "drop":
79 this.performer.drop(command.getOption());
74 return; 80 return;
75 case "help": 81 case "help":
76 this.performer.showHelp(); 82 this.performer.showHelp();
@@ -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 27cbf14..8f8afeb 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/**
@@ -99,10 +100,10 @@ class Performer {
99 * the direction of the new room 100 * the direction of the new room
100 */ 101 */
101 public void goTo(final String direction) { 102 public void goTo(final String direction) {
102 final Room nextRoom = this.game.getRoomExit(direction); 103 final Room nextRoom = this.game.getPlayer().getCurrentRoom().getExit(direction);
103 if (nextRoom != null) { 104 if (nextRoom != null) {
104 this.game.goToRoom(nextRoom); 105 this.game.getPlayer().goToRoom(nextRoom);
105 this.view.updateRoom(this.game.getCurrentRoom()); 106 this.view.updateRoom(this.game.getPlayer().getCurrentRoom());
106 } else { 107 } else {
107 this.echo(this.game.getNoExitMessage()); 108 this.echo(this.game.getNoExitMessage());
108 } 109 }
@@ -112,22 +113,69 @@ class Performer {
112 * Changes the current room to the previous one. 113 * Changes the current room to the previous one.
113 */ 114 */
114 public void goBack() { 115 public void goBack() {
115 this.game.goToPreviousRoom(); 116 this.game.getPlayer().goToPreviousRoom();
116 this.view.updateRoom(this.game.getCurrentRoom()); 117 this.view.updateRoom(this.game.getPlayer().getCurrentRoom());
117 } 118 }
118 119
119 /** 120 /**
120 * Displays informations about the current place. 121 * Displays informations about the current place.
121 */ 122 */
122 public void look() { 123 public void look() {
123 this.echo(this.game.getCurrentRoom().getInformations()); 124 this.echo(this.game.getPlayer().getCurrentRoom().getInformations());
124 } 125 }
125 126
126 /** 127 /**
127 * Displays a special message. 128 * Moves an item from the current Room to the Player's inventory.
129 *
130 * @param itemName
131 * the item's name
132 */
133 public void take(final String itemName) {
134 int weight = this.game.getPlayer().getInventory().getTotalWeight();
135 weight += this.game.getPlayer().getCurrentRoom().getItems().getItemWeight(itemName);
136 final int maxWeight = this.game.getPlayer().getMaxCarryWeight();
137
138 if (weight >= maxWeight) {
139 this.echo("Maximum inventory weight reached. Cannot pick up item.");
140 return;
141 }
142
143 this.moveItem(this.game.getPlayer().getCurrentRoom().getItems(), this.game.getPlayer().getInventory(), itemName);
144 }
145
146 /**
147 * Moves an item from the Player's inventory to the current Room.
148 *
149 * @param itemName
150 * the item's name
151 */
152 public void drop(final String itemName) {
153 this.moveItem(this.game.getPlayer().getInventory(), this.game.getPlayer().getCurrentRoom().getItems(), itemName);
154 }
155
156 /**
157 * Moves a given item referred by its name from an inventory to another.
158 *
159 * @param source
160 * the source inventory
161 * @param dest
162 * the destination inventory
163 * @param itemName
164 * the item's name
165 */
166 private void moveItem(final Inventory source, final Inventory dest, final String itemName) {
167 if (!source.hasItem(itemName)) {
168 this.echo("No such item.");
169 return;
170 }
171 dest.putItem(itemName, source.takeItem(itemName));
172 }
173
174 /**
175 * Lists the items contained in the player's inventory.
128 */ 176 */
129 public void eat() { 177 public void listItems() {
130 this.echo(this.game.getEatMessage()); 178 this.echo(Utils.list(this.game.getPlayer().getInventory().getItemList(), "Items:", "No item in your inventory."));
131 } 179 }
132 180
133} 181}
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