-
Notifications
You must be signed in to change notification settings - Fork 0
/
Item.java
executable file
·117 lines (108 loc) · 2.61 KB
/
Item.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
// YichunZhang k19012458
/**
* Class Item - a item in an adventure game.
* This class is part of the "Underground Base Escape" application.
*
* A "Item" represents one object in the scenery of the game. Items are in
* rooms.
*
* @author Yichun Zhang
* @version 2019/11/29
*/
public class Item
{
private String name;
private String description;
private int weight;
private boolean canBePicked;
private boolean isCarriedWith;
private boolean isVisible;
/**
* Create a item.
* @param name The item's name.
* @param description Information about the item
* @param weight The item's weight
* @param canBePicked Whether it can be picked up or not
* @param isVisible Whether it can be visible or not
*/
public Item(String name, String description, int weight,
boolean canBePicked, boolean isVisible)
{
this.name = name;
this.description = description;
this.weight = weight;
this.canBePicked = canBePicked;
isCarriedWith = false;
this.isVisible = isVisible;
}
/**
* @return true, if the item is visible, false otherwise
*/
public boolean getIsVisible()
{
return isVisible;
}
/**
* @return true, if the item can be carried with, false otherwise
*/
public boolean getIsCarriedWith()
{
return isCarriedWith;
}
/**
* @return Name of the item
*/
public String getName()
{
return name;
}
/**
* @return Weight of the item
*/
public int getWeight()
{
return weight;
}
/**
* @return description of the item
*/
public String getDescription()
{
return description;
}
/**
* Set the itme is visible
*/
public void setVisible()
{
isVisible = true;
}
/**
* @return true, if the item can be picked up and is visible,
* false otherwise
*/
public boolean pickUpItem()
{
boolean isPickUp = false;
if (canBePicked && isVisible) {
isCarriedWith = true;
isVisible = false;
isPickUp = !isPickUp;
}
return isPickUp;
}
/**
* @return true, if the item is carried with by the player and is not
* visible, false otherwise
*/
public boolean throwAwayItem()
{
boolean isThrowAway = false;
if (isCarriedWith && !isVisible) {
isCarriedWith = false;
isVisible = true;
isThrowAway = !isThrowAway;
}
return isThrowAway;
}
}