-
Notifications
You must be signed in to change notification settings - Fork 0
/
Room.java
executable file
·125 lines (112 loc) · 3.09 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
import java.util.Set;
import java.util.HashMap;
import java.util.Iterator;
/*
* Class Room - a room in an adventure game.
*
* This class is the main class of the "Queen saving" Game`
*
* A "Room" represents one location in the scenery of the game. It is
* connected to other rooms via exits. For each existing exit, the room
* stores a reference to the neighboring room.
*
* @author Michael Kolling and David J. Barnes and 121880(Long Yu)
* @version 1.0 (Nov 2013)
*/
class Room
{
private String description;
private HashMap exits; // stores exits of this room.
public Person character;
public Gear gear=null;
/**
* Create a room described "description". Initially, it has no exits.
* "description" is something like "in a kitchen" or "in an open court
* yard".
* @param the description
*/
public Room(String description)
{
this.description = description;
exits = new HashMap();
}
/**
* setter method of the room object
* @param parameter is the character of the room
*/
public void setCharater(Person character)
{
this.character = character;
}
/**
* setter method of the room object
* @param parameter is the gear of the room
*/
public void setGear(Gear gear)
{
this.gear = gear;
}
/**
* destroy the gear of the room
* @param parameter is the gear you want to destroy of the room
*/
public void destroyGear(Gear gear)
{
this.gear = null;
}
/**
* destroy the character of the room
* @param parameter is the character you want to destroy of the room
*/
public void destroyCharater(Person character)
{
this.character = null;
}
/**
* Define an exit from this room.
*/
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 getShortDescription()
{
return description;
}
/**
* Return a long description of this room, in the form:
* You are in the kitchen.
* Exits: north west
* @return a long description
*/
public String getLongDescription()
{
return "You are " + description + ".\n" + getExitString();
}
/**
* Return a string describing the room's exits, for example
* "Exits: north west".
* @return the string with exits
*/
private String getExitString()
{
String returnString = "Exits:";
Set keys = exits.keySet();
for(Iterator iter = keys.iterator(); iter.hasNext(); )
returnString += " " + iter.next();
return returnString;
}
/**
* @param paramter is the direction of the exit.
* @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.
*/
public Room getExit(String direction)
{
return (Room)exits.get(direction);
}
}