-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmor.java
57 lines (40 loc) · 1.24 KB
/
Armor.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
// Public class for Armor objects.
// Subclass of the abstract class Item
// Implements the Equippable intereface
public class Armor extends Item implements Equippable {
// private data members
private int reduction;
private boolean equipped = false;
// Constructor for the Armor object
public Armor(String name, int price, int level, int reduction) {
super(name, price, level);
this.reduction = reduction;
}
// getter methods
public int getReduction() {
return reduction;
}
// setter methods
public void setreduction(int k) {
reduction = k;
}
// additional methods, including implementations of abstract and interface methods
boolean canBeUsed(HeroEntity other) {
return this.getLevel() <= other.getLevel();
}
public boolean isEquipped() {
return equipped;
}
public void equip() {
equipped = true;
}
public void unequip() {
equipped = false;
}
// To string method for the ARmoro object
public String toString() {
String s = super.toString();
s += " Defense Reduction: " + Colors.ANSI_GREEN + Integer.toString(reduction) + Colors.ANSI_RESET + "\n";
return s;
}
}