-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameInstance.cs
1168 lines (1116 loc) · 53.5 KB
/
GameInstance.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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Sharpmon
{
public static class GameInstance
{
//FIELDS
public static Random Rng = new Random(); //The random object that every class will use when it comes to Random number generator.
public static string Choice; //The value that will be used for stocking (almost) every choices in the game, one at a time.
private static Player player; //The one and only, main player of the game.
private static string savePath = "SharpmonSave"; //The path to your future (or existing) save file of the game. Note that this is MY own path, it may not work for you.
private static UnicodeEncoding ByteConverter = new UnicodeEncoding();
//METHODS
public static void Run()
{
/*A little ASCII Art used to offer a better user experience.*/
Console.WriteLine("\t _____ _ _ ___ _______________ ________ _ _ \n" +
"\t/ ___| | | | / _ \\ | ___ \\ ___ \\ \\/ | _ | \\ | |\n" +
"\t\\ `--.| |_| |/ /_\\ \\| |_/ / |_/ / . . | | | | \\| |\n" +
"\t `--. \\ _ || _ || /| __/| |\\/| | | | | . ` |\n" +
"\t/\\__/ / | | || | | || |\\ \\| | | | | \\ \\_/ / |\\ |\n" +
"\t\\____/\\_| |_/\\_| |_/\\_| \\_\\_| \\_| |_/\\___/\\_| \\_/\n");
/*Check if a save file of our game exist at the savepath entered. If so, display a little Menu so that
the player can choose if he wants to continue his saved game or if he wants to start a new one.*/
if (File.Exists(savePath))
{
Console.WriteLine("\t\t\t0: New Game\n\t\t\t1: Continue");
while (true)
{
Choice = Console.ReadLine();
switch (Choice.ToLower())
{
case "0":
case "start":
case "new game":
case "new":
NewGame();
break;
case "1":
case "continue":
case "charge":
DeserializeItem(savePath);
PrincipalScene();
break;
default:
Console.WriteLine("Enter a valid input.");
break;
}
}
}
/*If no save file exists at the savepath entered, a new game is the only option.*/
else
{
Console.WriteLine("\t\tPress any key to start a new game");
Console.ReadKey();
NewGame();
}
}
/// <summary>
/// Method that instanciate a new player into our static player variable. Isn't called if the player is loaded.
/// </summary>
private static void NewGame()
{
Console.Clear();
Console.WriteLine(
"Greetings adventurer!\nBefore you enter the wonderful world of Sharpmon, please enter your name:");
player = new Player(Console.ReadLine());
PrincipalScene();
}
/// <summary>
/// Static method representing the fact that the player is currently into the Main Menu having plenty of choices.
/// </summary>
private static void PrincipalScene()
{
while (true)
{
/*Those few lines before the switch are mostly here to offer a better user exeperience but also to display
to the player what are his options and what is important to be known (such as his name, his sharpdollars and his main sharpmon).*/
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
Console.Write($"Name: {player.Name} \t\tSharpdollars: {player.SharpDollars}\n" +
"Current Sharpmon: ");
player.GetCurrentSharpmon().GetColorElementalType();
Console.Write($"{player.GetCurrentSharpmon().Name} ");
Console.ForegroundColor = ConsoleColor.White;
Console.Write($"level {player.GetCurrentSharpmon().GetLevel()} ({player.GetCurrentSharpmon().CurrentHp}/{player.GetCurrentSharpmon().MaxHp} Hp)\n\n");
Console.ForegroundColor = ConsoleColor.Gray;
if(player.currentTown != Sharpdex.Towns.Last())
{
Console.WriteLine($"You're currently in {player.currentTown}.\nWhere do you want to go?\n\t0: Into the wild\n\t1: Fight for the {Sharpdex.Badges[Sharpdex.Towns.IndexOf(player.currentTown)]} badge\n\t2: Change current Sharpmon\n\t3: In the shop\n" +
"\t4: In the Sharpmon Center\n\t5: Save Game\n\t6: Exit Game");
}
else
{
Console.WriteLine($"You're currently in {player.currentTown}.\nWhere do you want to go?\n\t0: Into the wild\n\t1: Fight {player.currentTown}\n\t2: Change current Sharpmon\n\t3: In the shop\n" +
"\t4: In the Sharpmon Center\n\t5: Save Game\n\t6: Exit Game");
}
Choice = Console.ReadLine().ToLower();
/*If the player enter 0 or "into the wild" he's transported to the discovering Scene that will eventually lead him to a fight.
If he chooses 1 or "arena" he'll fight for the current town's badge.
If he chooses 2 or "change" he'll be able to change his current main sharpmon.
If he chooses 3 or "in the shop", he will be transported to the Shop so that he can buy or sell items.
If he chooses 4 or "in the sharpmon center", he will be transported to the sharpmon center so that he can heal his sharpmon or simply see all of them and their current Hp/Level.
If he chooses 5, "save" or "save game", the game will be saved. It means that all the player's informations will be Serialized into a .txt file.
If he chosses 6 or "exit game", the game will instantly be shut down.
If he enters none of the above input, he will be asked to re-enter an input in hope of matching the above inputs.*/
switch (Choice)
{
case "0":
case "into the wild":
case "wild":
if(player.GetCurrentSharpmon().IsAlive())
Discovering();
break;
case "1":
case "fight the next arena":
case "arena":
if(player.GetCurrentSharpmon().IsAlive())
FightNextArena();
break;
case "2":
case "change":
ChangeCurrentSharpmon();
continue;
case "3":
case "in the shop":
case "shop":
ShopScene();
break;
case "4":
case "in the sharpmon center":
case "center":
SharpmonCenterScene();
break;
case "5":
case "save":
case "save game":
SerializeItem(savePath);
continue;
case "6":
case "exit game":
case "exit":
Environment.Exit(0);
return;
case "7":
player.GetCurrentSharpmon().SetExp(90000000);
for(int i = 0; i < 5; i++)
player.GetSharpmons().Add(Sharpmon.CopySharpmon(Sharpmon.GetRandomSharpmon(Rng.Next(Sharpdex.AllSharpmons.Count))));
player.GetCurrentSharpmon().CheckForLevelUp();
break;
default:
Console.WriteLine("Please enter a valid input.\nPress any key to continue.");
Console.ReadKey();
continue;
}
}
}
/// <summary>
/// Static method used as a substitute of a loading screen to offer
/// a better user experience but also change the range of the discoverable sharpmons
/// based on the current Sharpmon's level.
/// </summary>
private static void Discovering()
{
Console.Clear();
Console.Write("You're currently walking trought the grass");
for (int i = 0; i < Rng.Next(10, 30); i++)
{
if (i == 15)
{
Console.Clear();
Console.Write("You're currently walking trought the grass");
}
System.Threading.Thread.Sleep(100);
Console.Write(".");
}
Console.Clear();
Sharpmon Ennemy;
if (player.GetCurrentSharpmon().GetLevel() < 30)
Ennemy = Sharpmon.CopySharpmon(Sharpmon.GetRandomSharpmon(Rng.Next(Sharpdex.AllSharpmons.Count - 27))); //Allow the discovering of common Sharpmons.
else if (player.GetCurrentSharpmon().GetLevel() >= 30 && player.GetCurrentSharpmon().GetLevel() < 40)
Ennemy = Sharpmon.CopySharpmon(Sharpmon.GetRandomSharpmon(Rng.Next(Sharpdex.AllSharpmons.Count - 6))); //Allow the discovering of a possible Advanced Sharpmon.
else
Ennemy = Sharpmon.CopySharpmon(Sharpmon.GetRandomSharpmon(Rng.Next(Sharpdex.AllSharpmons.Count))); //Allow the discovering of a possible Legendary Sharpmon.
for (int i = 0; i < player.GetCurrentSharpmon().GetLevel()-1; i++)
Ennemy.OnLevelUp();
Console.Write($"A wild {Ennemy.Name} appeared!\n\nLoading battle.");
Loading(150, 10);
FightScene(Ennemy);
}
/// <summary>
/// Static method representing the fact that the player is currently against a specific sharpmon.
/// From there he can choose what to do next.
/// </summary>
private static void FightScene(Sharpmon ennemy, bool arenaFight = false)
{
while (true)
{
Console.Clear();
ennemy.DrawTable();
player.GetCurrentSharpmon().DrawTable();
Console.WriteLine("\n\t\t\tWhat will you do?\n\t\t\t\t0: Attack\n\t\t\t\t1: Change Sharpmon\n\t\t\t\t2: Use item\n\t\t\t\t3: Capture\n\t\t\t\t4: Run away");
Choice = Console.ReadLine().ToLower();
switch (Choice)
{
case "0":
case "attack":
FightSystem(player.GetCurrentSharpmon(), ennemy, arenaFight);
return;
case "1":
case "change sharpmon":
ChangeSystem(ennemy, arenaFight);
return;
case "2":
case "use item":
ItemSystem(ennemy, arenaFight);
return;
case "3":
case "capture":
if (!arenaFight)
{
if(player.GetSharpmons().Count < 6)
{
Console.WriteLine($"You threw a Sharpball at {ennemy.Name}!");
CaptureSystem(player.GetCurrentSharpmon(), ennemy);
}
else
{
Console.WriteLine("You can't capture more sharpmons unless you put some into your PC! (in the Sharpmon Center)\nPress a key to continue the fight.");
Console.ReadKey();
continue;
}
}
else
{
Console.WriteLine("You can't capture someone's sharpmon!\nPress a key to continue the fight.");
Console.ReadKey();
continue;
}
return;
case "4":
case "run away":
if (!arenaFight)
{
EscapeSystem(player.GetCurrentSharpmon(), ennemy);
return;
}
else
{
Console.WriteLine("You can't flee from an arena fight until all your sharpmons are KO!\nPress a key to continue the fight.");
Console.ReadKey();
continue;
}
default:
Console.WriteLine("Please enter a valid input.\nPress a key to continue the fight.");
Console.ReadKey();
continue;
}
}
}
private static void FightNextArena()
{
Console.Clear();
Sharpmon Ennemy = Sharpdex.ArenaSharpmons.ElementAt(Sharpdex.Towns.IndexOf(player.currentTown)).Key;
for (int i = 0; i < Sharpdex.ArenaSharpmons.ElementAt(Sharpdex.Towns.IndexOf(player.currentTown)).Value - 1; i++)
Ennemy.OnLevelUp();
Console.Write($"The gym leader accepted your challenge with his");
Ennemy.ToString();
Console.Write("!\n\nPrepare yourself.");
Loading(150, 10);
FightScene(Ennemy, true);
}
/// <summary>
/// Static method representing the fact that the player is currently in the shop.
/// From there he can choose what to do next.
/// </summary>
private static void ShopScene()
{
while (true)
{
Console.Clear();
Console.WriteLine("Welcome to the SharpShop!\nWhat do you want to do?\n\t0: Buy items\n\t1: Sell items\n\t2: Exit the shop");
Choice = Console.ReadLine().ToLower();
switch (Choice)
{
case "0":
case "buy":
case "buy item":
BuyShop();
break;
case "1":
case "sell":
case "sell item":
SellShop();
break;
case "2":
case "exit":
case "exit shop":
Console.Write("Heading back to town");
Loading(100, 10);
return;
default:
Console.WriteLine("Please enter a valid input.\nPress any key to continue.");
Console.ReadKey();
continue;
}
}
}
/// <summary>
/// Static method representing the fact that the player is currently into the Sharpmon Center.
/// From there he can choose what to do next.
/// </summary>
private static void SharpmonCenterScene()
{
while (true)
{
Console.Clear();
Console.WriteLine("Welcome in the Sharpmon Center! Do you want to heal all your sharpmons or exit the center?\n\t0: Heal all the sharpmons");
player.GetSharpmons().ForEach(sharpmon => Console.WriteLine($"\t\t{sharpmon.Name} (Level {sharpmon.GetLevel()}): {sharpmon.CurrentHp}/{sharpmon.MaxHp}"));
Console.WriteLine("\n\t1: Launch your PC\n\t2: Exit center");
Choice = Console.ReadLine().ToLower();
switch (Choice)
{
case "0":
case "heal":
case "heal all the sharpmons":
player.GetSharpmons().ForEach(sharpmon => sharpmon.CurrentHp = sharpmon.MaxHp);
Console.Clear();
Console.Write("All your Sharpmons have been healed!\nYou're now exiting the center.\nExiting the center.");
Loading(200, 10);
return;
case "1":
case "pc":
Console.Write("Launching your PC.");
Loading(100, 10);
LaunchPC();
continue;
case "2":
case "exit center":
Console.Write("Exiting the center.");
Loading(100, 10);
return;
default:
continue;
}
}
}
private static void LaunchPC()
{
while (true)
{
Console.Clear();
Console.WriteLine("You're logged into your PC!\nDo you want to store your sharpmons, take one or log out?\n\t0: Store a sharpmon\n\t1: Take a sharpmon\n\t2: Log out");
Choice = Console.ReadLine().ToLower();
switch (Choice)
{
case "0":
case "store":
StoreInPC();
continue;
case "1":
case "take":
TakeFromPC();
continue;
case "2":
case "log off":
return;
default:
continue;
}
}
}
private static void StoreInPC()
{
Console.WriteLine("Choose a Sharpmon to store in your PC:");
for (int i = 0; i < player.GetSharpmons().Count; i++)
{
player.GetSharpmons()[i].GetColorElementalType();
Console.WriteLine($"\t\t{i}: {player.GetSharpmons()[i].Name} (Hp: {player.GetSharpmons()[i].CurrentHp}/{player.GetSharpmons()[i].MaxHp})");
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.WriteLine($"\n\tEnter: Return to the PC's menu");
int parsedChoice;
while (true)
{
Choice = Console.ReadLine();
if (int.TryParse(Choice, out parsedChoice) && parsedChoice >= 0 && parsedChoice < player.GetSharpmons().Count)
{
if(player.GetSharpmons().Count > 1)
{
Console.Write("Placing");
player.GetSharpmons()[parsedChoice].ToString();
Console.WriteLine("in your PC.");
player.AddSharpmonInPC(player.GetSharpmons()[parsedChoice]);
player.GetSharpmons().RemoveAt(parsedChoice);
Loading(150, 5);
return;
}
else
{
Console.WriteLine("You can't store your last sharpmon.\nPress any key to return to the PC's menu");
Console.ReadKey();
return;
}
}
else if(Choice == "")
{
return;
}
else
{
Console.WriteLine("Enter a valid input.");
}
}
}
private static void TakeFromPC()
{
int page = 1;
int pageMax = (int)Math.Ceiling(player.GetSharpmonsInPC().Count/8f);
int parsedChoice;
while (true)
{
Console.Clear();
Console.WriteLine($"Choose a Sharpmon from your PC:\t(Page {page}/{pageMax})");
for (int i = (page-1)*8; i < ((page < pageMax) ? page*8: ((page-1)*8)+player.GetSharpmonsInPC().Count%8); i++)
{
player.GetSharpmonsInPC()[i].GetColorElementalType();
Console.WriteLine($"\t\t{i-((page-1)*8)}: {player.GetSharpmonsInPC()[i].Name} (Hp: {player.GetSharpmonsInPC()[i].CurrentHp}/{player.GetSharpmonsInPC()[i].MaxHp})");
Console.ForegroundColor = ConsoleColor.Gray;
}
if(page < pageMax)
{
Console.Write($"\t8: Next page");
}
if(page > 1)
{
Console.Write($"\n\t9 Previous page");
}
Console.WriteLine("\n\tEnter: Return to the PC's menu");
Choice = Console.ReadLine();
if(int.TryParse(Choice, out parsedChoice))
{
if (parsedChoice >= 0 && parsedChoice < player.GetSharpmonsInPC().Count%8)
{
if(player.GetSharpmons().Count < 6)
{
Console.Write("Placing");
player.GetSharpmonsInPC()[(page-1)*8+parsedChoice].ToString();
Console.WriteLine("in your inventory.");
player.GetSharpmons().Add((player.GetSharpmonsInPC()[(page-1)*8+parsedChoice]));
player.GetSharpmonsInPC().RemoveAt((page-1)*8+parsedChoice);
Loading(200, 5);
return;
}
else
{
Console.WriteLine("You already have the maximum number of sharpmons in your inventory.\nReturning to the PC's menu.");
Loading(300, 9);
return;
}
}
else if(parsedChoice == 8 && page < pageMax)
{
page++;
continue;
}
else if(parsedChoice == 9 && page > 1)
{
page--;
continue;
}
}
else if(Choice == "")
{
return;
}
}
}
/// <summary>
/// Method to draw the sharpmon's stat table in the color of its element.
/// </summary>
/// <param name="entity"></param>
private static void DrawTable(this Sharpmon entity)
{
entity.GetColorElementalType();
Console.WriteLine($"\t _______________________________________________\n" +
$"\t|\t{entity.Name} Level {entity.GetLevel()}: \tHp: {entity.CurrentHp}/{entity.MaxHp} \t|\n" +
$"\t|\tPow: {entity.CurrentPower} \tDef: {entity.CurrentDefense} \t\t|\n" +
$"\t|\tAcc: {entity.CurrentAccucary} \tDodge: {entity.CurrentDodge}\t\t|\n" +
$"\t|\tSpd: {entity.CurrentSpeed} \t\t\t\t|\n" +
$"\t|_______________________________________________|");
Console.ForegroundColor = ConsoleColor.White;
}
/// <summary>
/// Method used to determine who attack first and what attack does the computer.
/// Before and after every action, a check is done to see if the receiver of an attack died from it.
/// </summary>
/// <param name="currentSharpmon"></param>
/// <param name="ennemy"></param>
private static void FightSystem(Sharpmon currentSharpmon, Sharpmon ennemy, bool arenaFight = false)
{
while (true)
{
if (currentSharpmon.CurrentSpeed > ennemy.CurrentSpeed)
{
if (currentSharpmon.IsAlive())
currentSharpmon.ChooseAttack().LaunchAttack(currentSharpmon, ennemy);
else
{
ChangeSystem(ennemy, arenaFight);
return;
}
if (ennemy.IsAlive())
ennemy.GetAttack(Rng.Next(ennemy.GetAttacks().Count)).LaunchAttack(ennemy, currentSharpmon);
else
{
currentSharpmon.Win(ennemy, arenaFight);
return;
}
if (!currentSharpmon.IsAlive())
{
ChangeSystem(ennemy, arenaFight);
return;
}
EndTurn(ennemy, arenaFight);
return;
}
else if (currentSharpmon.CurrentSpeed < ennemy.CurrentSpeed)
{
Attack tempAttack = currentSharpmon.ChooseAttack();
if (ennemy.IsAlive())
ennemy.GetAttack(Rng.Next(ennemy.GetAttacks().Count)).LaunchAttack(ennemy, currentSharpmon);
else
{
currentSharpmon.Win(ennemy, arenaFight);
return;
}
if (currentSharpmon.IsAlive())
tempAttack.LaunchAttack(currentSharpmon, ennemy);
else
{
ChangeSystem(ennemy, arenaFight);
return;
}
if(!ennemy.IsAlive())
{
currentSharpmon.Win(ennemy, arenaFight);
return;
}
EndTurn(ennemy, arenaFight);
return;
}
else if (currentSharpmon.CurrentSpeed == ennemy.CurrentSpeed)
{
Attack tempAttack = currentSharpmon.ChooseAttack();
if (Rng.Next(2) == 1)
{
if (ennemy.IsAlive())
ennemy.GetAttack(Rng.Next(ennemy.GetAttacks().Count)).LaunchAttack(ennemy, currentSharpmon);
else
{
currentSharpmon.Win(ennemy, arenaFight);
return;
}
if (currentSharpmon.IsAlive())
tempAttack.LaunchAttack(currentSharpmon, ennemy);
else
{
ChangeSystem(ennemy, arenaFight);
return;
}
if (!ennemy.IsAlive())
{
currentSharpmon.Win(ennemy, arenaFight);
return;
}
EndTurn(ennemy, arenaFight);
return;
}
else
{
if (currentSharpmon.IsAlive())
tempAttack.LaunchAttack(currentSharpmon, ennemy);
else
{
ChangeSystem(ennemy, arenaFight);
return;
}
if (ennemy.IsAlive())
ennemy.GetAttack(Rng.Next(ennemy.GetAttacks().Count)).LaunchAttack(ennemy, currentSharpmon);
else
{
currentSharpmon.Win(ennemy, arenaFight);
return;
}
if (!currentSharpmon.IsAlive())
{
ChangeSystem(ennemy, arenaFight);
return;
}
EndTurn(ennemy, arenaFight);
return;
}
}
}
}
/// <summary>
/// Method that allows the user to choose the attack of its sharpmon he wants to use.
/// </summary>
/// <param name="currentSharpmon"></param>
/// <param name="ennemy"></param>
private static Attack ChooseAttack(this Sharpmon currentSharpmon)
{
Console.WriteLine($"Choose your attack:");
for (int i = 0; i < currentSharpmon.GetAttacks().Count; i++)
Console.WriteLine($"\t {i}: {currentSharpmon.GetAttack(i).GetName()}");
while (true)
{
Choice = Console.ReadLine().ToLower();
for (int i = 0; i < currentSharpmon.GetAttacks().Count; i++)
{
if (Choice == currentSharpmon.GetAttack(i).GetName().ToLower() || Choice == $"{i}")
{
return currentSharpmon.GetAttack(i);
}
}
Console.WriteLine("Please entere a valid index or name.");
}
}
/// <summary>
/// Method that tells the user that the current turn has ended. It automaticly begins a new one.
/// </summary>
/// <param name="ennemy"></param>
private static void EndTurn(Sharpmon ennemy, bool arenaFight = false)
{
Console.WriteLine("Both Sharpmon attacked, press any key to continue the fight.");
Console.ReadKey();
FightScene(ennemy, arenaFight);
return;
}
/// <summary>
/// Method that displays to the player how much experience and sharpdollars his current sharpmon
/// and himself won with this fight. It sign the end of the fight and allow the user to return to
/// the principal scene.
/// </summary>
/// <param name="currentSharpmon"></param>
/// <param name="ennemy"></param>
private static void Win(this Sharpmon currentSharpmon, Sharpmon ennemy, bool arenaFight = false)
{
Console.WriteLine($"{ennemy.Name} fainted.\nPress any key to continue.");
Console.ReadKey();
Console.Clear();
int temp = (arenaFight) ? Rng.Next(50, 70) * ennemy.GetLevel() : Rng.Next(120, 150) * ennemy.GetLevel();
currentSharpmon.CurrentExperience += temp;
Console.WriteLine($"Your {currentSharpmon.Name} won {temp} experience points!");
if(!arenaFight)
{
temp = Rng.Next(50, 100);
player.SharpDollars += temp;
Console.Write($"You won {temp} SharpDollars!\nHeading back to town");
Loading(150, 15);
}
else
{
if(player.currentTown != Sharpdex.Towns.Last())
{
temp = Rng.Next(2000);
player.SharpDollars += temp;
Console.Write($"You defeated the gym leader and earned the {Sharpdex.Badges[Sharpdex.Towns.IndexOf(player.currentTown)]} Badge!\nThe gym leader also gave you {temp} SharpDollars!\nHeading to {Sharpdex.Towns[Sharpdex.Towns.IndexOf(player.currentTown)+1]}");
player.currentTown = Sharpdex.Towns[Sharpdex.Towns.IndexOf(player.currentTown)+1];
Loading(300, 15);
}
else
{
temp = Rng.Next(3000, 6000);
player.SharpDollars += temp;
Console.Write($"You defeated {player.currentTown} and acquired the title of Sharpmons' Champion Badge!\nThe eliter four also gave you {temp} SharpDollars to congratulate you!\nHeading back to {player.currentTown}.");
Loading(300, 20);
}
}
currentSharpmon.CheckForLevelUp();
CheckEmptyInventory();
return;
}
private static void ChangeCurrentSharpmon()
{
string choice;
int ParsedChoice;
while (true)
{
Console.WriteLine("Choose which one of your sharpmon you want as your current one:");
for (int i = 0; i < player.GetSharpmons().Count; i++)
{
player.GetSharpmons()[i].GetColorElementalType();
Console.WriteLine($"\t\t{i}: {player.GetSharpmons()[i].Name} (Hp: {player.GetSharpmons()[i].CurrentHp}/{player.GetSharpmons()[i].MaxHp})");
Console.ForegroundColor = ConsoleColor.Gray;
}
choice = Console.ReadLine();
if (int.TryParse(choice, out ParsedChoice) && ParsedChoice >= 0 && ParsedChoice < player.GetSharpmons().Count)
{
Sharpmon TemporarySharpmon = player.GetCurrentSharpmon();
player.GetSharpmons()[0] = player.GetSharpmons()[ParsedChoice];
player.GetSharpmons()[ParsedChoice] = TemporarySharpmon;
return;
}
else
Console.WriteLine("Please enter a valid input.");
}
}
/// <summary>
/// Method that changes (or not) the current sharpmon to another one in the player's sharpmon list.
/// </summary>
/// <param name="ennemy"></param>
private static void ChangeSystem(Sharpmon ennemy, bool arenaFight = false)
{
Console.WriteLine("You current Sharpmon fainted!");
string choice;
int ParsedChoice;
while (true)
{
Console.WriteLine("Choose a Sharpmon:");
for (int i = 0; i < player.GetSharpmons().Count; i++)
{
player.GetSharpmons()[i].GetColorElementalType();
Console.WriteLine($"\t\t{i}: {player.GetSharpmons()[i].Name} (Hp: {player.GetSharpmons()[i].CurrentHp}/{player.GetSharpmons()[i].MaxHp})");
Console.ForegroundColor = ConsoleColor.White;
}
Console.WriteLine($"\n\t{player.GetSharpmons().Count}: Continue the fight with current the Sharpmon\n\t{player.GetSharpmons().Count + 1}: Leave the fight");
choice = Console.ReadLine();
if (int.TryParse(choice, out ParsedChoice) && ParsedChoice > 0 && ParsedChoice < player.GetSharpmons().Count)
{
if (player.GetSharpmons()[ParsedChoice].IsAlive())
{
Sharpmon TemporarySharpmon = player.GetCurrentSharpmon();
player.GetSharpmons()[0] = player.GetSharpmons()[ParsedChoice];
player.GetSharpmons()[ParsedChoice] = TemporarySharpmon;
Console.WriteLine($"I choose you {player.GetCurrentSharpmon().Name}!");
Loading(350, 3);
FightScene(ennemy, arenaFight);
return;
}
else
{
Console.WriteLine("You can't choose this sharpmon because he's KO.");
continue;
}
}
else if (int.TryParse(choice, out ParsedChoice) &&(ParsedChoice == player.GetSharpmons().Count || ParsedChoice == 0))
{
if (!player.GetCurrentSharpmon().IsAlive())
{
Console.Write("Your current Sharpmon is KO.");
continue;
}
else
{
FightScene(ennemy, arenaFight);
return;
}
}
else if (int.TryParse(choice, out ParsedChoice) && ParsedChoice == player.GetSharpmons().Count + 1)
{
if(player.GetSharpmons().Where(sharpmon => sharpmon.CurrentHp > 0).Any())
{
Console.WriteLine("You can't run away from a fight if any of your sharpmon is alive!");
continue;
}
else
{
Console.Write("You fled the fight.\nHeading back to town");
Loading(150,10);
return;
}
}
else
Console.WriteLine("Please enter a valid input.");
}
}
/// <summary>
/// Method that allows the use of items in fight.
/// </summary>
/// <param name="ennemy"></param>
private static void ItemSystem(Sharpmon ennemy, bool arenaFight = false)
{
if (!player.GetItems().Any())
{
Console.WriteLine("Your inventory is empty.\nPress any key to return to the fight.");
Console.ReadKey();
FightScene(ennemy, arenaFight);
return;
}
else
{
Inventory();
Console.Write("Enter the name of the item you want to use: (Press enter to return to the fight)");
string choice;
string tempChoice;
int hiddenCount = 0;
int ParsedChoice = 0;
while (true)
{
choice = Console.ReadLine();
if (Item.ContainItem(choice, player.GetItems()))
{
Console.WriteLine("On which Sharpmon do you want to use it?");
foreach (Sharpmon sharpmon in player.GetSharpmons())
{
Console.WriteLine($"\t{hiddenCount}: {sharpmon.Name} (Level {sharpmon.GetLevel()}): {sharpmon.CurrentHp} /{sharpmon.MaxHp}");
hiddenCount++;
}
while (true)
{
tempChoice = Console.ReadLine();
if (int.TryParse(tempChoice, out ParsedChoice) && (ParsedChoice >= 0 && ParsedChoice < player.GetSharpmons().Count))
{
/*Use the selected item on the selected sharpmon (if the usage is needed in case of potions).
The item is destroyed after the usage.*/
if(player.GetItems()[player.GetItems().IndexOf(Item.GetItem(choice, player.GetItems()))].Use(player.GetSharpmons()[ParsedChoice], ennemy))
{
player.GetItems().RemoveAt(player.GetItems().IndexOf(Item.GetItem(choice, player.GetItems())));
/*The ennemy always execute an attack after the usage of an item.*/
ennemy.GetAttack(Rng.Next(2)).LaunchAttack(ennemy, player.GetCurrentSharpmon());
if (!player.GetCurrentSharpmon().IsAlive())
{
ChangeSystem(ennemy, arenaFight);
return;
}
else
{
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
FightScene(ennemy, arenaFight);
return;
}
}
else
break;
}
else
Console.WriteLine("Please enter a valid Sharpmon name.");
}
}
else if (choice == "")
{
FightScene(ennemy, arenaFight);
return;
}
else
Console.WriteLine("Please enter a valid name.");
}
}
}
/// <summary>
/// Method that allows the capture of a sharpmon (it does a full copy of the ennemy if successfull).
/// </summary>
/// <param name="CurrentSharpmon"></param>
/// <param name="ennemy"></param>
private static void CaptureSystem(Sharpmon CurrentSharpmon, Sharpmon ennemy)
{
Console.Write("Capturing .");
double CaptureSuccess = (double)(3 * ennemy.MaxHp - 2 * ennemy.CurrentHp) / (3 * ennemy.MaxHp);
if (Rng.Next(101) <= CaptureSuccess * 100)
{
Loading(200, 8);
player.AddSharpmon(ennemy);
Console.WriteLine($"\nYou captured a {ennemy.Name}!");
Console.Write($"Heading back to town.");
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(150);
Console.Write(".");
}
return;
}
else
{
Loading(200, Functions.Choose(2, 4, 6));
Console.WriteLine($"\n{ennemy.Name} broke free!");
ennemy.GetAttack(Rng.Next(2)).LaunchAttack(ennemy, CurrentSharpmon);
if (!CurrentSharpmon.IsAlive())
{
Console.WriteLine("You current Sharpmon fainted!");
ChangeSystem(ennemy);
return;
}
else
{
Console.WriteLine("The turn has ended. Press any key to continue.");
Console.ReadKey();
FightScene(ennemy);
return;
}
}
}
/// <summary>
/// Method that allow the user to run away from a fight if he wants or if he doesn't have any more sharpmon to fight.
/// If it's a success, the player return back to town.
/// </summary>
/// <param name="CurrentSharpmon"></param>
/// <param name="ennemy"></param>
private static void EscapeSystem(Sharpmon CurrentSharpmon, Sharpmon ennemy)
{
double RunAwaySuccess = (double)CurrentSharpmon.CurrentDodge / ennemy.CurrentDodge;
if (Rng.Next(101) <= RunAwaySuccess*100)
{
Console.WriteLine("You fled successfully.\nHeading back to the city");
Console.Write("You're currently walking trought the grass");
Loading(150, Rng.Next(10, 15));
return;
}
else
{
Console.WriteLine("You failed your escape.");
ennemy.GetAttack(Rng.Next(2)).LaunchAttack(ennemy, player.GetCurrentSharpmon());
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
FightScene(ennemy);
return;
}
}
/// <summary>
/// Display dynamically all the item in the player inventory.
/// </summary>
private static void Inventory()
{
Console.WriteLine("Your inventory contains:");
foreach (Item item in Sharpdex.AllItems)
{
if (Item.ContainItem(item.GetName(), player.GetItems()))
Console.WriteLine($"{item.GetName()} \tx{Item.GetNumberOfItem(item.GetName(), player.GetItems())}\t|{item.GetDescription()}");
}
}
/// <summary>
/// Check if the player's list of item (so his inventory) is empty. If so, it clears the list to set the .Count() back to Zero. (Remove let it at 1 even tho everything is removed)
/// </summary>
private static void CheckEmptyInventory()
{
int hiddenCount = 0;
foreach (Item possibeItem in Sharpdex.AllItems)
{
if (Item.ContainItem(possibeItem.GetName(), player.GetItems()))
hiddenCount++;
}
if (hiddenCount == 0)
player.GetItems().Clear();
}
/// <summary>
/// Method that allows the user to buy items and put them in its inventory (list of items).
/// </summary>
private static void BuyShop()
{
Console.Clear();