diff --git a/Actions.cs b/Actions.cs index e6fa6f8..56f2a2e 100644 --- a/Actions.cs +++ b/Actions.cs @@ -1,291 +1,557 @@ public interface IAction { - void GetAction(Character character); - void DoNothing(Character character); - void Attack(); - void HealthPotion(); - Item Items(); + void DoAction(Character character, Action action); } -public sealed class Actions : IAction +public sealed class Actions { - private static readonly Lazy _instance = new Lazy(() => new Actions()); - private Actions() { } + + public static readonly Lazy _instance = new Lazy (() => new Actions()); + private Actions() {} public static Actions Instance { - get { return _instance.Value; } + get {return _instance.Value;} } - public void GetAction(Character character) + public int GetAction(Character character) { - switch (MenuItem.Description) + if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == false) { - - default: - } - - while (true) - { - var type = character.GetType().ToString(); - switch (type) + int input; + while (true) { - case "Player": PlayerActions(character); break; - case "Skeleton": MonsterActions(character); break; - case "UncodedOne": MonsterActions(character); break; - default: + try + { + input = Int32.Parse(ColoredConsole.Prompt("Select an action")); + } + catch (FormatException) + { + ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + if (input <= 0 || input > character.CharacterEnabledActions.Count) + { + ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + else + { break; + } } - break; + return input - 1; } - } - - public void PlayerActions(Character character) - { - string? action; - - while (true) + else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == false) { - Console.Clear(); - GameState.Instance.DisplayStatus(); - Console.WriteLine($"Current Round: {GameState.Instance.currentRound}"); - Console.WriteLine("\n1. Do Nothing"); - Console.WriteLine("2. Punch"); - if (GameState.Instance.herosAIControl == true) + int input; + while (true) { - action = AIPickAction(); + input = Int32.Parse(ColoredConsole.Prompt("Select an action")); + if (input <= 0 || input > character.CharacterEnabledActions.Count) + { + ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + else + { + break; + } + } + return input - 1; + } + else if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == true) + { + if (character.currentHP < character.maxHP / 2) + { + Random random = new Random(); + int roll = random.Next(1, 5); + if (roll == 1) + { + return 1; + } + else + { + return 0; + } + } + return 0; + } + else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == true) + { + Random random = new Random(); + if (character.currentHP < character.maxHP / 2) + { + int roll = random.Next(1, 5); + if (roll == 1) + { + return roll; + } + else + { + while (true) + { + int notPotionAction = random.Next(0, character.CharacterEnabledActions.Count); + if (notPotionAction != 1) + { + return notPotionAction; + } + else + { + continue; + } + } + } } else { - Console.Write($"\n{character.name}, select an action: "); - action = Console.ReadLine(); + while (true) + { + int notPotionAction = random.Next(0, character.CharacterEnabledActions.Count); + if (notPotionAction != 1) + { + return notPotionAction; + } + else + { + continue; + } + } } - switch (action) - { - case "1": DoNothing(character); break; - case "2": Punch(character); break; - default: - Console.WriteLine("Sorry, you can't do that..."); - Thread.Sleep(1000); - continue; - } - break; } + else return 0; } - public void MonsterActions(Character character) + public bool DoAction(Character character, int action) { - while (true) + string actionToDo = character.CharacterEnabledActions[action]; + if (actionToDo == "Do Nothing") { - string? action; - Console.Clear(); - GameState.Instance.DisplayStatus(); - Console.WriteLine($"Current Round: {GameState.Instance.currentRound}"); - if (character.name == "Skeleton") - { - Console.WriteLine("\n1. Do Nothing"); - Console.WriteLine("2. Bone Crunch"); - if (GameState.Instance.monstersAIControl == true) - { - action = AIPickAction(); - } - else - { - Console.Write($"\n{character.name}, select an action: "); - action = Console.ReadLine(); - } - switch (action) - { - case "1": DoNothing(character); break; - case "2": BoneCrunch(character); break; - default: - Console.WriteLine("Sorry, you can't do that..."); - Thread.Sleep(1000); - continue; - } - } - if (character.name == "The Uncoded One") - { - Console.WriteLine("\n1. Do Nothing"); - Console.WriteLine("2. Unraveling"); - if (GameState.Instance.monstersAIControl == true) - { - action = AIPickAction(); - } - else - { - Console.Write($"\n{character.name}, select and action: "); - action = Console.ReadLine(); - } - switch (action) - { - case "1": DoNothing(character); break; - case "2": Unraveling(character); break; - default: Console.WriteLine("Sorry, you can't do that..."); - Thread.Sleep(1000); - continue; - } - } - break; + DoNothing(character); + return true; } - } - - - public Character SelectTarget(Character character) - { - int target; - - while (true) + if (actionToDo == "Punch") { - if (GameState.Instance.heros.Contains(character)) - { - Console.WriteLine(); - int number = 1; - foreach (var monster in GameState.Instance.monsters) - { - Console.WriteLine($"{number}. {monster.name}"); - number++; - } - } - else if (GameState.Instance.monsters.Contains(character)) - { - int number = 1; - Console.WriteLine(); - foreach (var hero in GameState.Instance.heros) - { - Console.WriteLine($"{number}. {hero.name}"); - number++; - } - } - Console.Write("\nSelect a target: "); - try - { - target = Int32.Parse(Console.ReadLine()); - } - catch (System.FormatException) - { - Console.WriteLine("\nSorry, that's not a valid target..."); - continue; - } - try - { - if (GameState.Instance.heros.Contains(character)) - { - return GameState.Instance.monsters[target - 1]; - } - else if (GameState.Instance.monsters.Contains(character)) - { - return GameState.Instance.heros[target - 1]; - } - } - catch (System.ArgumentOutOfRangeException) - { - Console.WriteLine("\nSorry, that's not a valid target..."); - continue; - } + Punch(character); + return true; + } + if (actionToDo == "Sword Attack") + { + SwordAttack(character); + return true; + } + if (actionToDo == "Health Potion") + { + HealthPotion(character); + return true; + } + if (actionToDo == "Items") + { + bool useItem = Items(character); + return useItem; + } + if (actionToDo == "Bone Crunch") + { + BoneCrunch(character); + return true; + } + if (actionToDo == "Unraveling") + { + Unraveling(character); + return true; + } + if (actionToDo == "Bow Shot") + { + BowShot(character); + return true; + } + if (actionToDo == "Quick Shot") + { + QuickShot(character); + return true; + } + if (actionToDo == "Hero's Sword") + { + HerosSword(character); + return true; + } + if (actionToDo == "Bite") + { + Bite(character); + return true; + } + else + { + return false; } } public void DoNothing(Character character) { - - Console.WriteLine($"\n{character.name} does nothing..."); - Thread.Sleep(1000); + ColoredConsole.WriteLine($"\n{character.name} does NOTHING.", ConsoleColor.Yellow); + Thread.Sleep(1500); + return; } public void Punch(Character character) { - Character target = null; - if (GameState.Instance.herosAIControl == true) + var target = GetTarget(character); + int damage = character.damageModifier + 1 - target.damageReduction; + ColoredConsole.WriteLine($"\n{character.name} uses PUNCH!", ConsoleColor.Yellow); + if (target.name == "Amarok") { - target = AIPickTarget(character); + ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red); + } + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write("HP.", ConsoleColor.Cyan); + target.currentHP -= damage; + Thread.Sleep(1500); + return; + } + + public void SwordAttack(Character character) + { + var target = GetTarget(character); + int damage; + Random random = new Random(); + + if (character.equipedItems.Any()) + { + damage = character.damageModifier + character.equipedItems[0].ItemDamageModifier - target.damageReduction; } else { - target = SelectTarget(character); + damage = character.damageModifier - target.damageReduction; } - - Console.WriteLine($"\n{character.name} uses PUNCH on {target.name}!"); - Console.WriteLine($"{target.name} took 1 damage!"); - target.currentHP -= 1; - Thread.Sleep(1000); + ColoredConsole.WriteLine($"\n{character.name} uses SWORD ATTACK!", ConsoleColor.Yellow); + if (target.name == "Amarok") + { + ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red); + } + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write("HP.", ConsoleColor.Cyan); + target.currentHP -= damage; + Thread.Sleep(1500); return; } + public void HerosSword(Character character) + { + var target = GetTarget(character); + int damage; + Random random = new Random(); + + damage = random.Next(1, 4) + character.equipedItems[0].ItemDamageModifier - target.damageReduction; + ColoredConsole.WriteLine($"\n{character.name} uses HERO'S SWORD!", ConsoleColor.Yellow); + if (target.name == "Amarok") + { + ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red); + } + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write("HP.", ConsoleColor.Cyan); + target.currentHP -= damage; + Thread.Sleep(1500); + return; + + } + public void BoneCrunch(Character character) { - Character target = null; - if (GameState.Instance.monstersAIControl == true) - { - target = AIPickTarget(character); - } - else - { - target = SelectTarget(character); - } + var target = GetTarget(character); + int damage; + ColoredConsole.WriteLine($"\n{character.name} uses BONE CRUNCH!", ConsoleColor.Yellow); Random random = new Random(); - int coin = random.Next(1, 101); - Console.WriteLine($"\n{character.name} used Bone Crunch on {target.name}!"); - if (coin > 50) + if (character.equipedItems.Any()) { - Console.WriteLine($"{target.name} took 1 damage!"); - target.currentHP -= 1; - Thread.Sleep(1000); - return; + damage = random.Next(0, 2) + character.damageModifier + character.equipedItems[0].ItemDamageModifier - target.damageReduction; } else { - Console.WriteLine("Nothing happened!"); - Thread.Sleep(1000); - return; + damage = random.Next(0, 2) - target.damageReduction; } + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write("HP.", ConsoleColor.Cyan); + target.currentHP -= damage; + Thread.Sleep(1500); + return; + } + + public void HealthPotion(Character character) + { + if (GameState.Instance.heros.Contains(character)) + { + if (GameState.Instance.heroPotionsAvailable > 0) + { + ColoredConsole.WriteLine($"\n{character.name} uses a HEALTH POTION!", ConsoleColor.Yellow); + GameState.Instance.heroPotionsAvailable -= 1; + if (character.currentHP + 5 > character.maxHP) + { + character.currentHP = character.maxHP; + ColoredConsole.WriteLine($"{character.name}'s HP is now {character.maxHP}.", ConsoleColor.Green); + } + else + { + character.currentHP += 5; + ColoredConsole.WriteLine($"{character.name}'s HP is now {character.currentHP}.", ConsoleColor.Green); + } + Thread.Sleep(1500); + return; + } + else + { + ColoredConsole.WriteLine("There are no more potions!", ConsoleColor.Red); + return; + } + } + else + { + if (GameState.Instance.monsterPotionsAvailable > 0) + { + ColoredConsole.WriteLine($"\n{character.name} uses a HEALTH POTION!", ConsoleColor.Yellow); + GameState.Instance.monsterPotionsAvailable -= 1; + if (character.currentHP + 5 > character.maxHP) + { + character.currentHP = character.maxHP; + ColoredConsole.WriteLine($"{character.name}'s HP is now {character.maxHP}.", ConsoleColor.Green); + } + else + { + character.currentHP += 5; + ColoredConsole.WriteLine($"{character.name}'s HP is now {character.currentHP}.", ConsoleColor.Green); + } + Thread.Sleep(1500); + return; + } + else + { + ColoredConsole.WriteLine("There are no more potions!", ConsoleColor.Red); + return; + } + } + } + + public bool Items(Character character) + { + while (true) + { + Console.Clear(); + GameState.Instance.DisplayStatus(); + Menu.BuildItemsMenu(character); + Item item = GetItem(character); + if (item is null) + { + return false; + } + //Console.WriteLine(ItemDamageModifier); + if (item != null) + { + Item.EquipItem(character, item); + return true; + } + break; + } + return false; + } + + public Item? GetItem(Character character) + { + int selection; + while (true) + { + selection = Int32.Parse(ColoredConsole.Prompt("Select an item")) - 1; + if (character.equipedItems.Any() && selection == 0) + { + Item.UnequipItem(character, character.equipedItems[selection]); + return null; + } + if (!character.equipedItems.Any() && selection >= 0 && selection < GameState.Instance.heroInventory.Count) + { + break; + } + if (selection == GameState.Instance.heroInventory.Count) + { + return null; + } + else + { + ColoredConsole.WriteLine("Sorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + } + Item item = GameState.Instance.heroInventory[selection]; + return item; } public void Unraveling(Character character) { - Character target = null; - if (GameState.Instance.monstersAIControl == true) + var target = GetTarget(character); + int damage; + Random random = new Random(); + + ColoredConsole.WriteLine($"\n{character.name} uses UNRAVELING!", ConsoleColor.Yellow); + damage = random.Next(0, 6) - target.damageReduction; + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write("HP.", ConsoleColor.Cyan); + target.currentHP -= damage; + Thread.Sleep(1500); + return; + } + + public void Bite(Character character) + { + var target = GetTarget(character); + int damage; + + ColoredConsole.WriteLine($"\n{character.name} uses BITE!", ConsoleColor.Yellow); + damage = character.damageModifier + 1 - target.damageReduction; + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write("HP.", ConsoleColor.Cyan); + target.currentHP -= damage; + Thread.Sleep(1500); + return; + } + + public void BowShot(Character character) + { + var target = GetTarget(character); + int damage; + + ColoredConsole.WriteLine($"\n{character.name} uses BOW SHOT!", ConsoleColor.Yellow); + if (target.name == "Amarok") { - target = AIPickTarget(character); + ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red); + } + damage = character.equipedItems[0].ItemDamageModifier - target.damageReduction; + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write($"HP.", ConsoleColor.Cyan); + target.currentHP -= damage; + Thread.Sleep(1500); + return; + } + + public void QuickShot(Character character) + { + var target = GetTarget(character); + int damage; + Random random = new Random(); + + ColoredConsole.WriteLine($"\n{character.name} uses QUICK SHOT!", ConsoleColor.Yellow); + int roll = random.Next(1, 101); + if (roll < 50) + { + ColoredConsole.WriteLine("Nothing happened!", ConsoleColor.Yellow); + Thread.Sleep(1500); + return; } else { - target = SelectTarget(character); - } - Random random = new Random(); - Console.WriteLine($"\n{character.name} used Unraveling on {target.name}!"); - int damage = random.Next(3); - if (damage > 0) - { - Console.WriteLine($"{target.name} took {damage} damage!"); + if (target.name == "Amarok") + { + ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red); + } + damage = random.Next(2,6) - target.damageReduction; + ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan); + ColoredConsole.Write($"{damage} ", ConsoleColor.Red); + ColoredConsole.Write($"HP.", ConsoleColor.Cyan); target.currentHP -= damage; - Thread.Sleep(1000); + Thread.Sleep(1500); return; } } - public Character AIPickTarget(Character character) + public Character GetTarget(Character character) { - Random random = new Random(); - if (GameState.Instance.heros.Contains(character)) + if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == false) { - var lastItem = GameState.Instance.monsters.Count(); - var target = random.Next(1, lastItem + 1); - return GameState.Instance.monsters[target - 1]; + while (true) + { + foreach (Character monster in GameState.Instance.monsters) + { + int index = GameState.Instance.monsters.IndexOf(monster) + 1; + int indexOf = GameState.Instance.monsters.IndexOf(monster); + int indexLast = GameState.Instance.monsters.IndexOf(GameState.Instance.monsters[^1]); + Console.Write($"{index}. {monster.name}"); + if (indexOf != indexLast && index != GameState.Instance.monsters.Count()) + { + Console.Write("\n"); + } + } + try + { + int target = Int32.Parse(ColoredConsole.Prompt("\nSelect a target")); + return GameState.Instance.monsters[target - 1]; + } + catch (ArgumentOutOfRangeException) + { + ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + catch (FormatException) + { + ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + } } - else + else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == false) { - var lastItem = GameState.Instance.heros.Count(); - var target = random.Next(1, lastItem + 1); - return GameState.Instance.heros[target - 1]; + while (true) + { + foreach (Character hero in GameState.Instance.heros) + { + int index = GameState.Instance.heros.IndexOf(hero) + 1; + Console.Write($"{index}. {hero.name}"); + } + try + { + int target = Int32.Parse(ColoredConsole.Prompt("\nSelect a target")); + return GameState.Instance.heros[target - 1]; + } + catch (ArgumentOutOfRangeException) + { + ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + catch (FormatException) + { + ColoredConsole.WriteLine("\nSorry. That's not a valid input.", ConsoleColor.Red); + continue; + } + } } - } - - public string AIPickAction() - { - Random random = new Random(); - Thread.Sleep(1000); - return random.Next(1, 3).ToString(); + else if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == true) + { + while (true) + { + Random random = new Random(); + int index = random.Next(0, GameState.Instance.monsters.Count); + if (GameState.Instance.monsters.Contains(GameState.Instance.monsters[index])) + { + return GameState.Instance.monsters[index]; + } + else continue; + } + } + else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == true) + { + while (true) + { + Random random = new Random(); + int index = random.Next(0, GameState.Instance.heros.Count); + if (GameState.Instance.heros.Contains(GameState.Instance.heros[index])) + { + return GameState.Instance.heros[index]; + } + else continue; + } + } + else return GameState.Instance.heros[0]; } } - diff --git a/Amarok.cs b/Amarok.cs new file mode 100644 index 0000000..cf7731a --- /dev/null +++ b/Amarok.cs @@ -0,0 +1,11 @@ +public class Amarok : Character +{ + public Amarok() + { + maxHP = 4; + currentHP = maxHP; + name = "Amarok"; + damageReduction = 1; + CharacterEnabledActions.AddRange("Bite", "Health Potion", "Do Nothing"); + } +} diff --git a/Character.cs b/Character.cs index 5603ea6..3116303 100644 --- a/Character.cs +++ b/Character.cs @@ -4,7 +4,10 @@ public abstract class Character public int maxHP {get; set;} public int currentHP {get; set;} public bool dead {get; set;} = false; - public string turnMarker = "*"; - public bool isTurn {get; set;} = false; - public ListCharacterEnabledActions = new List(); + public bool isTurn {get; set;} + public List? CharacterEnabledActions = new List(); + public int damageReduction {get; set;} = 0; + public int damageModifier {get; set;} = 0; + public List? equipedItems = new List(); + public List? CharacterDisabledActions = new List(); } diff --git a/ColoredConsole.cs b/ColoredConsole.cs new file mode 100644 index 0000000..1be4ba3 --- /dev/null +++ b/ColoredConsole.cs @@ -0,0 +1,36 @@ +public static class ColoredConsole +{ + public static void WriteLine(string text, ConsoleColor color) + { + ConsoleColor previousColor = Console.ForegroundColor; + Console.ForegroundColor = color; + Console.WriteLine(text); + Console.ForegroundColor = previousColor; + } + + public static void Write(string text, ConsoleColor color) + { + ConsoleColor previousColor = Console.ForegroundColor; + Console.ForegroundColor = color; + Console.Write(text); + Console.ForegroundColor = previousColor; + } + + public static string Prompt(string text) + { + try + { + ConsoleColor previousColor = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Green; + Console.Write($"{text}: "); + Console.ForegroundColor = ConsoleColor.Cyan; + string input = Console.ReadLine() ?? ""; + Console.ForegroundColor = previousColor; + return input; + } + catch (FormatException) + { + throw; + } + } +} diff --git a/GameState.cs b/GameState.cs index adbbed2..0dfd382 100644 --- a/GameState.cs +++ b/GameState.cs @@ -11,34 +11,31 @@ public sealed class GameState 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 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(); } } diff --git a/Item.cs b/Item.cs new file mode 100644 index 0000000..377f632 --- /dev/null +++ b/Item.cs @@ -0,0 +1,107 @@ +public abstract class Item +{ + public string? Description {get; set;} + public int ItemDamageModifier {get; set;} = 0; + public int ItemDamageReduction {get; set;} = 0; + public string? ActionEnable {get; set;} + public string? IsEquippedBy {get; set;} + + public static void EquipItem(Character character, Item item) + { + if (character.equipedItems.Count == 0) + { + ColoredConsole.WriteLine($"{character.name} has equipped {item.Description}", ConsoleColor.Yellow); + Thread.Sleep(1500); + item.IsEquippedBy = character.name; + character.equipedItems.Insert(0, item); + GameState.Instance.heroInventory.Remove(item); + character.CharacterEnabledActions[0] = Convert.ToString(item.ActionEnable); + CheckEquipped(character, item); + } + else + { + ColoredConsole.WriteLine($"{character.name} has unequipped {character.equipedItems[0].Description}.", ConsoleColor.Yellow); + ColoredConsole.WriteLine($"{character.name} has equipped {item.Description}", ConsoleColor.Yellow); + Thread.Sleep(1500); + item.IsEquippedBy = character.name; + foreach (Item equipped in character.equipedItems) + { + GameState.Instance.heroInventory.Add(equipped); + } + character.equipedItems.Clear(); + character.equipedItems.Insert(0, item); + GameState.Instance.heroInventory.Remove(item); + character.CharacterEnabledActions[0] = Convert.ToString(item.ActionEnable); + CheckEquipped(character, item); + } + return; + } + + public static void UnequipItem(Character character, Item item) + { + ColoredConsole.WriteLine($"{character.name} has unequipped {item.Description}.", ConsoleColor.Yellow); + Thread.Sleep(1500); + GameState.Instance.heroInventory.Insert(0, item); + character.equipedItems.Clear(); + character.CharacterEnabledActions.Insert(0, "Punch"); + character.CharacterEnabledActions.Remove(item.ActionEnable); + return; + } + + public static void CheckEquipped(Character character, Item item) + { + if (character.name == "Vin Fletcher") + { + if (item.Description == "Vin's Bow") + { + character.CharacterEnabledActions[0] = "Quick Shot"; + return; + } + else return; + } + if (character.name != "Vin Fletcher") + { + if (item.Description == "Hero's Sword") + { + character.CharacterEnabledActions[0] = "Hero's Sword"; + return; + } + else return; + } + else + { + return; + } + } +} + + +public class Sword : Item +{ + public Sword() + { + Description = "Hero's Sword"; + ItemDamageModifier = 2; + ActionEnable = "Sword Attack"; + } +} + +class Armor : Item +{ + public Armor() + { + Description = "Armor"; + ItemDamageReduction = 1; + } +} + +class Bow : Item +{ + public Bow() + { + Description = "Vin's Bow"; + ItemDamageModifier = 2; + ActionEnable = "Bow Shot"; + } + +} diff --git a/Menu.cs b/Menu.cs new file mode 100644 index 0000000..91212e5 --- /dev/null +++ b/Menu.cs @@ -0,0 +1,35 @@ +public struct Menu +{ + public static void BuildMenu(Character character) + { + int index = 1; + foreach (string action in character.CharacterEnabledActions) + { + if (action == "Health Potion") + { + Console.WriteLine($"{index}. {action} ({GameState.Instance.heroPotionsAvailable})"); + } + else + { + Console.WriteLine($"{index}. {action}"); + } + index++; + } + } + + public static void BuildItemsMenu(Character character) + { + int index = 1; + if (character.equipedItems.Any()) + { + Console.WriteLine($"{index}. Unequip {character.equipedItems[0].Description}"); + index++; + } + foreach (Item item in GameState.Instance.heroInventory) + { + Console.WriteLine($"{index}. {item.Description}"); + index++; + } + Console.WriteLine($"{index}. Go back"); + } +} diff --git a/Player.cs b/Player.cs index 1df8696..b93c839 100644 --- a/Player.cs +++ b/Player.cs @@ -2,19 +2,43 @@ public class Player : Character { public Player() { - maxHP = 10; - currentHP = maxHP; name = GetName(); - CharacterEnabledActions.AddRange("Do Nothing", "Attack", "Items"); - + maxHP = 25; + currentHP = maxHP; + dead = false; + CharacterEnabledActions.AddRange("Punch", "Health Potion", "Items", "Do Nothing"); } public string GetName() { - string? input; - Console.Write("Enter your player's name: "); - input = Console.ReadLine(); - return input; + string input = null; + if (GameState.Instance.herosAIControl == false) + { + while (true) + { + try + { + input = ColoredConsole.Prompt("Enter your name"); + if (input.Length < 1) + { + ColoredConsole.WriteLine("Sorry, that isn't a valid input.", ConsoleColor.Red); + continue; + } + else + { + return input; + } + } + catch (FormatException) + { + ColoredConsole.WriteLine("Sorry, that isn't a valid input.", ConsoleColor.Red); + continue; + } + } + } + else + { + return "The True Programmer"; + } } } - diff --git a/Program.cs b/Program.cs index d3e7131..b7002fe 100644 --- a/Program.cs +++ b/Program.cs @@ -1,62 +1,56 @@ string? input; Console.Clear(); -Console.WriteLine("Welcome True Programmer, to the final battle for the realms of C#."); -Console.WriteLine("------------------------------------------------------------------"); +ColoredConsole.WriteLine("------------------------------------------------------------------", ConsoleColor.Cyan); +ColoredConsole.WriteLine("Welcome True Programmer, to the final battle for the realms of C#.", ConsoleColor.Cyan); Thread.Sleep(1000); -Console.WriteLine("\nThis will be the final battle against the Uncoded One..." - + "\nAre you ready?"); -Console.WriteLine("--------------------------------------------------------" - + "--------------"); +ColoredConsole.WriteLine("\nThis will be the final battle against the Uncoded One..." + + "\nAre you ready?", ConsoleColor.Cyan); +ColoredConsole.WriteLine("--------------------------------------------------------" + + "----------", ConsoleColor.Cyan); Console.ReadLine(); while (true) { - Console.Clear(); - Console.Write("\nWould you like the heroes party to be controlled by AI? (yes/no): "); - input = Console.ReadLine().ToLower(); - if (input == "yes" || input == "no") + try { - if (input == "yes") - { - GameState.Instance.herosAIControl = true; - } - if (input == "no") + Console.Clear(); + ColoredConsole.WriteLine("Game mode:", ConsoleColor.Green); + Console.WriteLine("\n1. Player vs Computer\n2. Player vs Player\n3. Computer vs Computer"); + ColoredConsole.WriteLine("-----------------------", ConsoleColor.Cyan); + input = ColoredConsole.Prompt("Enter a game mode"); + if (input == "1") { GameState.Instance.herosAIControl = false; - } - } - else - { - Console.WriteLine("Please answer yes or no."); - Thread.Sleep(1000); - continue; - } - break; -} -while (true) -{ - Console.Clear(); - Console.Write("\nWould you like the monsters party to be controlled by AI? (yes/no): "); - input = Console.ReadLine().ToLower(); - if (input == "yes" || input == "no") - { - if (input == "yes") - { GameState.Instance.monstersAIControl = true; + break; } - if (input == "no") + if (input == "2") { + GameState.Instance.herosAIControl = false; GameState.Instance.monstersAIControl = false; + break; } + if (input == "3") + { + GameState.Instance.herosAIControl = true; + GameState.Instance.monstersAIControl = true; + break; + } + else + { + ColoredConsole.WriteLine("Sorry. That isn't a valid input...", ConsoleColor.Red); + Thread.Sleep(1000); + continue; + } + } - else + catch (FormatException) { - Console.WriteLine("Please answer yes or no."); + ColoredConsole.WriteLine("Sorry. That isn't a valid input...", ConsoleColor.Red); Thread.Sleep(1000); continue; } - break; } Player player = new Player(); diff --git a/Skeleton.cs b/Skeleton.cs index 9692cb8..bfb911c 100644 --- a/Skeleton.cs +++ b/Skeleton.cs @@ -5,5 +5,6 @@ public class Skeleton : Character maxHP = 5; currentHP = maxHP; name = "Skeleton"; + CharacterEnabledActions.AddRange("Bone Crunch", "Health Potion", "Do Nothing"); } } diff --git a/UncodedOne.cs b/UncodedOne.cs index 09927da..dca3421 100644 --- a/UncodedOne.cs +++ b/UncodedOne.cs @@ -5,5 +5,6 @@ public class UncodedOne : Character maxHP = 15; currentHP = maxHP; name = "The Uncoded One"; + CharacterEnabledActions.AddRange("Unraveling", "Health Potion", "Do Nothing"); } } diff --git a/VinFletcher.cs b/VinFletcher.cs new file mode 100644 index 0000000..a6ba0ec --- /dev/null +++ b/VinFletcher.cs @@ -0,0 +1,10 @@ +class VinFletcher : Character +{ + public VinFletcher() + { + maxHP = 15; + currentHP = maxHP; + name = "Vin Fletcher"; + CharacterEnabledActions.AddRange("Punch", "Health Potion", "Items", "Do Nothing"); + } +} diff --git a/bin/Debug/net9.0/FinalBattle.dll b/bin/Debug/net9.0/FinalBattle.dll index 93a9422..d16aaa3 100644 Binary files a/bin/Debug/net9.0/FinalBattle.dll and b/bin/Debug/net9.0/FinalBattle.dll differ diff --git a/bin/Debug/net9.0/FinalBattle.pdb b/bin/Debug/net9.0/FinalBattle.pdb index 2c580f4..faab228 100644 Binary files a/bin/Debug/net9.0/FinalBattle.pdb and b/bin/Debug/net9.0/FinalBattle.pdb differ diff --git a/obj/Debug/net9.0/FinalBattle.AssemblyInfo.cs b/obj/Debug/net9.0/FinalBattle.AssemblyInfo.cs index 577ed91..3e48596 100644 --- a/obj/Debug/net9.0/FinalBattle.AssemblyInfo.cs +++ b/obj/Debug/net9.0/FinalBattle.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("FinalBattle")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+30793101dfbeebd38c8103f6fe11058c2add5b63")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+69e6699e26437733347c699bdfce91e200b6319c")] [assembly: System.Reflection.AssemblyProductAttribute("FinalBattle")] [assembly: System.Reflection.AssemblyTitleAttribute("FinalBattle")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net9.0/FinalBattle.AssemblyInfoInputs.cache b/obj/Debug/net9.0/FinalBattle.AssemblyInfoInputs.cache index 56e667b..a3b3f68 100644 --- a/obj/Debug/net9.0/FinalBattle.AssemblyInfoInputs.cache +++ b/obj/Debug/net9.0/FinalBattle.AssemblyInfoInputs.cache @@ -1 +1 @@ -03324aadae7ba823214854ceeca2cc3a92695461309aa141d7edb8b5f2f8cc47 +e00ffe98b8c56894d814e7bb3259dda6570fc0986ec9409909259c374f9f4a7c diff --git a/obj/Debug/net9.0/FinalBattle.csproj.CoreCompileInputs.cache b/obj/Debug/net9.0/FinalBattle.csproj.CoreCompileInputs.cache index 3e2b214..4289a2a 100644 --- a/obj/Debug/net9.0/FinalBattle.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net9.0/FinalBattle.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -3235bef0a15147595cd9d8b95c54ad6a8e17ed84b619b5a0ff9feb9b9eb6f2e3 +fc5e7a79401482b5116e4f706afeb0a9e24e4ee24b315420ef0280d76b87f3ac diff --git a/obj/Debug/net9.0/FinalBattle.dll b/obj/Debug/net9.0/FinalBattle.dll index 93a9422..d16aaa3 100644 Binary files a/obj/Debug/net9.0/FinalBattle.dll and b/obj/Debug/net9.0/FinalBattle.dll differ diff --git a/obj/Debug/net9.0/FinalBattle.pdb b/obj/Debug/net9.0/FinalBattle.pdb index 2c580f4..faab228 100644 Binary files a/obj/Debug/net9.0/FinalBattle.pdb and b/obj/Debug/net9.0/FinalBattle.pdb differ diff --git a/obj/Debug/net9.0/ref/FinalBattle.dll b/obj/Debug/net9.0/ref/FinalBattle.dll index a1c1241..deb52ea 100644 Binary files a/obj/Debug/net9.0/ref/FinalBattle.dll and b/obj/Debug/net9.0/ref/FinalBattle.dll differ diff --git a/obj/Debug/net9.0/refint/FinalBattle.dll b/obj/Debug/net9.0/refint/FinalBattle.dll index a1c1241..deb52ea 100644 Binary files a/obj/Debug/net9.0/refint/FinalBattle.dll and b/obj/Debug/net9.0/refint/FinalBattle.dll differ