-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdventurer.java
More file actions
114 lines (92 loc) · 2.52 KB
/
Adventurer.java
File metadata and controls
114 lines (92 loc) · 2.52 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
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
// Collaborators:
public abstract class Adventurer{
private String name;
private int HP,maxHP;
private int damageAmount;
private int healAmount;
/*There is no no-arg constructor. Be careful with your subclass constructors.*/
public Adventurer(String name) {
this.name = name;
}
public Adventurer(String name, int damageAmount, int healAmount){
this(name, 10, damageAmount, healAmount);
}
public Adventurer(String name, int hp, int damageAmount, int healAmount){
this.name = name;
this.HP = hp;
this.maxHP = hp;
this.damageAmount = damageAmount;
this.healAmount = healAmount;
}
public int getDamageAmount() {
return damageAmount;
}
public int getHealAmount() {
return healAmount;
}
//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;
}
//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 void setSpecial(int n);
public abstract int getSpecialMax();
/*
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);
//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;
}
public void applyHeal(int amount) {
this.HP += amount;
}
//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;
}
}