Files
FinalBattle/GameState.cs

211 lines
7.2 KiB
C#

public sealed class GameState
{
public static readonly Lazy<GameState> _instance = new Lazy<GameState>(() => new GameState());
private GameState() {}
public static GameState Instance
{
get {return _instance.Value;}
}
public List<Character> heros = new List<Character>();
public List<Character> monsters = new List<Character>();
public List<Character> heroRemove = new List<Character>();
public List<Character> monsterRemove = new List<Character>();
public int currentRound = 1;
public bool gameOver = false;
public bool herosAIControl = false;
public bool monstersAIControl = true;
public bool lastRound = false;
public void Run()
{
Rounds(currentRound);
while (gameOver == false)
{
GameOver();
if (gameOver == true)
{
return;
}
if (heros.Any())
{
foreach (Character hero in heros)
{
hero.isTurn = true;
Actions.Instance.GetAction(hero);
CheckDead();
hero.isTurn = false;
}
}
foreach (Character monster in monsterRemove)
{
monsters.Remove(monster);
}
if (monsters.Any() && heros.Any())
{
foreach (Character monster in monsters)
{
monster.isTurn = true;
Actions.Instance.GetAction(monster);
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();
Console.WriteLine("You are victorious in your first battle!");
Thread.Sleep(2000);
Console.WriteLine("\nAs you make your way deeper into the Uncoded One's fortress"
+ "\nmore enemies appear, blocking your way forward to defeat their master...");
Console.WriteLine("\n\nPress Enter to continue...");
Console.ReadLine();
Skeleton skeleton1 = new Skeleton();
Skeleton skeleton2 = new Skeleton();
monsters.AddRange(skeleton1, skeleton2);
}
if (currentRound == 3)
{
Console.Clear();
Console.WriteLine("You have completed the second battle in your assualt on the"
+ " Uncoded One's fortress!");
Thread.Sleep(2000);
Console.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!\"");
Console.WriteLine("\n\nPress Enter to continue...");
Console.ReadLine();
Skeleton skeleton1 = new Skeleton();
Skeleton skeleton2 = new Skeleton();
Skeleton skeleton3 = new Skeleton();
UncodedOne uncodedOne = new UncodedOne();
monsters.AddRange(skeleton1, skeleton2, skeleton3, uncodedOne);
}
}
public void HerosWin()
{
Console.Clear();
Thread.Sleep(2000);
Console.WriteLine("As you strike the Uncoded One down, the sky brightens and the"
+ " miasma\nsurrounding his dark fortress begins to lift...\n\n"
+ "You are victorious!\n\nTrue Programming has been restored to the lands, and"
+ " the people\ncan now improve their lives through the various arts of code you\n"
+ "have helped restore...");
Console.WriteLine("\nPress Enter to exit your final challenge, True Programmer!");
Console.ReadLine();
}
public void MonstersWin()
{
Console.Clear();
Thread.Sleep(2000);
Console.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...");
Console.ReadLine();
}
}