-
Notifications
You must be signed in to change notification settings - Fork 0
/
Warrior.java
93 lines (79 loc) · 2.82 KB
/
Warrior.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
/*=============================================
class Warrior -- protagonist of Ye Olde RPG
(_)
__ ____ _ _ __ _ __ _ ___ _ __
\ \ /\ / / _` | '__| '__| |/ _ \| '__|
\ V V / (_| | | | | | | (_) | |
\_/\_/ \__,_|_| |_| |_|\___/|_|
=============================================*/
public class Warrior extends Character {
// ~~~~~~~~~~~ INSTANCE VARIABLES ~~~~~~~~~~~
// inherited from superclass
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*=============================================
default constructor
pre: instance vars are declared
post: initializes instance vars.
=============================================*/
public Warrior() {
super();
_hitPts = 125;
_strength = 100;
_defense = 40;
_attack = .4;
}
/*=============================================
overloaded constructor
pre: instance vars are declared
post: initializes instance vars. _name is set to input String.
=============================================*/
public Warrior( String name ) {
this();
if (!name.equals("")) {
_name = name;
}
}
/*=============================================
void specialize() -- prepares character for special attack
pre:
post: Attack of character is increased, defense is decreased
=============================================*/
public void specialize() {
_attack = .75;
_defense = 20;
}
/*=============================================
void normalize() -- revert stats back to normal
pre:
post: Attack and defense of character is de-specialized
=============================================*/
public void normalize() {
_attack = .45;
_defense = 40;
}
/*=============================================
String about() -- returns descriptions character type
pre:
post: Info is returned
=============================================*/
public String about() {
return "Warriors are fierce and strong fighters, but are slow.";
}
/*==========================
String heroSpecial()
pre:
post: executes a character's special move, for example, a priest would heal itself, and
returns a string summarizing what happened.
========================*/
public String heroSpecial(){
if (((int) (Math.random()*99)) >= 50){
this._strength+=20;
return "your warrior summons a magical steroid and eats it, your warrior's strength has increased to " + this._strength;
}
else {
this._hitPts-=10;
this._defense -=10;
return "your warrior accidentally summons a bad magic steroid, lowering HP and defence by 10" ;
}
}
}//end class Warrior