-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdventurer.java
119 lines (94 loc) · 2.51 KB
/
Adventurer.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
118
119
import java.util.*;
public abstract class Adventurer {
private String name;
private int HP, maxHP;
// Abstract methods are meant to be implemented in child classes.
/*
* all adventurers must have a custom special
* consumable resource (mana/rage/money/witts etc)
*/
// give it a short name (fewer than 13 characters)
public abstract String getSpecialName();
// accessor methods
public abstract int getSpecial();
public abstract int getSpecialMax();
public abstract void setSpecial(int n);
// concrete method written using abstract methods.
// refill special resource by amount, but only up to at most getSpecialMax()
public int restoreSpecial(int n) {
if (n > getSpecialMax() - getSpecial()) {
n = getSpecialMax() - getSpecial();
}
setSpecial(getSpecial() + n);
return n;
}
/*
* all adventurers must have a way to attack enemies and
* support their allys
*/
// hurt or hinder the target adventurer
public abstract String attack(Adventurer other);
/*
* This is an example of an improvement that you can make to allow
* for more flexible targetting.
*/
// heal or buff the party
// public abstract String support(ArrayList<Adventurer> others);
// heal or buff the target adventurer
public abstract String support(Adventurer other);
// heal or buff self
public abstract String support();
// hurt or hinder the target adventurer, consume some special resource
public abstract String specialAttack(Adventurer other);
/*
* standard methods
*/
public void applyDamage(int amount) {
this.HP -= amount;
}
// You did it wrong if this happens.
public Adventurer() {
this("Lester-the-noArg-constructor-string");
}
public Adventurer(String name) {
this(name, 10);
}
public Adventurer(String name, int hp) {
this.name = name;
this.HP = hp;
this.maxHP = hp;
}
// toString method
public String toString() {
return this.getName();
}
// Get Methods
public String getName() {
return name;
}
public int getHP() {
return HP;
}
public int getmaxHP() {
return maxHP;
}
public void setmaxHP(int newMax) {
maxHP = newMax;
}
// Set Methods
public void setHP(int health) {
this.HP = health;
}
public void setName(String s) {
this.name = s;
}
public String randomAttack(Adventurer target) {
int chance = (int) (Math.random() * 2);
if (chance == 0) {
return this.attack(target);
}
else {
return this.specialAttack(target);
}
}
}