-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoom.java
130 lines (115 loc) · 3.08 KB
/
Room.java
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
package com.zuul.game;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Class Room - a room in an adventure game.
*
* @author Michael Kölling and David J. Barnes
* @version 2016.02.29
*/
public class Room
{
private String description;
private String name;
private HashMap<String, Room> exits;
private ArrayList<Item> items = new ArrayList<Item>();
private ArrayList<Alien> aliens;
/**
* 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 name, String description)
{
this.name = name;
this.description = description;
this.exits = new HashMap<>();
this.aliens = new ArrayList<>();
}
public void addAlien(Alien alien) {
this.aliens.add(alien);
}
public ArrayList<Alien> getAliens(){
return this.aliens;
}
/**
* Define an exit from this room.
* @param direction The direction of the exit.
* @param neighbor The room to which the exit leads.
*/
public void setExit(String direction, Room neighbor)
{
exits.put(direction, neighbor);
}
/**
* @return The description of the room
* (the one that was defined in the constructor).
*/
public String getDescription()
{
return description;
}
/**
* @return The name of the room.
*/
public String getName()
{
return name;
}
/**
* Return a description of the room in the form:
* You are in the kitchen.
* Exits: north west
* @return A long description of this room
*/
/* public String getLongDescription()
{
String completeDescription = "You are " + description + ".\n" + ".\n" + "Items in a room";
//return getExitString();
}*/
/**
* Return a string describing the room's exits, for example
* "Exits: north west".
* @return Details of the room's exits.
*/
/* private String getExitString()
{
String returnString = "Exits:";
HashSet<String> keys = exits.keySet();
for(String exit : keys) {
returnString += " " + exit;
}
return returnString;
}*/
/**
* Return the room that is reached if we go from this room in direction
* "direction". If there is no room in that direction, return null.
* @param direction The exit's direction.
* @return The room in the given direction.
*/
public Room getExits(String direction)
{
return exits.get(direction);
}
/** Adds item to a room
* @param item the item that you want to add to the room
*/
public void addItem(Item item)
{
items.add(item);
}
public void removeItem(Item item)
{
int index = items.indexOf(item);
items.remove(index);
}
public int getItemNumber()
{
return items.size();
}
public ArrayList<Item> getItems()
{
return items;
}
}