-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCharacter.java
More file actions
264 lines (228 loc) · 5.52 KB
/
Character.java
File metadata and controls
264 lines (228 loc) · 5.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import greenfoot.*;
/**
* Write a description of class Character here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Character extends Actor
{
private boolean moved, movable;
private int x, y;
public static final int TILESIZE = 1;
public static final int MOVEDELAY = 10;
GreenfootImage player = new GreenfootImage("images/priest/priest_victory1.png");
/**
* Variables for RPG-ness
* health: the player's Hit Points
* faith: the player's Magic Points
* strength: the player's physical strength
* defense: the player's physical defense
* piety: the player's magic strength
* will: the player's magic defense
* speed: the player's speed
* maxHP: the player's maximum health
*/
private int health, faith;
private int strength, defense, piety, will, speed;
private int maxHP, maxMP;
public Character(int startx, int starty)
{
moved = false;
movable = true;
player.scale(70, 70);
setImage(player);
x = startx;
y = starty;
health = 100;
faith = 50;
strength = 15;
defense = 15;
piety = 15;
will = 15;
speed = 15;
maxHP = 100;
maxMP = 50;
}
public void battleReady()
{
player.scale(140, 140);
setImage(player);
}
public void exploreReady()
{
player.scale(70, 70);
setImage(player);
}
/**
* Act - do whatever the Character wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(movable)
{
if (Greenfoot.isKeyDown("up"))
{
y -= TILESIZE;
if (y < 0)
y = 0;
moved = true;
Greenfoot.delay(MOVEDELAY);
}
else if (Greenfoot.isKeyDown("down"))
{
y += TILESIZE;
if (y >= getWorld().getHeight())
y = getWorld().getHeight() - 1;
moved = true;
Greenfoot.delay(MOVEDELAY);
}
else if (Greenfoot.isKeyDown("left"))
{
x -= TILESIZE;
if (x < 0)
x = 0;
moved = true;
Greenfoot.delay(MOVEDELAY);
}
else if (Greenfoot.isKeyDown("right"))
{
x += TILESIZE;
if (x >= getWorld().getWidth())
x = getWorld().getWidth() - 1;
moved = true;
Greenfoot.delay(MOVEDELAY);
}
setLocation(x, y);
}
}
/**
* Attack with a physical attack
* @return the amount of damage dealt
*/
public int attack(Monster m)
{
int damage = 0;
int monDef = m.getDefense();
damage = (strength * 2) / (monDef * 3);
if (damage == 0)
damage = 1;
return damage;
}
/**
* Attack with a magical attack
* @return the amount of damage dealt
*/
public int cast(Monster m, int cost)
{
int damage = 0;
int monMDef = m.getWill();
faith -= cost;
damage = (piety * 2) / (monMDef * 3);
if (damage == 0)
damage = 1;
return damage;
}
/**
* Heal up to 5% of your faith back
* @return the amount of faith recovered
*/
public int pray()
{
int recover, temp = 0;
temp = (int)(maxMP * 0.05);
recover = java.lang.Math.min(Greenfoot.getRandomNumber(temp+1), maxMP - faith);
return recover;
}
/**
* Heal 15% of your health back
* @return the amount of health recovered
*/
public int heal()
{
int recover, temp;
temp = (int)(maxHP * 0.15);
recover = java.lang.Math.min(temp, maxHP - health);
return recover;
}
public boolean hasMoved()
{
boolean ret = moved;
moved = false;
return ret;
}
/** GETTERS AND SETTERS **/
public boolean getMovable()
{
return movable;
}
public void setMovable(boolean canMove)
{
movable = canMove;
}
public int getHealthPercent()
{
return health * 100 / maxHP;
}
public int getFaithPercent()
{
return faith * 100 / maxMP;
}
public int getHealth()
{
return health;
}
public void setHealth(int hp)
{
health = hp;
}
public int getFaith()
{
return faith;
}
public void setFaith(int mp)
{
faith = mp;
}
public int getStrength()
{
return strength;
}
public void setStrength(int str)
{
strength = str;
}
public int getDefense()
{
return defense;
}
public void setDefense(int def)
{
defense = def;
}
public int getPiety()
{
return piety;
}
public void setPiety(int mStr)
{
piety = mStr;
}
public int getWill()
{
return will;
}
public void setWill(int william)
{
will = william;
}
public int getSpeed()
{
return speed;
}
public void setSpeed(int spd)
{
speed = spd;
}
}