forked from SkylerLutz/adventure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomLockable.java
More file actions
49 lines (48 loc) · 1.27 KB
/
Copy pathRoomLockable.java
File metadata and controls
49 lines (48 loc) · 1.27 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
public class RoomLockable extends Room {
public RoomLockable(String description, String shortDescription, boolean locked, Item key) {
super(description, shortDescription);
this.locked = locked;
this.key = key;
this.causesDeath = false;
this.deathMessage = "";
this.unlockMessage = "Room unlocked.";
}
public RoomLockable(String description, String shortDescription) {
// unlocked by default
this(description, shortDescription, false, Item.getInstance("unknown"));
}
public boolean isLocked() {
return this.locked;
}
public void setCausesDeath(boolean causesDeath, String message) {
this.causesDeath = causesDeath;
this.deathMessage = message;
}
public boolean causesDeath() {
return this.causesDeath;
}
public String deathMessage() {
return this.deathMessage;
}
public void setUnlockMessage(String s){
this.unlockMessage = s;
}
public boolean unlock(Item key) {
if(this.key.compareTo(key) == 0) {
this.locked = false;
System.out.println(this.unlockMessage);
return true;
}
else {
if(!causesDeath()) {
System.out.println("This key doesn't seem to fit");
}
return false;
}
}
protected boolean locked;
protected Item key;
protected boolean causesDeath;
protected String deathMessage;
protected String unlockMessage;
}