Repository navigation
Expand file tree
/
Copy pathRoom.java
More file actions
212 lines (192 loc) · 6.73 KB
/
Copy pathRoom.java
File metadata and controls
212 lines (192 loc) · 6.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Set;
// import java.awt.image.BufferedImage;
// import javax.imageio.ImageIO;
// import java.io.FileInputStream;
/**
* Class Room - a room in an adventure game.
*
* This class is part of the "World of Zuul" application.
* "World of Zuul" is a very simple, text based adventure game.
*
* A "Room" represents one location in the scenery of the game. It is
* connected to other rooms via exits. The exits are labelled north,
* east, south, west. For each direction, the room stores a reference
* to the neighboring room, or null if there is no exit in that direction.
*
* @author Michael Kölling and David J. Barnes
* @Edits by (Mainuddin Monsur Robin)
* @version v2
*/
public class Room
{
String description;
private HashMap<String, Room> directions;
private ArrayList<Item> items;
private static final int ItemsLimit = 5;
private int itemsCount;
private Item secretKey;
private String imagPath;
// private BufferedImage img;
/**
* Create a room described "description". Initially, it has
* no exits. "description" is something like "a kitchen" or
* "an open court yard".
* @param description The room's description.
*/
public Room(String description, String imagPath)
{
this.directions = new HashMap<String, Room>();
this.description = description;
this.items = new ArrayList<Item>();
this.itemsCount = 0;
secretKey = null;
this.imagPath = imagPath;
// img = ImageIO.read(new FileInputStream(path));
}
/*<-----------------Room and Exits related methods-------------------------------------------------------------->*/
/**
* Method setExit
*
* @param direction A parameter which is the key of the hashmap
* that describes the location of another room relative to this one.
* @param room A parameter the room in that direction.
*/
public void setExit(String direction, Room room)
{
// making sure that there is no duplicates to avoid over write of data
if(directions.containsKey(direction))
{
directions.remove("direction");
directions.put(direction,room);
}
else
{
directions.put(direction,room);
}
}
/**
* Method getExit
*
* @param direction A parameterwhich is the key of the HashMap
* @return The return value is the coresponding room to vthat direction
*/
public Room getExit(String direction)
{
return directions.get(direction);
}
/**
* @return The Full description of the room witb its currents Exits.
*/
public String getDescription()
{
return description;
}
/**
* Method getDirections
*
* @return The return value is the possible directoin to go
*/
public Set<String> getDirections()
{
return directions.keySet();
}
/*<-----------------Items Arraylist related methods-------------------------------------------------------------->*/
/**
* Method setItem
*-- items arraylist Setter -- adds an item by just declaring ints propetises
*-- called by the environment class --
*
* @param newItems the arrsylist of items to enter.
* @return return true if the addation is done, otherwise return false and dont add any thing
* if it will exceed the itemlimit.
*/
public boolean setItem(String name, String description)
{
// adding the new items as an array list to the main one
if(itemsCount + 1 <= ItemsLimit)
{
items.add(new Item(name, description ));
itemsCount++;
return true; // return true if the addation is done
}
else
{
return false; // return flase if the addation fails and its valueis the current capacity
//return itemsCount doesnt work;
}
}
/**
* Method removeItem
*-- will be used by the player class --
* @param item the item to be removed.
* @return returns true if succesfully removed or false if not.
*/
public boolean removeItem(Item item)
{
// updating the items count if sucessfull -- consistancy
if(items.remove(item))
{
itemsCount--;
return true; //true if succesfully removed
}
else
{
return false; //false if failed
}
}
/**
* Method addItem
*-- will be called by the player class -- adds specific item to the room items regarfing the maximun condition
* @param item the item to be add.
* @return returns true if succesfully added or false if not
*/
public boolean addItem(Item item)
{
if(itemsCount + 1 < ItemsLimit)
{
items.add(item);
// updating the items count if sucessfull -- consistancy
itemsCount++;
return true; //true if succesfully removed
}
else{
return false; //false if failed
}
}
/**
* Method printItemList
* --Will be called by game class
*
* prints the itemslist to the user with its description
*/
public void printItemList()
{
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
System.out.printf("| %-10s | %-50s | %-6s | %-13s | %-13s | %-13s |%n", "Name", "Description", "Weight", "Attack Points", "Defense Points", "Health Points");
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
for (Item item : items)
{
System.out.printf("| %-10s | %-50s | %-6d | %-13d | %-14d | %-13d |%n", item.getName(), item.getDescription()/*, item.getWeight() item.getAttackPoints(), item.getDefensePoints(), item.getHealthPoints()*/);
}
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
System.out.printf("| %44s = %d |%n","itemsCouts", itemsCount);
System.out.printf("+---------------------------------------------------------------------------------------------------------------------------+%n");
}
/**
*items arraylist getter
*
* @return items arraylist
*/
public ArrayList<Item> getItems()
{
// returns the items arraylist
return items;
}
//Immage Getter
public String getImagePath()
{
return imagPath;
}
}