-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
704 lines (609 loc) · 25.6 KB
/
Program.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
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
using System.Security.Cryptography;
using static System.Console;
namespace ASCII_CLI_IdleRPG
{
internal class Program
{
// Basic game logic
static bool isRunning = true;
static bool isMenu = true;
static bool isPlay = false;
static bool isRules = false;
//static short choice;
static int choice;
//static char choice;
//static string choice;
// Battle logic
static bool Fight = false;
static bool Standing = true;
static Random random = new Random();
// Advanture logic
static bool shopBuy = false;
static bool speakMayor = false;
static bool bossEnemy = false;
public class CharacterStats
{
public string Name { get; set; }
public int HP { get; set; } = 50;
public int HPMAX { get; private set; } = 50;
public int ATK { get; set; } = 3;
public int POTION { get; set; } = 1;
public int ELIXIR { get; set; } = 0;
public int GOLD { get; set; } = 7;
public int CoordinateX { get; set; } = 0;
public int CoordinateY { get; set; } = 0;
public bool IsKey { get; set; } = false;
}
static CharacterStats characterStats = new CharacterStats();
static public string Name = characterStats.Name;
static public int HP = characterStats.HP;
static public int HPMAX = characterStats.HPMAX;
static public int ATK = characterStats.ATK;
static public int POTION = characterStats.POTION;
static public int ELIXIR = characterStats.ELIXIR;
static public int GOLD = characterStats.GOLD;
static public int CoordinateX = characterStats.CoordinateX;
static public int CoordinateY = characterStats.CoordinateY;
static public bool IsKey = characterStats.IsKey;
// Maps 2d array or matix
static string[,] Map = //columns (X)
{ // x = 0 // x = 1 // x = 2 // x = 3 // x = 4 // x = 5 // x = 6 // rows (Y)
{ "plains", "plains", "plains", "plains", "forest", "mountain", "cave" }, // y = 0
{ "forest", "forest", "forest", "forest", "forest", "hills", "mountain" }, // y = 1
{ "forest", "fields", "bridge", "plains", "hills", "forest", "hills" }, // y = 2
{ "plains", "shop", "town", "mayor", "plains", "hills", "mountain" }, // y = 3
{ "plains", "fields", "fields", "plains", "hills", "mountain", "mountain" } // y = 4
};
static int LengthY = Map.GetLength(0) - 1;
static int LengthX = Map.GetLength(1) - 1;
// Dict of Biom enemy spawn
static Dictionary<string, Dictionary<string, object>> Biom = new Dictionary<string, Dictionary<string, object>>()
{
{"plains", new Dictionary<string, object> { {"text", "PLAINS"}, {"enemy", true} }},
{"forest", new Dictionary<string, object> { {"text", "WOODS"}, {"enemy", true} }},
{"fields", new Dictionary<string, object> { {"text", "FIELDS"}, {"enemy", false} }},
{"bridge", new Dictionary<string, object> { {"text", "BRIDGE"}, {"enemy", true} }},
{"town", new Dictionary<string, object> { {"text", "TOWN CENTRE"}, {"enemy", false} }},
{"shop", new Dictionary<string, object> { {"text", "SHOP"}, {"enemy", false} }},
{"mayor", new Dictionary<string, object> { {"text", "MAYOR"}, {"enemy", false} }},
{"cave", new Dictionary<string, object> { {"text", "CAVE"}, {"enemy", false} }},
{"mountain", new Dictionary<string, object> { {"text", "MOUNTAIN"}, {"enemy", true} }},
{"hills", new Dictionary<string, object> { {"text", "HILLS"}, {"enemy", true} }},
};
static List<string> EnemyList = new List<string>() { "Goblin", "Orc", "Slime" };
static Dictionary<string, Dictionary<string, int>> Mobs = new Dictionary<string, Dictionary<string, int>>()
{
{"Goblin", new Dictionary<string, int>() { { "hp", 15 }, { "atk", 3 }, { "gold", 8 } } },
{"Orc", new Dictionary<string, int>() { { "hp", 35 }, { "atk", 5 }, { "gold", 18 } } },
{"Slime", new Dictionary<string, int>() { { "hp", 30 }, { "atk", 2 }, { "gold", 12 } } },
{"Dragon", new Dictionary<string, int>() { { "hp", 100 }, { "atk", 8 }, { "gold", 100 } } }
};
static void startPageInfo()
{
WriteLine(@" ▄▄▄▄▀ ▄███▄ ▄ ▄▄▄▄▄ ▄ █▄▄▄▄ ██
▀▀▀ █ █▀ ▀ █ █ ▀▄ █ █ ▄▀ █ █
█ ██▄▄ ██ █ ▄ ▀▀▀▀▄ █ █ █▀▀▌ █▄▄█
█ █▄ ▄▀ █ █ █ ▀▄▄▄▄▀ █ █ █ █ █ █
▀ ▀███▀ █ █ █ █▄ ▄█ █ █
█ ██ ▀▀▀ ▀ █
▀
▄█ ██▄ █ ▄███▄ █▄▄▄▄ █ ▄▄ ▄▀
██ █ █ █ █▀ ▀ █ ▄▀ █ █ ▄▀
██ █ █ █ ██▄▄ █▀▀▌ █▀▀▀ █ ▀▄
▐█ █ █ ███▄ █▄ ▄▀ █ █ █ █ █
▐ ███▀ ▀ ▀███▀ █ █ ███
▀ ▀ ");
drawLine();
WriteLine("1. NEW GAME");
WriteLine("2. LOAD GAME");
WriteLine("3. RULES");
WriteLine("4. QUIT GAME");
drawLine();
WriteLine("Play by typing choosen options like 1 and click Enter");
drawLine();
}
static void drawLine()
{
WriteLine("xX--------------------xX");
}
static void Save()
{
string[] list = new string[]
{
Name,
HP.ToString(),
ATK.ToString(),
POTION.ToString(),
ELIXIR.ToString(),
GOLD.ToString(),
CoordinateX.ToString(),
CoordinateY.ToString(),
IsKey.ToString()
};
// TODO: Save this file in current project directory not in bin/Debug/load.txt
// NOTE: there may be use interface and save it another data formats like plain text, json, database like sqlite for executable game
using (StreamWriter file = new StreamWriter("load.txt"))
{
foreach (string item in list)
{
file.WriteLine(item);
}
}
}
static void Heal(int amount)
{
if (HP + amount < HPMAX) { HP += amount; }
else { HP = HPMAX; }
WriteLine($"{Name}'s HP refilled to {HP}!");
}
static void Battle()
{
string enemyName;
if (!bossEnemy)
{
int randomEnemyIndex = random.Next(EnemyList.Count);
enemyName = EnemyList[randomEnemyIndex];
}
else { enemyName = "Dragon"; }
int enemyHP = Mobs[enemyName]["hp"];
int enemyHPMax = enemyHP;
int enemyATK = Mobs[enemyName]["atk"];
int enemyGold = Mobs[enemyName]["gold"];
while (Fight)
{
Clear();
drawLine();
WriteLine("Defeat the " + enemyName + "!");
drawLine();
WriteLine($"{enemyName}'s HP: {enemyHP}/{enemyHPMax}");
WriteLine($"{Name}'s HP: {HP}/{HPMAX}");
WriteLine($"POTIONS: {POTION}");
WriteLine($"ELIXIR: {ELIXIR}");
drawLine();
WriteLine("1 - ATTACK");
if (POTION > 0) { WriteLine("2 - USE POTION (30HP)"); }
if (ELIXIR > 0) { WriteLine("3 - USE ELIXIR (50HP)"); }
drawLine();
Write($"{Name}# ");
string choice = ReadLine();
if (choice == "1")
{
enemyHP -= ATK;
WriteLine($"{Name} dealt {ATK} damage to the {enemyName}.");
if (enemyHP > 0)
{
HP -= enemyATK;
WriteLine($"{enemyName} dealt {enemyATK} damage to the {Name}.");
}
Write($"{Name}> ");
ReadLine();
}
else if (choice == "2")
{
if (POTION > 0)
{
POTION--;
Heal(amount: 30);
// Skip one move if player in Fight with enemy
HP -= enemyATK;
WriteLine($"{enemyName} dealt {enemyATK} damage to the {Name}.");
}
else { WriteLine("No potions!"); }
Write($"{Name}> ");
ReadLine();
}
else if (choice == "3")
{
if (ELIXIR > 0)
{
ELIXIR--;
Heal(amount: 50);
// Skip one move if player in Fight with enemy
HP -= enemyATK;
WriteLine($"{enemyName} dealt {enemyATK} damage to the {Name}.");
}
else { WriteLine("No elixirs!"); }
Write($"{Name}> ");
ReadLine();
}
if (HP <= 0)
{
WriteLine($"{enemyName} defeated {Name}...");
drawLine();
Fight = false;
isPlay = false;
isRunning = false;
WriteLine("GAME OVER");
Write($"{Name}> ");
ReadLine();
}
if (enemyHP <= 0)
{
WriteLine($"{Name} defeated the {enemyName}!");
drawLine();
Fight = false;
GOLD += enemyGold;
WriteLine($"You've found {enemyGold} gold!");
if (random.Next(0, 100) <= 30)
{
POTION++;
WriteLine($"You've found a potion!");
}
else if (random.Next(0, 100) <= 20)
{
ELIXIR++;
WriteLine($"You've found a elixir!");
}
if (enemyName == "Dragon")
{
WriteLine("Congratulations, you've finished the game!");
bossEnemy = false;
isPlay = false;
isRunning = false;
}
Write($"{Name}> ");
ReadLine();
Clear();
}
}
}
static void Shop()
{
while (shopBuy)
{
Clear();
drawLine();
WriteLine("Welcome to the shop!");
drawLine();
WriteLine($"GOLD: {GOLD}");
WriteLine($"POTIONS: {POTION}");
WriteLine($"ELIXIRS: {ELIXIR}");
WriteLine($"ATK: {ATK}");
drawLine();
WriteLine("1 - BUY POTION (30 HP) - 5 GOLD");
WriteLine("2 - BUY ELIXIR (MAXHP) - 8 GOLD");
WriteLine("3 - UPGRADE WEAPON (+2ATK) - 10 GOLD");
WriteLine("4 - LEAVE");
drawLine();
Write($"{Name}# ");
string choice = ReadLine();
if (choice == "1")
{
if (GOLD >= 5)
{
POTION++;
GOLD -= 5;
WriteLine("You've bought a potion!");
}
else { WriteLine("Not enough gold!"); }
Write($"{Name}> ");
ReadLine();
}
else if (choice == "2")
{
if (GOLD >= 8)
{
ELIXIR++;
GOLD -= 8;
WriteLine("You've bought a elixir!");
}
else { WriteLine("Not enough gold!"); }
Write($"{Name}> ");
ReadLine();
}
else if (choice == "3")
{
if (GOLD >= 10)
{
ATK += 2;
GOLD -= 10;
WriteLine("You've upgraded your weapon!");
}
else { WriteLine("Not enough gold!"); }
Write($"{Name}> ");
ReadLine();
}
else if (choice == "4") { shopBuy = false; }
}
}
static void Mayor()
{
while (speakMayor)
{
Clear();
drawLine();
WriteLine($"Hello there, {Name}!");
if (ATK < 10)
{
WriteLine("You're not strong enough to face the dragon yet! Keep practicing and come back later!");
IsKey = false;
}
else
{
WriteLine("You might want to take on the dragon now! Take this key but be careful with the beast!");
IsKey = true;
}
drawLine();
WriteLine("1 - LEAVE");
drawLine();
Write($"{Name}# ");
string choice = ReadLine();
if (choice == "1")
{
speakMayor = false;
}
}
}
static void Cave()
{
while (bossEnemy)
{
Clear();
drawLine();
WriteLine("Here lies the cave of the dragon. What will you do?");
drawLine();
if (IsKey)
{
WriteLine("1 - USE KEY");
}
WriteLine("2 - TURN BACK");
drawLine();
Write($"{Name}# ");
string choice = ReadLine();
if (choice == "1")
{
if (IsKey)
{
Fight = true;
Battle();
}
}
else if (choice == "2")
{
bossEnemy = false;
}
}
}
static void Main(string[] args)
{
Title = "Tensura Idle RPG";
MainGameManager();
}
static void MainGameManager()
{
Clear();
startPageInfo();
while (isRunning)
{
while (isMenu)
{
if (isRules)
{
Clear();
WriteLine(@"
This is advanture RPG game that has an ending and you can try to beat the game.
Mobs: Slime, Goblic, Orc and Final Secret Boss.
Special place on Maps: Shop, Mayor, Curve.
Items in Shop: heal Potion, upgrade ATK.");
isRules = false;
Write($"{Name}> ");
ReadLine();
continue;
}
else
{
Write($"{Name}# ");
string userInput = ReadLine();
if (int.TryParse(userInput, out choice)) { }
else
{
Clear();
startPageInfo();
continue;
}
}
switch (choice)
{
case 1:
Clear();
Write("# What's your name, hero? ");
Name = Convert.ToString(ReadLine());
isMenu = false;
isPlay = true;
break;
case 2:
try
{
// TODO: try to read and load this file in current project layer not in bin/Debug/load.txt
using (StreamReader file = new StreamReader("load.txt"))
{
string[] load_list = file.ReadToEnd().Split('\n');
// TODO: Implement reading Corrupt save file exception!
//if (load_list.Length == 9)
//{
Name = load_list[0].TrimEnd();
HP = int.Parse(load_list[1].TrimEnd());
ATK = int.Parse(load_list[2].TrimEnd());
POTION = int.Parse(load_list[3].TrimEnd());
ELIXIR = int.Parse(load_list[4].TrimEnd());
GOLD = int.Parse(load_list[5].TrimEnd());
CoordinateX = int.Parse(load_list[6].TrimEnd());
CoordinateY = int.Parse(load_list[7].TrimEnd());
IsKey = bool.Parse(load_list[8].TrimEnd());
Clear();
WriteLine("Welcome back, " + Name + "!");
Write($"{Name}> ");
isMenu = false;
isPlay = true;
//}
//else
//{
// WriteLine("Corrupt save file!");
// Write("> "); ReadLine();
//}
}
}
catch (IOException)
{
WriteLine("No loadable save file!");
Write($"{Name}> ");
}
break;
case 3:
isRules = true;
break;
case 4:
return;
default:
Clear();
WriteLine("That Choice Doesn't Exist. Try others!");
startPageInfo();
break;
}
}
while (isPlay)
{
Save(); // autosave
Clear();
bool enemySpawn = (bool)Biom[Map[CoordinateY,CoordinateX]]["enemy"];
string mapLocation = (string)Biom[Map[CoordinateY,CoordinateX]]["text"];
if (!Standing)
{
if (enemySpawn)
{
if (random.Next(0, 100) <= 30)
{
Fight = true;
Battle();
}
}
}
if (isPlay)
{
// Player Information
drawLine();
WriteLine($"LOCATION: {mapLocation}");
drawLine();
WriteLine(
$"NAME: {Name}\n" +
$"HP: {HP}/{HPMAX}\n" +
$"ATK: {ATK} \n" +
$"POTIONS: {POTION} \n" +
$"ELIXIRS: {ELIXIR} \n" +
$"GOLD: {GOLD} "
);
drawLine();
WriteLine($"COORDINATES: {CoordinateX}, {CoordinateY}");
drawLine();
// Action button for player
WriteLine("0 - SAVE AND QUIT! ");
if ( CoordinateY > 0 ) { WriteLine("1 - NORTH"); }
if ( CoordinateX < LengthX ) { WriteLine("2 - EAST"); }
if ( CoordinateY < LengthY ){ WriteLine("3 - SOUTH"); }
if ( CoordinateX > 0 ) { WriteLine("4 - WEST"); }
if ( POTION > 0 ) { WriteLine("5 - USE POTION (30HP)"); }
if ( ELIXIR > 0 ) { WriteLine("6 - USE ELIXIR (50HP)"); }
if (Map[CoordinateY, CoordinateX] == "shop" ||
Map[CoordinateY, CoordinateX] == "mayor" ||
Map[CoordinateY, CoordinateX] == "cave" ) { WriteLine("7 - ENTER"); }
drawLine();
Write($"{Name}# ");
string Destination = Convert.ToString(ReadLine());
if (Destination == "0")
{
isPlay = false;
isMenu = true;
isRules = false;
Save();
Clear();
startPageInfo();
}
else if (Destination == "1")
{
if (CoordinateY > 0)
{
CoordinateY--;
Standing = false;
}
}
else if (Destination == "2")
{
if (CoordinateX < LengthX)
{
CoordinateX++;
Standing = false;
}
}
else if (Destination == "3")
{
if (CoordinateY < LengthY)
{
CoordinateY++;
Standing = false;
}
}
else if (Destination == "4")
{
if (CoordinateX > 0)
{
CoordinateX--;
Standing = false;
}
}
else if (Destination == "5")
{
if (POTION > 0)
{
POTION--;
Heal(amount: 30);
}
else { WriteLine("No potions!"); }
Write($"{Name}> ");
ReadLine();
Standing = true;
}
else if (Destination == "6")
{
if (ELIXIR > 0)
{
ELIXIR--;
Heal(amount: 50);
}
else { WriteLine("No elixirs!"); }
Write($"{Name}> ");
ReadLine();
Standing = true;
}
else if (Destination == "7")
{
if (Map[CoordinateY, CoordinateX] == "shop")
{
shopBuy = true;
Shop();
}
else if (Map[CoordinateY, CoordinateX] == "mayor")
{
speakMayor = true;
Mayor();
}
else if (Map[CoordinateY, CoordinateX] == "cave")
{
bossEnemy = true;
Cave();
}
}
else
{
Standing = true;
}
}
}
}
}
}
}