-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter.java
64 lines (53 loc) · 1.44 KB
/
Character.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
/*
Team Patcraft -- Jason Chua, Sadia Azmine
APCS1 pd9
HW30 -- Ye Olde Role Playing Game, Expanded
2015-11-14
*/
public abstract class Character {
//instance variables
protected String name;
protected int health, strength, defense;
protected double attack;
//returns true if health is over 0
//false otherwise
public boolean isAlive() {
return health > 0;
}
//returns name value
public String getName() {
return name;
}
//returns defense value
public int getDefense() {
return defense;
}
//only lowers hp if x is positive
//otherwise no damage is dealt
public void lowerHP(int x) {
if (x > 0) {
health -= x;
}
}
//saves damage integer to local variable dmg
//lowers hp of given character argument by dmg
//returns dmg
public int attack(Character x) {
int dmg = (int)(strength * attack) - x.getDefense();
x.lowerHP(dmg);
//returns 0 if dmg is negative so display message does not display
//negative damage
if (dmg > 0) {
return dmg;
}
else {
return 0;
}
}
//resets defense and attack to normal values
public abstract void normalize();
//decreases defense and increases attack
public abstract void specialize();
//information about classes and attributes of each
public abstract String about();
}