forked from TechHead27/EW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinalBattle.java
225 lines (198 loc) · 6.78 KB
/
FinalBattle.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
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
import greenfoot.*;
/**
* Write a description of class FinalBattle here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class FinalBattle extends BattleField
{
private static final int[][] options = {{75, 304}, {75, 330}, {75, 356}, {75, 382}};
private Monster boss;
private HealthBar healthBar;
private FaithBar faithBar;
private Character player;
private GreenfootSound bgm;
private GreenfootImage background;
private boolean alreadyActing = false;
private Arrow selector;
public FinalBattle(Character c)
{
super();
showText("Toilet appeared!", 300, 244);
background = new GreenfootImage("images/menus/battlemenu.png");
background.scale(600, 400);
setBackground(background);
selector = new Arrow(options);
addObject(selector, 75, 304);
showText("ATTACK", 135, 298);
showText("Standard physical attack", 350, 298);
showText("MAGIC", 144, 324);
showText("Standard magical attack", 347, 324);
showText("PRAY", 150, 350);
showText("Recover faith", 296, 350);
showText("HEAL", 151, 376);
showText("Recover health", 303, 376);
// set up toilet
boss = new FinalBoss();
addObject(boss, 497, 119);
player = c;
player.setMovable(false);
player.battleReady();
addObject(player, 157, 138);
healthBar = new HealthBar(player);
addObject(healthBar, 77, 20);
faithBar = new FaithBar(player);
addObject(faithBar, 225, 20);
bgm = new GreenfootSound("BGM/Boss.mp3");
bgm.playLoop();
Greenfoot.delay(35);
player = c;
}
private void prayer()
{
int recover;
alreadyActing = true;
recover = player.pray();
showText(BattleField.RECOV + recover + BattleField.FAITH, 300, 244);
player.setFaith(player.getFaith() + recover);
faithBar.setFaithImage(player);
Greenfoot.delay(40);
bossTurn();
Greenfoot.delay(40);
alreadyActing = false;
}
private void heal()
{
int recover;
alreadyActing = true;
recover = player.heal();
showText(BattleField.RECOV + recover + BattleField.HEALTH, 300, 244);
player.setHealth(player.getHealth() + recover);
healthBar.setHealthImage(player);
Greenfoot.delay(40);
bossTurn();
Greenfoot.delay(40);
alreadyActing = false;
}
/**
* Player was killed
*/
public void killPlayer()
{
player.setHealth(0);
healthBar.setHealthImage(player);
bgm.stop();
removeObject(player);
showText(BattleField.DEAD, 300, 244);
Greenfoot.stop();
}
/**
* Attack the player with physical or magical
* @return The amount of damage done
*/
public int attackPlayer()
{
showText(BattleField.REKT + boss.getClass().getName() + BattleField.DEALT + boss.chooseAttack(player) + BattleField.DAMAGE, 300, 244);
Greenfoot.delay(60);
return boss.chooseAttack(player);
}
/**
* Attack the monster with physical attack
* @return The amount of damage done
*/
public int attackMonster()
{
showText(BattleField.WRECK + boss.getClass().getName() + BattleField.FISTS + player.attack(boss) + BattleField.DAMAGE, 300, 244);
Greenfoot.delay(40);
return player.attack(boss);
}
/**
* Attack the monster with magical attack
* @return The amount of damage done
*/
public int castMonster(int cost)
{
int temp = player.cast(boss, cost);
faithBar.setFaithImage(player);
showText(BattleField.WRECK + boss.getClass().getName() + BattleField.MAGIC + temp + BattleField.DAMAGE, 300, 244);
Greenfoot.delay(40);
return temp;
}
private void bossTurn()
{
int damage;
damage = attackPlayer();
if(player.getHealth() - damage <= 0)
killPlayer();
else
{
player.setHealth(player.getHealth() - damage);
healthBar.setHealthImage(player);
}
}
public void act()
{
if(!alreadyActing)
{
showText("", 300, 244);
if (Greenfoot.isKeyDown(BattleField.ENTER))
{
switch (selector.getSelection())
{
case 0: attackMonster();
bossTurn();
break;
case 1: if (player.getFaith() - 2 >= 0)
{
castMonster(2);
bossTurn();
}
else
{
showText(BattleField.NOMP, 300, 244);
Greenfoot.delay(40);
}
break;
case 2: prayer();
break;
case 3: heal();
break;
default:break;
}
}
}
if(boss == null || boss.getWorld() == null)
{
bgm.stop();
removeObject(boss);
GreenfootSound victory = new GreenfootSound("BGM/VictoryFanFare.mp3");
victory.playLoop();
showText("YOU HAVE PROTECTED THE WORLD FROM",300,236);
showText("THE EVIL POSSESED TOILET.",300,256);
Greenfoot.delay(100);
showText("YOU HAVE FREED THE PEOPLE OF THEIR FEAR OF", 300, 236);
showText("POOPING AND CLOSED THE SWIRLING VORTEX WITHIN.", 300, 256);
Greenfoot.delay(500);
Greenfoot.delay(5);
victory.stop();
Greenfoot.setWorld(new Credits("images/credits/credits1.png"));
}
if (Greenfoot.isKeyDown("7"))
{
bgm.stop();
removeObject(boss);
GreenfootSound victory = new GreenfootSound("BGM/VictoryFanFare.mp3");
victory.playLoop();
showText("YOU HAVE PROTECTED THE WORLD FROM",300,236);
showText("THE EVIL POSSESED TOILET.",300,256);
Greenfoot.delay(100);
showText("YOU HAVE FREED THE PEOPLE OF THEIR FEAR OF", 300, 236);
showText("POOPING AND CLOSED THE SWIRLING VORTEX WITHIN.", 300, 256);
Greenfoot.delay(500);
Greenfoot.delay(5);
victory.stop();
Greenfoot.setWorld(new Credits("images/credits/credits1.png"));
}
}
}