-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
41 lines (38 loc) · 941 Bytes
/
Item.java
File metadata and controls
41 lines (38 loc) · 941 Bytes
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
public class Item extends Usable {
private int count;
// Constructors
public Item(Usable usable) {
this(usable, 1);
}
public Item(Usable usable, int count) {
super(usable.getName(), usable.isTargetUser(), usable.isSwitchTarget(), usable.getEffect());
this.count = count;
}
/* Changes count by 1. */
public void increment() {
changeCount(1);
}
/* Changes count by -1.
* Returns false if count reaches 0, else returns true. */
public boolean decrement() {
return changeCount(-1);
}
/* Changes count by the specified amount.
* Returns true if count > 0, else returns false. */
public boolean changeCount(int change) {
count += change;
return count > 0;
}
// Getters/Setters
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
// toString
@Override
public String toString() {
return "Item [count=" + count + ", usable=" + super.toString() + "]";
}
}