-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeapon.java
More file actions
66 lines (49 loc) · 1.49 KB
/
Copy pathWeapon.java
File metadata and controls
66 lines (49 loc) · 1.49 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
// Public class for Weapon objects.
// Subclass of the abstract class Item
// Implements the Equippable intereface
public class Weapon extends Item implements Equippable {
// private data members
private int damage;
private int required_hands;
private boolean equipped = false;
// constructor for the Weapon object
public Weapon(String name, int price, int level, int damage, int required_hands) {
super(name, price, level);
this.required_hands = required_hands;
this.damage = damage;
}
// getter methods
public int getDamage() {
return damage;
}
public int getRequiredHands() {
return required_hands;
}
// setter methods
public void setDamage(int k) {
damage = k;
}
public void setRequiredHands(int k) {
required_hands = k;
}
// additional 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 overriden
public String toString() {
String s = super.toString();
s += " Damage: " + Colors.ANSI_GREEN + Integer.toString(damage) + Colors.ANSI_RESET + "\n";
s += " Required hands: " + Colors.ANSI_BLUE + Integer.toString(required_hands) + Colors.ANSI_RESET + "\n";
return s;
}
}