-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeWarrior.java
80 lines (69 loc) · 2.12 KB
/
CodeWarrior.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
public class CodeWarrior extends Adventurer{
int caffeine, caffeineMax;
String preferredLanguage;
/*the other constructors ultimately call the constructor
*with all parameters.*/
public CodeWarrior(String name, int hp, String language){
super(name,hp);
caffeineMax = 12;
caffeine = caffeineMax/2;
preferredLanguage = language;
}
public CodeWarrior(String name, int hp){
this(name,hp,"c++");
}
public CodeWarrior(String name){
this(name,24);
}
public CodeWarrior(){
this("Carmack");
}
/*The next 8 methods are all required because they are abstract:*/
public String getSpecialName(){
return "caffeine";
}
public int getSpecial(){
return caffeine;
}
public void setSpecial(int n){
caffeine = n;
}
public int getSpecialMax(){
return caffeineMax;
}
/*Deal 2-7 damage to opponent, restores 2 caffeine*/
public String attack(Adventurer other){
int damage = (int)(Math.random()*6)+2;
other.applyDamage(damage);
restoreSpecial(2);
return this + " attacked "+ other + " and dealt "+ damage +
" points of damage. They then take a sip of their coffee.";
}
/*Deal 3-12 damage to opponent, only if caffeine is high enough.
*Reduces caffeine by 8.
*/
public String specialAttack(Adventurer other){
if(getSpecial() >= 8){
setSpecial(getSpecial()-8);
int damage = (int)(Math.random()*5+Math.random()*5)+3;
other.applyDamage(damage);
return this + " used their "+preferredLanguage+
" skills to hack the matrix. "+
" This glitched out "+other+" dealing "+ damage +" points of damage.";
}else{
return "Not enough caffeine to use the ultimate code. Instead "+attack(other);
}
}
/*Restores 5 special to other*/
public String support(Adventurer other){
return "Gives a coffee to "+other+" and restores "
+ other.restoreSpecial(5)+" "+other.getSpecialName();
}
/*Restores 6 special and 1 hp to self.*/
public String support(){
int hp = 1;
setHP(getHP()+hp);
return this+" drinks a coffee to restores "+restoreSpecial(6)+" "
+ getSpecialName()+ " and "+hp+" HP";
}
}