-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mage.java
87 lines (75 loc) · 2.56 KB
/
Mage.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
/*=============================================
class Mage -- protagonist of Ye Olde RPG
=============================================*/
public class Mage extends Character {
// ~~~~~~~~~~~ INSTANCE VARIABLES ~~~~~~~~~~~
// inherited from superclass
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*=============================================
default constructor
pre: instance vars are declared
post: initializes instance vars.
=============================================*/
public Mage() {
super();
_hitPts = 100;
_strength = 70;
_defense = 20;
_attack = .8;
}
/*=============================================
overloaded constructor
pre: instance vars are declared
post: initializes instance vars. _name is set to input String.
=============================================*/
public Mage( 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 = 1;
_defense = 15;
}
/*=============================================
void normalize() -- revert stats back to normal
pre:
post: Attack and defense of character is de-specialized
=============================================*/
public void normalize() {
_attack = .8;
_defense = 20;
}
/*=============================================
String about() -- returns descriptions character type
pre:
post: Info is returned
=============================================*/
public String about() {
return "Mages are cunning and smart magicians, but aren't very strong.";
}
/*==========================
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._defense+=20;
return "your mage casts a magic barrier, raising defence to " + this._defense;
}
else {
if (this._defense > 0){
this._defense-=5;
}
return "your mage fails to cast magic barrier, lowering defence to: " + this._defense;
}
}
}//end class Mage