public sealed class GameState { public static readonly Lazy _instance = new Lazy(() => new GameState()); private GameState() {} public static GameState Instance { get {return _instance.Value;} } public List heros = new List(); public List monsters = new List(); public List heroRemove = new List(); public List monsterRemove = new List(); public List heroInventory = new List(); public int currentRound = 1; public bool gameOver = false; public bool herosAIControl = false; public bool monstersAIControl = true; public bool lastRound = false; public int heroPotionsAvailable = 5; public int monsterPotionsAvailable = 2; public bool BowIsEquippedBy = false; public bool SwordIsEquippedBy = false; //Menu menu = new Menu(); public void Run() { Sword heroSword = new Sword(); Bow bow = new Bow(); VinFletcher vin = new VinFletcher(); heroInventory.Add(heroSword); heroInventory.Add(bow); heros.Add(vin); Rounds(currentRound); while (gameOver == false) { int action; GameOver(); if (gameOver == true) { return; } if (heros.Any()) { foreach (Character hero in heros) { BeginHeroTurn: hero.isTurn = true; Console.Clear(); DisplayStatus(); if (GameState.Instance.herosAIControl == false) { Menu.BuildMenu(hero); } action = Actions.Instance.GetAction(hero); bool actionPerformed = Actions.Instance.DoAction(hero, action); if (actionPerformed == true) { Console.Clear(); DisplayStatus(); CheckDead(); foreach (Character monster in monsterRemove) { monsters.Remove(monster); } hero.isTurn = false; } else { goto BeginHeroTurn; } if (!monsters.Any()) { break; } } } if (monsters.Any() && heros.Any()) { foreach (Character monster in monsters) { monster.isTurn = true; Console.Clear(); DisplayStatus(); if (GameState.Instance.monstersAIControl == false) { Menu.BuildMenu(monster); } action = Actions.Instance.GetAction(monster); Actions.Instance.DoAction(monster, action); Console.Clear(); DisplayStatus(); CheckDead(); foreach (Character hero in heroRemove) { heros.Remove(hero); } if (!heros.Any()) { break; } monster.isTurn = false; } } } } public void DisplayStatus() { Console.WriteLine("================================= BATTLE ================================="); foreach (Character hero in GameState.Instance.heros) { if (hero.isTurn == true) { Console.ForegroundColor = ConsoleColor.Cyan; } Console.WriteLine($"{hero.name, -20} HP: {hero.currentHP}/{hero.maxHP}"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("----------------------------------- VS -----------------------------------"); } foreach (Character monster in GameState.Instance.monsters) { if (monster.isTurn == true) { Console.ForegroundColor = ConsoleColor.Red; } if (monster.name == "The Uncoded One") { Console.WriteLine($"{monster.name, 59} HP: {monster.currentHP, 2}/{monster.maxHP, -2}"); Console.ForegroundColor = ConsoleColor.White; } else { Console.WriteLine($"{monster.name, 59} HP: {monster.currentHP}/{monster.maxHP, -2}"); Console.ForegroundColor = ConsoleColor.White; } } } public void CheckDead() { foreach (Character hero in heros) { if (hero.currentHP <= 0) { hero.dead = true; heroRemove.Add(hero); } } foreach (Character monster in monsters) { if (monster.currentHP <= 0) { monster.dead = true; monsterRemove.Add(monster); } } } public void GameOver() { if (currentRound == 3) { lastRound = true; } if (!heros.Any()) { gameOver = true; MonstersWin(); return; } if (!monsters.Any() && lastRound == false) { currentRound++; Console.WriteLine($"Round {currentRound}"); Rounds(currentRound); return; } if (!monsters.Any() && lastRound == true) { gameOver = true; HerosWin(); return; } } public void Rounds(int currentRound) { if (currentRound == 1) { Skeleton skeleton1 = new Skeleton(); monsters.Add(skeleton1); } if (currentRound == 2) { Console.Clear(); ColoredConsole.WriteLine("You are victorious in your first battle!", ConsoleColor.Green); Thread.Sleep(1500); ColoredConsole.WriteLine("\nAs you make your way deeper into the Uncoded One's fortress" + "\nmore enemies appear to block your way to defeat their master...", ConsoleColor.Cyan); Console.WriteLine("\n\nPress Enter to continue..."); Console.ReadLine(); Skeleton skeleton1 = new Skeleton(); Skeleton skeleton2 = new Skeleton(); Amarok amarok1 = new Amarok(); monsters.AddRange(skeleton1, skeleton2, amarok1); } if (currentRound == 3) { Console.Clear(); ColoredConsole.WriteLine("You have completed the second battle in your assualt on the" + " Uncoded One's fortress!", ConsoleColor.Green); Thread.Sleep(1500); ColoredConsole.WriteLine("\nAs you move deeper into the fortress, you come upon two great" + "\nsteel doors set into a wall of stone. You push open the doors, and" + "\nfind yourself in the Uncoded One's throne room. The Uncoded One stands" + "\nfrom his throne of blackened steel and hisses, \"You have finally" + "\nappeared before me True Programmer. Now you will die, and the world" + "\nwill be mine!\"", ConsoleColor.Cyan); Console.WriteLine("\n\nPress Enter to continue..."); Console.ReadLine(); Amarok amarok1 = new Amarok(); Amarok amarok2 = new Amarok(); Skeleton skeleton1 = new Skeleton(); Skeleton skeleton2 = new Skeleton(); Skeleton skeleton3 = new Skeleton(); UncodedOne uncodedOne = new UncodedOne(); monsters.AddRange(skeleton1, skeleton2, skeleton3, amarok1, amarok2, uncodedOne); } } public void HerosWin() { Console.Clear(); Thread.Sleep(1500); ColoredConsole.WriteLine("As you strike the Uncoded One down, the sky brightens and the" + " miasma\nsurrounding his dark fortress begins to lift...\n\n", ConsoleColor.Cyan); ColoredConsole.Write("You are ", ConsoleColor.Cyan); ColoredConsole.WriteLine("VICTORIOUS!\n\n", ConsoleColor.Green); ColoredConsole.WriteLine("True Programming has been brough back to the lands, and" + " the people\ncan now improve their lives through the various arts of code you\n" + "have helped restore...", ConsoleColor.Cyan); Console.WriteLine("\nPress Enter to exit your final challenge, True Programmer!"); Console.ReadLine(); } public void MonstersWin() { Console.Clear(); Thread.Sleep(1500); ColoredConsole.WriteLine("You have been brutally struck down by the Uncoded One and his evil\n" + "minions. This is a devastating loss for the all the people whom you have helped...\n" + "The Uncoded One will now reign supreme in unchecked war against the entire land, and\n" + "\nTrue Programming may forever be lost...", ConsoleColor.Red); Console.ReadLine(); } }