-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
488 lines (404 loc) · 20.4 KB
/
Program.cs
File metadata and controls
488 lines (404 loc) · 20.4 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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
using System;
using System.Threading;
namespace EternityRPG
{
class Program
{
private static int biomeType { get; set; }
static void Main(string[] args)
{
string yesOrNo = string.Empty;
string input = string.Empty;
int choice = default;
Print.GameTitle();
Print.PressEnter();
Print.RainbowLoading(consoleClear: true);
Print.Text("Hello, traveler. I can't remember your", ConsoleColor.Cyan);
Print.Text(" name ", ConsoleColor.DarkYellow);
Print.Text("Can you help me with this?\n\n", ConsoleColor.Cyan);
Thread.Sleep(1500);
//******************** SECTION OF CREATING A PLAYER ********************
while (yesOrNo != "y")
{
yesOrNo = string.Empty;
//selection of player's name ********************
Print.Text("Enter your name or press ENTER: ");
Game.player.SetName(GetPlayerInput(ConsoleColor.Green));
//selection of player's gender ********************
Print.GenderOptions();
do
{
Print.Text("choose gender: ".PadLeft(47, ' '));
int.TryParse(GetPlayerInput(ConsoleColor.Green), out choice);
}
while (choice == 0 || choice > Game.genders.Count);
Game.player.SetGender(choice);
//selection of player's class ********************
Print.PlayerClassOptions();
do
{
Print.Text("choose class: ".PadLeft(46, ' '));
int.TryParse(GetPlayerInput(ConsoleColor.Green), out choice);
}
while (choice == 0 || choice > Game.classes.Count);
Game.player.SetClass(choice);
//creating player according to chosen class
Game.CreatePlayer();
do
{
//card of player before start of the game
Print.PlayerShortInfo(Game.player);
Print.Question("Are you ready to start the adventure with this character?");
yesOrNo = GetPlayerInput(ConsoleColor.Green);
}
while (yesOrNo != "y" && yesOrNo != "n");
Console.Clear();
}
//creating weapons (according to chosen class) / enemies / bosses / locations
Game.InitializeWorld();
Print.AdventureBegins();
Print.RainbowLoading(consoleClear: true);
//******************** SECTION OF THE MAIN GAMEPLAY ********************
while (!Game.player.IsDead)
{
//******************** CHOOSING DIRECTION ********************
int selectDirection = default;
while (selectDirection == 0 || selectDirection > Game.directions.Count)
{
//change your direction
Print.ChangeDirection();
Print.Text("\tmake your choice: ");
int.TryParse(GetPlayerInput(ConsoleColor.Cyan), out selectDirection);
}
//******************** SHOP ********************
if (selectDirection == 1)
{
do
{
Print.ShopOptions(Game.player, Game.inventory);
Console.Write("make your choice: ".PadLeft(44, ' '));
input = GetPlayerInput(ConsoleColor.DarkYellow);
int.TryParse(input, out choice);
//trying to buy something
if (choice > 0 && choice <= Game.inventory.Length)
Game.inventory[choice - 1].Buy(Game.player, Game.inventory, choice);
}
while (input != "<");
}
//******************** LOCATIONS ********************
if (selectDirection == 2)
{
int maxLocations;
int deathCounter = default;
//checking if you killed enough bosses to unlock final location
foreach (var boss in Game.bosses)
if (boss.IsDead)
deathCounter++;
if (deathCounter == Game.bosses.Length - 1)
maxLocations = Game.biomes.Length;
else
maxLocations = Game.biomes.Length - 1;
choice = default;
while (choice == 0 || choice > maxLocations)
{
Print.SelectLocation(Game.bosses, Game.biomes, maxLocations);
Console.Write("make your choice: ".PadLeft(44, ' '));
input = GetPlayerInput(ConsoleColor.Green);
//exit from choosing locations
if (input == "<") break;
int.TryParse(input, out choice);
//create location according to the number of chosen location
biomeType = choice - 1;
}
if (input == "<") continue;
//enter to the secret location, if you already killed three bosses
if (choice == Game.biomes.Length)
{
yesOrNo = string.Empty;
while (yesOrNo != "y" && yesOrNo != "n")
{
Console.Clear();
Print.Question($"Are you ready for final battle?", ConsoleColor.Cyan);
yesOrNo = GetPlayerInput(ConsoleColor.Cyan);
}
Console.Clear();
//final fight of the game
if (yesOrNo == "y")
{
BattleZone(bossBattle: true);
//if you win final battle
if (Game.bosses[biomeType].IsDead)
{
Print.TheEnd(Game.player, Game.inventory);
break;
}
}
}
//starting battle section according to the chosen location
else
{
//printing full info about the location, only once in each location, according to the chosen location
Print.Text($"{Game.biomes[biomeType].LocationInfo}\n", ConsoleColor.DarkGreen, slow: true, consoleClear: true);
//start battle section with regular enemies
BattleZone();
}
}
//******************** PLAYER STATS ********************
if (selectDirection == 3)
{
Print.PlayerStatistics(Game.player, Game.inventory);
Print.PressEnter();
}
//if you killed enough enemies in the location, you can fight with boss of this location, if it is not dead
if (Game.DefeatedEnemiesToFightTheBoss == Game.bosses[biomeType].CounterToReachTheBoss && !Game.bosses[biomeType].IsDead)
{
Print.BossFight();
Print.Text($"\tGet ready for battle, the {Game.bosses[biomeType].Name} is coming...\n\n");
Print.PressEnter();
Console.Clear();
//start boss fight
BattleZone(bossBattle: true);
}
}
}
//******************** SECTION OF BATTLE LOGIC ********************
public static void BattleZone(bool bossBattle = false)
{
if (!bossBattle)
{
//setting counter of defeated enemies to 0 before the start of each battle
Game.DefeatedEnemiesToFightTheBoss = 0;
}
string yesOrNo = string.Empty;
while (yesOrNo != "n")
{
int choice = default;
string keyBoardInput = string.Empty;
yesOrNo = string.Empty;
//printing short name of the location before each regular enemy
Print.Text($"Location: {Game.biomes[biomeType].ShortTitle}\n", ConsoleColor.DarkCyan);
if (!bossBattle)
{
//create new enemy randomly every time when the cycle starts again, according to the chosen location
Game.enemy = Game.biomes[biomeType].CreateEnemy();
Print.RainbowLoading(Game.random.Next(1, 9));
//print randomly generated phrase when new enemy appear
Print.EntryBattlePhrase(Game.enemy);
}
else
{
Game.enemy = Game.bosses[biomeType];
Print.Text($"\nBOSS: {Game.enemy.Name}\n\n", ConsoleColor.DarkRed);
}
Print.BattleOptions();
while (true)
{
Print.Text("choose action: ".PadLeft(41, ' '));
keyBoardInput = GetPlayerInput(ConsoleColor.DarkGray);
int.TryParse(keyBoardInput, out int battleChoice);
//manual fight - 1 && automatic fight - 2
if (battleChoice == 1 || battleChoice == 2)
{
while (Game.player.HP > 0 || Game.enemy.HP > 0)
{
NextAttack(Game.player, PlayerDamage());
//if an enemy is dead
if (Game.enemy.IsDead)
{
Game.player.Gold += Game.enemy.Gold;
Game.player.Exp += Game.enemy.Exp;
//check if player has enough experience to get new level
Game.player.LevelUp(Game.player.Exp);
Print.PlayerStatistics(Game.player, Game.inventory);
if (!bossBattle)
{
Game.DefeatedEnemiesOverall++;
Game.DefeatedEnemiesToFightTheBoss++;
break;
}
else
{
Game.DefeatedBossesOverall++;
Print.PressEnter();
return;
}
}
NextAttack(Game.enemy, Game.enemy.GenerateDamage());
//if the player is dead
if (Game.player.IsDead) return;
//if the player has low hp
if (Game.player.HP <= Game.player.DangerousLevelOfHealth()) break;
//if manual fight, break to choose next option
if (battleChoice == 1) break;
//else continue automatic fight
else Thread.Sleep(500);
}
if (Game.enemy.IsDead) break;
}
//battle optins => healing options
if (battleChoice == 3)
{
Print.HealingOptions(Game.inventory);
choice = default;
while (choice == 0 || choice > Potion.AmountOfPotions())
{
Print.Text("make your choice: ".PadLeft(44, ' '));
keyBoardInput = GetPlayerInput(ConsoleColor.DarkGreen);
int.TryParse(keyBoardInput, out choice);
if (keyBoardInput == "<")
{
Print.Text("\n");
break;
}
}
if (choice > 0 && choice <= Potion.AmountOfPotions())
{
int x = choice - 1;
//if you have potion
if (Game.inventory[x].Amount > 0)
{
Game.inventory[x].Use(Game.player, Game.inventory, choice);
//if player's current health equal or greater than maximum health
if (Game.player.HP > Game.player.MaxHP)
{
Game.player.HP = Game.player.MaxHP;
Print.Text("\n\tmax HP\n", ConsoleColor.DarkGreen);
}
//if not => heal
else Print.Text($"\n\t+{Game.inventory[x].HealingPower} HP. {Game.player.Name} have {Game.player.HP} HP now\n", ConsoleColor.DarkGreen);
}
//if you don't have any potions
else Print.Text($"\n\tYou don't have {Game.inventory[x].Title}\n", ConsoleColor.DarkRed);
//enemy does his turn, after you tried to heal
NextAttack(Game.enemy, Game.enemy.GenerateDamage());
//if the player is dead
if (Game.player.IsDead) return;
}
}
//battle optins => buff options
if (battleChoice == 4)
{
Print.BuffOptions(Game.inventory);
choice = default;
while (choice == 0 || choice > Buff.AmountOfBuffs())
{
Print.Text("make your choice: ".PadLeft(44, ' '));
keyBoardInput = GetPlayerInput(ConsoleColor.DarkMagenta);
int.TryParse(keyBoardInput, out choice);
if (keyBoardInput == "<")
{
Print.Text("\n");
break;
}
}
if (choice > 0 && choice <= Buff.AmountOfBuffs())
{
int x = choice + Buff.AmountOfBuffs() - 1;
//if you have elixir
if (Game.inventory[x].Amount > 0)
{
Game.inventory[x].Use(Game.player, Game.inventory, choice);
Print.Text($"\n\t+{Game.inventory[x].BuffPower} DMG", ConsoleColor.DarkRed);
Print.Text($" / ");
Print.Text($"{Game.inventory[x].CurrentDurationOfEffect} hits left\n", ConsoleColor.DarkRed);
}
//if you don't have any elixirs
else Print.Text($"\n\tYou don't have {Game.inventory[x].Title} elixir of strength\n", ConsoleColor.DarkRed);
//enemy does his turn, after you tried to use buff
NextAttack(Game.enemy, Game.enemy.GenerateDamage());
//if the player is dead
if (Game.player.IsDead) return;
}
}
//show player stats
if (battleChoice == 5)
Print.PlayerStatistics(Game.player, Game.inventory);
//trying to run away from the enemy
if (battleChoice == 6)
{
//calculating the player's chance to escape randomly
//if you succeed in escaping
if (Game.random.Next(0, 100) > Game.enemy.ChanceToInterruptTheEscape)
{
//lost 10 percent of all gold you own
double penalty = (int)((Game.player.Gold / 100) * 10);
Game.player.Gold -= penalty;
if (Game.player.Gold <= 0) Game.player.Gold = 0;
Print.Text("\n\tYou escaped successfully", ConsoleColor.DarkGreen);
Print.Text($"\n\t-{penalty} gold", ConsoleColor.DarkRed);
Print.Text(", ");
Print.Text($"{Game.player.Gold} gold ", ConsoleColor.DarkYellow);
Print.Text("remaining\n\n");
Print.PressEnter();
return;
}
//you can't avoid a battle with some enemies
else
{
if (Game.enemy.ChanceToInterruptTheEscape == 100)
Print.Text($"\n\tyou can't escape from the {Game.enemy.Name}\n", ConsoleColor.DarkRed);
else
Print.Text("\n\tfailed to escape\n", ConsoleColor.DarkRed);
//if you failed to escape, an enemy does his attack
NextAttack(Game.enemy, Game.enemy.GenerateDamage());
//if the player is dead
if (Game.player.IsDead) return;
}
}
}
if (Game.DefeatedEnemiesToFightTheBoss == Game.bosses[biomeType].CounterToReachTheBoss && !Game.bosses[biomeType].IsDead) return;
//asking if you want to continue grinding or not
do
{
Print.Question($"Farm more at the {Game.biomes[biomeType].ShortTitle}?", ConsoleColor.Cyan);
yesOrNo = GetPlayerInput(ConsoleColor.Cyan);
if (yesOrNo == "y") Console.Clear();
}
while (yesOrNo != "y" && yesOrNo != "n");
void NextAttack(Character attacker, double damage)
{
if (Game.random.Next(0, 100) > attacker.CritChance)
attacker.Attack(Game.player, Game.enemy, damage);
else
attacker.Attack(Game.player, Game.enemy, damage, crit: true);
}
double PlayerDamage()
{
double damage = Game.player.GenerateDamage();
//if player bought weapon, it will generate damage + weapon damage
for (int i = 0; i < Game.inventory.Length; i++)
{
if (Game.inventory[i].WeaponIsBought)
{
damage += Game.inventory[i].Damage;
break;
}
}
//additional damage will be added if player use elixir
for (int i = 0; i < Game.inventory.Length; i++)
{
if (Game.inventory[i].BuffIsActive && Game.inventory[i].CurrentDurationOfEffect > 0)
{
damage += Game.inventory[i].BuffPower;
Game.inventory[i].CurrentDurationOfEffect--;
if (Game.inventory[i].CurrentDurationOfEffect == 0)
{
Game.inventory[i].BuffIsActive = false;
break;
}
}
}
//returning all calculated damage
return damage;
}
}
}
private static string GetPlayerInput(ConsoleColor color = ConsoleColor.White)
{
Console.ForegroundColor = color;
string input = Console.ReadLine().ToLower();
Console.ResetColor();
return input;
}
}
}