Changed a lot of Actions.cs and a few other things to be more easily

extendable.
This commit is contained in:
2025-09-03 23:32:20 -05:00
parent 69e6699e26
commit e4b230a0ad
21 changed files with 834 additions and 314 deletions

View File

@@ -11,34 +11,31 @@ public sealed class GameState
public List<Character> monsters = new List<Character>();
public List<Character> heroRemove = new List<Character>();
public List<Character> monsterRemove = new List<Character>();
public List<Item> heroInventory = new List<Item>();
public int currentRound = 1;
public bool gameOver = false;
public bool herosAIControl = false;
public bool monstersAIControl = true;
public bool lastRound = false;
public record MenuItem
{
string? Description;
bool IsEnabled;
IAction? ActionToPerform;
}
public void BuildMenu(Character character)
{
int number = 1;
foreach (string action in character.CharacterEnabledActions)
{
Console.WriteLine($"{number}. {action}");
number++;
}
}
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)
{
@@ -48,22 +45,52 @@ public sealed class GameState
{
foreach (Character hero in heros)
{
BeginHeroTurn:
hero.isTurn = true;
Actions.Instance.GetAction(hero);
CheckDead();
hero.isTurn = false;
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;
}
}
}
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);
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)
{
@@ -169,47 +196,52 @@ public sealed class GameState
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 to block your way to defeat their master...");
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();
monsters.AddRange(skeleton1, skeleton2);
Amarok amarok1 = new Amarok();
monsters.AddRange(skeleton1, skeleton2, amarok1);
}
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"
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!\"");
+ "\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, uncodedOne);
monsters.AddRange(skeleton1, skeleton2, skeleton3, amarok1, amarok2, 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"
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...");
+ "have helped restore...", ConsoleColor.Cyan);
Console.WriteLine("\nPress Enter to exit your final challenge, True Programmer!");
Console.ReadLine();
}
@@ -217,11 +249,11 @@ public sealed class GameState
public void MonstersWin()
{
Console.Clear();
Thread.Sleep(2000);
Console.WriteLine("You have been brutally struck down by the Uncoded One and his evil\n"
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...");
+ "\nTrue Programming may forever be lost...", ConsoleColor.Red);
Console.ReadLine();
}
}