-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPotion.java
More file actions
67 lines (50 loc) · 1.62 KB
/
Copy pathPotion.java
File metadata and controls
67 lines (50 loc) · 1.62 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// public class for a Potion
// Subclass of the item abstract class
// Implements the Consumable interface
public class Potion extends Item implements Consumable {
// private data members
private int attributeIncrease;
private String attributeType;
private boolean consumed = false;
//
public Potion(String name, int price, int level, int attributeIncrease, String attributeType) {
super(name, price, level);
this.attributeIncrease = attributeIncrease;
this.attributeType = attributeType;
}
// getter methods
public int getAttributeIncrease() {
return attributeIncrease;
}
public String getAttributeType() {
return attributeType;
}
// setter methods
public void setAttributeIncrease(int k) {
attributeIncrease = k;
}
public void setType(String newType) {
attributeType = newType;
}
// additional methods that must be implented by this class
// like abstract methods and methods from the interface
public boolean isConsumed() {
return consumed;
}
public void consume() {
consumed = true;
}
boolean canBeUsed(HeroEntity other) {
if (other.getLevel() >= this.getLevel()) {
return true;
} else {
return false;
}
}
public String toString() {
String s = super.toString();
s += " Type: " + Colors.ANSI_BLUE + attributeType + Colors.ANSI_RESET + "\n";
s += " Attribute Increase: " + Colors.ANSI_GREEN + Integer.toString(attributeIncrease) + Colors.ANSI_RESET + "\n";
return s;
}
}