-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameDriver.java
293 lines (241 loc) · 11.5 KB
/
GameDriver.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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import java.util.Scanner;
import java.util.Random;
/** Creates GameDriver class.
* Works with Player and Enemy class.
*/
public class GameDriver {
/** Main method used as engine.
* @param args - not used.
*/
public static void main(String[] args) {
// Setup:
boolean gameRunning = true;
int num = 0;
int layer = 1;
// Introduce name of game:
System.out.println("\n----------Welcome to Dungeon Divers!----------\n");
// Give short summary of how to play:
System.out.println("In Dungeon Divers, you progress through layers of dungeons "
+ "\nto level up and see how far you can go!\n");
System.out.println("Kill 5 enemies in a row to progress to the next layer."
+ "\nThe 5th enemy will be a special boss enemy who is tougher to kill.");
System.out.println("\nGet through layer 5 and defeat the Imperial Red Dragon to win.\n");
// Ask for name of player:
Scanner sc = new Scanner(System.in);
System.out.println("Before you begin your crawl through layer 1, what is your name?");
String tempName = sc.nextLine().trim();
/*Could add a confirmation for name.*/
// Create Player with param name:
Player player = new Player(tempName);
// Main Game Loop begins:
while (gameRunning) {
//Creates enemy:
Enemy e1 = new Enemy();
// Determines what # enemy:
num += 1;
if (num > 5) {
num = 1;
//Post Game enemy stats increased.
if (layer > 5) {
e1.levelUp();
e1.setLuck(1);
}
//Normal Game enemy stats increased.
else {
e1.levelUp();
}
}
// Check for Boss / Generate stats for boss:
if (num == 5) {
//End Boss set stats.
if (layer == 5) {
e1.setName("Imperial Red Dragon");
e1.setAttack(100);
e1.setHp(150);
e1.setDefense(0);
e1.setLuck(e1.getLuck());
}
else {
// Normal Bosses:
String[] eBossList = new String[15];
eBossList[0] = "Blue Dragon Boss";
eBossList[1] = "Giant Troll Boss";
eBossList[2] = "Warlord Shaman Boss";
eBossList[3] = "Treasure Seeker Goblin Boss";
eBossList[4] = "Bloodthirsty Gnoll Boss";
int eBossLength = 4;
Random rn = new Random();
String tName = eBossList[rn.nextInt(eBossLength + 1)];
//Post Game bosses stats increased:
if (layer > 5) {
e1.setName(tName);
e1.setAttack(e1.getAttack() + 20);
e1.setHp(e1.getHp() + 30);
e1.setDefense(e1.getDefense());
e1.setLuck(e1.getLuck());
}
//Normal game bosses stats:
else {
e1.setName(tName);
e1.setAttack(e1.getAttack() + 10);
e1.setHp(e1.getHp() + 15);
e1.setDefense(e1.getDefense() - 5);
e1.setLuck(e1.getLuck() - 1);
}
}
}
// Enemy appears / Combat begins:
System.out.println("\n*Layer " + layer + ": Enemy " + num + " of 5*");
System.out.println("A " + e1.getName() + " appears!");
boolean combat = true;
// Combat Loop:
while (combat) {
System.out.println("");
System.out.println(player.toString());
System.out.println(e1.toString() + "\n");
System.out.println("What do you want to do?");
System.out.println("---[A]ttack, [D]odge, [H]eal---");
String line = sc.next().toUpperCase();
char action = line.charAt(0);
System.out.println("");
// Simplify variables:
String eName = e1.getName();
int pAtk = player.getAttack();
// Switch for options available (Attack, Dodge, Heal):
switch(action) {
// Try to attack:
case 'A':
//Player hits:
if (player.checkHit(player.getLuck())) {
e1.takeHit(pAtk - e1.getDefense());
int hit = pAtk - e1.getDefense();
System.out.println(eName + " took " + hit + " damage!");
if (e1.getHp() <= 0) {
break;
}
}
//Player misses:
else {
System.out.println("You missed!");
}
//Enemy hits:
if (e1.checkHit(e1.getLuck())) {
int hit = e1.getAttack() - player.getDefense();
System.out.println(eName + " hit you for " + hit + "!");
player.takeHit(e1.getAttack() - player.getDefense());
}
//Enemy misses:
else {
System.out.println(eName + " missed!");
}
break;
// Try to dodge:
case 'D':
System.out.println("You attempt to block the incoming attack!");
//Dodge failed:
if (e1.checkHit(e1.getLuck() + 3)) {
int hit = e1.getAttack() - player.getDefense();
System.out.println(eName + " still hit for " + hit + "!");
player.takeHit(e1.getAttack() - player.getDefense());
}
//Dodge is successful:
else {
System.out.println("You successfully dodged the incoming attack!");
System.out.println("You regained a small portion of your health!");
player.restoreHp(5 * player.getLevel());
}
break;
// Restore Health:
case 'H':
//If max health:
if (player.getHp() >= player.getMaxHp()) {
System.out.println("You are already at full health!");
break;
}
//Regain health (10hp * current player level):
else {
System.out.println("You use a potion to regain health!");
player.restoreHp(10 * player.getLevel());
System.out.println("Your health is now " + player.getHp() + ".");
}
//Check to see if enemy hits:
if (e1.checkHit(e1.getLuck() + 1)) {
int hit = e1.getAttack() - player.getDefense();
System.out.println(eName + " still hit for " + hit + "!");
player.takeHit(e1.getAttack() - player.getDefense());
}
break;
// Invalid command:
default:
System.out.println("Invalid command.");
break;
}
// Check to see if anyone died:
if (e1.getHp() <= 0) {
int amt = e1.generateGold();
player.addGold(amt);
System.out.println("You gained " + amt + " gold!");
System.out.println(e1.died());
combat = false;
//Layer increases if boss defeated:
if (num == 5) {
layer++;
//End tutorial / explain level up:
if (layer == 2) {
System.out.println("Enemies get tougher for every layer, but so do you.");
System.out.println("Keep the hordes at bay! Treasure awaits!");
System.out.println("When you level up, the stat of your choosing goes up by 10 (20 for HP)."
+ "\nBut don't worry, the others still go up by 5 (10 for HP).");
}
//End game / Player defeated final boss:
if (layer == 5) {
System.out.println("\nYou defeated the Imperial Red Dragon!");
System.out.println("Congratulations!");
System.out.println("***You have successfully completed Dungeon Divers!***\n"
+ "\nYou can keep going however, enemies will get a lot tougher from now on.");
}
// Level up:
System.out.println("\nYou leveled up!");
System.out.println("What do you want to upgrade?");
System.out.println("---[A]ttack, [D]efense, [H]ealth---");
String line2 = sc.next().toUpperCase();
char upgrade = line2.charAt(0);
boolean levelPhase = true;
//Level Loop active (for invalid commands):
while (levelPhase) {
// Switch for options (Attack, Defense, Health):
switch (upgrade) {
case 'A':
System.out.println("You upgraded attack!");
player.levelUp(1);
levelPhase = false;
break;
case 'D':
System.out.println("You upgraded defense!");
player.levelUp(2);
levelPhase = false;
break;
case 'H':
System.out.println("You upgraded health!");
player.levelUp(3);
levelPhase = false;
break;
default:
System.out.println("Invalid command.");
break;
}
}
System.out.println("--------------------------------------------------------");
}
}
//If player dies:
if (player.getHp() <= 0) {
combat = false;
System.out.println(player.died());
gameRunning = false;
System.exit(0);
}
}
}
}
}