-
Notifications
You must be signed in to change notification settings - Fork 0
/
Encounters.cs
293 lines (270 loc) · 10.8 KB
/
Encounters.cs
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
using Generic_Text_Based_RPG_Epic_Edition.BaseClasses;
using Generic_Text_Based_RPG_Epic_Edition.Enemies;
using System;
using System.Windows.Input;
using static Generic_Text_Based_RPG_Epic_Edition.Program;
using static System.Console;
namespace Generic_Text_Based_RPG_Epic_Edition
{
public class Encounters
{
public static ConsoleKey input;
public static int SleepTime = 50;
public static bool TextSkip = false;
static Random Rand { get; set; } = new();
static int UsedPotions = 0;
public static void Print(string text, int msgap = 20)
{
var remaining = text;
if (TextSkip == false)
{
foreach (char c in text)
{
Write(c);
remaining = remaining.Remove(0, 1);
System.Threading.Thread.Sleep(msgap);
if (Keyboard.IsKeyDown(Key.Space)|| Keyboard.IsKeyDown(Key.Enter))
{
Write(remaining);
TextSkip = true;
break;
}
}
}
else
Write(text);
WriteLine();
}
// Encounters
public static void SlimeEncounter()
{
Clear();
if (Rand.Next(0, 21) == 1)
{
if (CurrentPlayer.Level >= 20)
{
SlimeKing slimeKing = new();
slimeKing.StartBattle();
}
else
{
Slime slime = new();
slime.StartBattle();
}
}
else
{
Slime slime = new();
slime.StartBattle();
}
}
// Encounters Tools
public static void RandomEncounter()
{
switch (Rand.Next(0, 3))
{
case 0:
BasicEnemy basicEnemy = new();
basicEnemy.StartBattle();
break;
case 1:
SkeletonArcher skeletonArcher = new();
skeletonArcher.StartBattle();
break;
case 2:
SlimeEncounter();
break;
}
}
public static void Combat(Enemy enemy)
{
CurrentEnemy = enemy;
while (enemy.Health > 0)
{
TextSkip = true;
Clear();
Print(enemy.Name, 10);
Print(enemy.Power + " Attack" + " / " + enemy.Health + " Health" + " / " + enemy.Defense + " Defense", 10);
Print("\n=====================", 0);
Print("| (A)ttack (D)efend |", 0);
Print("| (R)un (H)eal |", 0);
Print("=====================", 0);
Print("Potions: " + CurrentPlayer.Potion + " Health: " + CurrentPlayer.Health + "/" + CurrentPlayer.MaxHealth, 10);
while (true)
{
input = ReadKey(true).Key;
if (input == ConsoleKey.A)
{
TextSkip = false;
Attack(enemy);
break;
}
else if (input == ConsoleKey.D)
{
TextSkip = false;
Defend(enemy);
break;
}
else if (input == ConsoleKey.R)
{
TextSkip = false;
Run(enemy);
break;
}
else if (input == ConsoleKey.H)
{
TextSkip = false;
Heal(enemy);
break;
}
}
if (CurrentPlayer.Health <= 0)
{
TextSkip = false;
CurrentEnemy = enemy;
Print("\nAs the " + enemy.Name + " strikes you it hits with a fatal blow!");
Print("\n (Press R To Restart) \n (Press Enter to Exit Game)");
while (true)
{
input = ReadKey(true).Key;
if (input == ConsoleKey.Enter)
Environment.Exit(0); //Restart System
}
}
}
int lootCoins = CurrentPlayer.CoinCalc();
TextSkip = false;
Print("\nAs you stand victorious over the " + enemy.Name + ", its body dissolves into " + lootCoins + " gold coins!");
ReadKey(true);
CurrentPlayer.Coins += lootCoins;
CurrentPlayer.LevelCheck(enemy.XP);
UsedPotions = 0;
}
public static void Attack(Enemy enemy)
{
Print("\nYou run forward swinging hoping to hit something! As you pass, the " + enemy.Name + " strikes you back!");
int damage = enemy.Power - (CurrentPlayer.ArmorValue + CurrentPlayer.Defense + Rand.Next(1, 4));
if (damage < 0)
damage = 0;
int attack = Rand.Next(0, CurrentPlayer.CurrentWeapon.Damage + CurrentPlayer.Strength) + Rand.Next(1, 4) - enemy.Defense;
if (attack < 0)
attack = 1;
Print("You lose " + damage + " health and deal " + attack + " damage");
Print("\n(Press Enter To Continue)");
while (true)
{
input = ReadKey(true).Key;
if (input == ConsoleKey.Enter)
break;
}
CurrentPlayer.Health -= damage;
enemy.Health -= attack;
}
public static void Defend(Enemy enemy)
{
Print("\nAs the " + enemy.Name + " prepares to strike, you ready your sword in a defensive stance!");
int damage = (enemy.Power / 4) + 1 - (CurrentPlayer.ArmorValue - 1 + CurrentPlayer.Defense + Rand.Next(1, 4));
int attack = 0;
if (damage < 0)
damage = 0;
Print("You lose " + damage + " health.");
if (Rand.Next(1, 11) == 7)
{
attack = Rand.Next(3, CurrentPlayer.CurrentWeapon.Damage + CurrentPlayer.Strength + 5) - enemy.Defense;
Print("\nYou get an opportunity to counterattack! The enemy takes " + attack + " damage.");
}
Print("\n(Press Enter To Continue)");
while (true)
{
input = ReadKey(true).Key;
if (input == ConsoleKey.Enter)
break;
}
CurrentPlayer.Health -= damage;
enemy.Health -= attack;
}
public static void Run(Enemy enemy)
{
if (Rand.Next(0, 2) == 0)
{
Print("\nAs you sprint away from the " + enemy.Name + ", its strike catches you in the back, sending you sprawling onto the ground!");
int damage = enemy.Power - (CurrentPlayer.ArmorValue + CurrentPlayer.Defense + Rand.Next(1, 4));
if (damage < 0)
damage = 0;
Print("You lose " + damage + " health and are unable to escape.");
Print("\n(Press Enter To Continue)");
while (true)
{
input = ReadKey(true).Key;
if (input == ConsoleKey.Enter)
break;
}
CurrentPlayer.Health -= damage;
}
else
{
Print("\nYou use your crazy mobility to evade the attacks of " + enemy.Name + " and you escape!");
Print("\n(Press Enter To Continue)");
while (true)
{
input = ReadKey(true).Key;
if (input == ConsoleKey.Enter)
break;
}
CurrentEnemy = enemy;
Shop.RunShop(CurrentPlayer);
}
}
public static void Heal(Enemy enemy)
{
if (CurrentPlayer.Potion == 0)
{
Print("\nAs you desperately grasp for a potion in your bag, all that you can find is empty glass flasks!");
int damage = enemy.Power - (CurrentPlayer.ArmorValue + CurrentPlayer.Defense + Rand.Next(1, 4));
if (damage < 0)
damage = 0;
Print("The " + enemy.Name + " strikes you with a mighty blow, and you lose " + damage + " health!");
CurrentPlayer.Health -= damage;
}
else
{
if (UsedPotions < 3)
{
Print("\nYou reach into your bag and pull out a glowing, red flask. You take a swig, you feel your body lighten up.");
int potionV = 5;
if (potionV + CurrentPlayer.Health > CurrentPlayer.MaxHealth)
{
potionV = CurrentPlayer.MaxHealth - CurrentPlayer.Health;
}
Print("You gain " + potionV + " health");
CurrentPlayer.Health += potionV;
Print("\nAs you were occupied, the " + enemy.Name + " advanced and struck.");
int damage = (enemy.Power / 2) - (CurrentPlayer.ArmorValue + CurrentPlayer.Defense + Rand.Next(1, 4));
if (damage < 0)
damage = 0;
UsedPotions += 1;
Print("You lose " + damage + " health.");
if (UsedPotions == 1)
Print("\n1/3 Potions Used.");
else if (UsedPotions == 2)
Print("\n2/3 Potions Used");
else if (UsedPotions == 3)
Print("\n3/3 Potions Used");
CurrentPlayer.Health -= damage;
CurrentPlayer.Potion--;
}
else
{
Print("\nThe thought of drinking even one more potion sickens you.");
}
}
Print("\n(Press Enter To Continue)");
while (true)
{
input = ReadKey(true).Key;
if (input == ConsoleKey.Enter)
break;
}
}
}
}