Compare commits

4 Commits

Author SHA1 Message Date
e4b230a0ad Changed a lot of Actions.cs and a few other things to be more easily
extendable.
2025-09-03 23:32:20 -05:00
69e6699e26 Nothing actually changed. 2025-08-29 10:53:50 -05:00
30793101df added some stuff 2025-08-24 08:06:04 -05:00
a1877e7ddb Re-add changes to interface so far. Broken at time of commit. 2025-08-24 07:47:14 -05:00
21 changed files with 834 additions and 317 deletions

View File

@@ -1,295 +1,557 @@
/*
public interface IAction public interface IAction
{ {
void GetAction(Character character); void DoAction(Character character, Action action);
void DoNothing(Character character);
void Attack();
void HealthPotion();
Item Items();
} }
*/
public sealed class Actions //: IAction public sealed class Actions
{ {
private static readonly Lazy<Actions> _instance = new Lazy<Actions>(() => new Actions());
private Actions() { } public static readonly Lazy<Actions> _instance = new Lazy<Actions> (() => new Actions());
private Actions() {}
public static Actions Instance public static Actions Instance
{ {
get { return _instance.Value; } get {return _instance.Value;}
} }
public void GetAction(Character character) public int GetAction(Character character)
{ {
/* if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == false)
switch (MenuItem.Description)
{ {
int input;
default: while (true)
}
*/
while (true)
{
var type = character.GetType().ToString();
switch (type)
{ {
case "Player": PlayerActions(character); break; try
case "Skeleton": MonsterActions(character); break; {
case "UncodedOne": MonsterActions(character); break; input = Int32.Parse(ColoredConsole.Prompt("Select an action"));
default: }
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;
}
} }
break; return input - 1;
} }
} else if (GameState.Instance.monsters.Contains(character) && GameState.Instance.monstersAIControl == false)
public void PlayerActions(Character character)
{
string? action;
while (true)
{ {
Console.Clear(); int input;
GameState.Instance.DisplayStatus(); while (true)
Console.WriteLine($"Current Round: {GameState.Instance.currentRound}");
Console.WriteLine("\n1. Do Nothing");
Console.WriteLine("2. Punch");
if (GameState.Instance.herosAIControl == 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 else
{ {
Console.Write($"\n{character.name}, select an action: "); while (true)
action = Console.ReadLine(); {
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; DoNothing(character);
Console.Clear(); return true;
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;
} }
} if (actionToDo == "Punch")
public Character SelectTarget(Character character)
{
int target;
while (true)
{ {
if (GameState.Instance.heros.Contains(character)) Punch(character);
{ return true;
Console.WriteLine(); }
int number = 1; if (actionToDo == "Sword Attack")
foreach (var monster in GameState.Instance.monsters) {
{ SwordAttack(character);
Console.WriteLine($"{number}. {monster.name}"); return true;
number++; }
} if (actionToDo == "Health Potion")
} {
else if (GameState.Instance.monsters.Contains(character)) HealthPotion(character);
{ return true;
int number = 1; }
Console.WriteLine(); if (actionToDo == "Items")
foreach (var hero in GameState.Instance.heros) {
{ bool useItem = Items(character);
Console.WriteLine($"{number}. {hero.name}"); return useItem;
number++; }
} if (actionToDo == "Bone Crunch")
} {
Console.Write("\nSelect a target: "); BoneCrunch(character);
try return true;
{ }
target = Int32.Parse(Console.ReadLine()); if (actionToDo == "Unraveling")
} {
catch (System.FormatException) Unraveling(character);
{ return true;
Console.WriteLine("\nSorry, that's not a valid target..."); }
continue; if (actionToDo == "Bow Shot")
} {
try BowShot(character);
{ return true;
if (GameState.Instance.heros.Contains(character)) }
{ if (actionToDo == "Quick Shot")
return GameState.Instance.monsters[target - 1]; {
} QuickShot(character);
else if (GameState.Instance.monsters.Contains(character)) return true;
{ }
return GameState.Instance.heros[target - 1]; if (actionToDo == "Hero's Sword")
} {
} HerosSword(character);
catch (System.ArgumentOutOfRangeException) return true;
{ }
Console.WriteLine("\nSorry, that's not a valid target..."); if (actionToDo == "Bite")
continue; {
} Bite(character);
return true;
}
else
{
return false;
} }
} }
public void DoNothing(Character character) public void DoNothing(Character character)
{ {
ColoredConsole.WriteLine($"\n{character.name} does NOTHING.", ConsoleColor.Yellow);
Console.WriteLine($"\n{character.name} does nothing..."); Thread.Sleep(1500);
Thread.Sleep(1000); return;
} }
public void Punch(Character character) public void Punch(Character character)
{ {
Character target = null; var target = GetTarget(character);
if (GameState.Instance.herosAIControl == true) 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 else
{ {
target = SelectTarget(character); damage = character.damageModifier - target.damageReduction;
} }
ColoredConsole.WriteLine($"\n{character.name} uses SWORD ATTACK!", ConsoleColor.Yellow);
Console.WriteLine($"\n{character.name} uses PUNCH on {target.name}!"); if (target.name == "Amarok")
Console.WriteLine($"{target.name} took 1 damage!"); {
target.currentHP -= 1; ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red);
Thread.Sleep(1000); }
ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
ColoredConsole.Write("HP.", ConsoleColor.Cyan);
target.currentHP -= damage;
Thread.Sleep(1500);
return; 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) public void BoneCrunch(Character character)
{ {
Character target = null; var target = GetTarget(character);
if (GameState.Instance.monstersAIControl == true) int damage;
{
target = AIPickTarget(character);
}
else
{
target = SelectTarget(character);
}
ColoredConsole.WriteLine($"\n{character.name} uses BONE CRUNCH!", ConsoleColor.Yellow);
Random random = new Random(); Random random = new Random();
int coin = random.Next(1, 101); if (character.equipedItems.Any())
Console.WriteLine($"\n{character.name} used Bone Crunch on {target.name}!");
if (coin > 50)
{ {
Console.WriteLine($"{target.name} took 1 damage!"); damage = random.Next(0, 2) + character.damageModifier + character.equipedItems[0].ItemDamageModifier - target.damageReduction;
target.currentHP -= 1;
Thread.Sleep(1000);
return;
} }
else else
{ {
Console.WriteLine("Nothing happened!"); damage = random.Next(0, 2) - target.damageReduction;
Thread.Sleep(1000);
return;
} }
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) public void Unraveling(Character character)
{ {
Character target = null; var target = GetTarget(character);
if (GameState.Instance.monstersAIControl == true) 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 else
{ {
target = SelectTarget(character); if (target.name == "Amarok")
} {
Random random = new Random(); ColoredConsole.WriteLine("STONE ARMOR reduced damage to Amarok by 1.", ConsoleColor.Red);
Console.WriteLine($"\n{character.name} used Unraveling on {target.name}!"); }
int damage = random.Next(3); damage = random.Next(2,6) - target.damageReduction;
if (damage > 0) ColoredConsole.Write($"{target.name} loses ", ConsoleColor.Cyan);
{ ColoredConsole.Write($"{damage} ", ConsoleColor.Red);
Console.WriteLine($"{target.name} took {damage} damage!"); ColoredConsole.Write($"HP.", ConsoleColor.Cyan);
target.currentHP -= damage; target.currentHP -= damage;
Thread.Sleep(1000); Thread.Sleep(1500);
return; return;
} }
} }
public Character AIPickTarget(Character character) public Character GetTarget(Character character)
{ {
Random random = new Random(); if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == false)
if (GameState.Instance.heros.Contains(character))
{ {
var lastItem = GameState.Instance.monsters.Count(); while (true)
var target = random.Next(1, lastItem + 1); {
return GameState.Instance.monsters[target - 1]; 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(); while (true)
var target = random.Next(1, lastItem + 1); {
return GameState.Instance.heros[target - 1]; 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;
}
}
} }
} else if (GameState.Instance.heros.Contains(character) && GameState.Instance.herosAIControl == true)
{
public string AIPickAction() while (true)
{ {
Random random = new Random(); Random random = new Random();
Thread.Sleep(1000); int index = random.Next(0, GameState.Instance.monsters.Count);
return random.Next(1, 3).ToString(); 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];
} }
} }

11
Amarok.cs Normal file
View File

@@ -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");
}
}

View File

@@ -4,7 +4,10 @@ public abstract class Character
public int maxHP {get; set;} public int maxHP {get; set;}
public int currentHP {get; set;} public int currentHP {get; set;}
public bool dead {get; set;} = false; public bool dead {get; set;} = false;
public string turnMarker = "*"; public bool isTurn {get; set;}
public bool isTurn {get; set;} = false; public List<string>? CharacterEnabledActions = new List<string>();
//public List<Actions>CharacterEnabledActions = new List<Actions>(); public int damageReduction {get; set;} = 0;
public int damageModifier {get; set;} = 0;
public List<Item>? equipedItems = new List<Item>();
public List<string>? CharacterDisabledActions = new List<string>();
} }

36
ColoredConsole.cs Normal file
View File

@@ -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;
}
}
}

View File

@@ -11,32 +11,31 @@ public sealed class GameState
public List<Character> monsters = new List<Character>(); public List<Character> monsters = new List<Character>();
public List<Character> heroRemove = new List<Character>(); public List<Character> heroRemove = new List<Character>();
public List<Character> monsterRemove = new List<Character>(); public List<Character> monsterRemove = new List<Character>();
public List<Item> heroInventory = new List<Item>();
public int currentRound = 1; public int currentRound = 1;
public bool gameOver = false; public bool gameOver = false;
public bool herosAIControl = false; public bool herosAIControl = false;
public bool monstersAIControl = true; public bool monstersAIControl = true;
public bool lastRound = false; public bool lastRound = false;
public int heroPotionsAvailable = 5;
/* public int monsterPotionsAvailable = 2;
public record MenuItem public bool BowIsEquippedBy = false;
{ public bool SwordIsEquippedBy = false;
string? Description;
bool IsEnabled; //Menu menu = new Menu();
IAction? ActionToPerform;
}
public void BuildMenu()
{
foreach (action in Character.EnabledActions)
int number = 1;
}
*/
public void Run() 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); Rounds(currentRound);
while (gameOver == false) while (gameOver == false)
{ {
int action;
GameOver(); GameOver();
if (gameOver == true) if (gameOver == true)
{ {
@@ -46,22 +45,52 @@ public sealed class GameState
{ {
foreach (Character hero in heros) foreach (Character hero in heros)
{ {
BeginHeroTurn:
hero.isTurn = true; hero.isTurn = true;
Actions.Instance.GetAction(hero); Console.Clear();
CheckDead(); DisplayStatus();
hero.isTurn = false; 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()) if (monsters.Any() && heros.Any())
{ {
foreach (Character monster in monsters) foreach (Character monster in monsters)
{ {
monster.isTurn = true; 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(); CheckDead();
foreach (Character hero in heroRemove) foreach (Character hero in heroRemove)
{ {
@@ -167,47 +196,52 @@ public sealed class GameState
if (currentRound == 2) if (currentRound == 2)
{ {
Console.Clear(); Console.Clear();
Console.WriteLine("You are victorious in your first battle!"); ColoredConsole.WriteLine("You are victorious in your first battle!", ConsoleColor.Green);
Thread.Sleep(2000); Thread.Sleep(1500);
Console.WriteLine("\nAs you make your way deeper into the Uncoded One's fortress" 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..."); + "\nmore enemies appear to block your way to defeat their master...", ConsoleColor.Cyan);
Console.WriteLine("\n\nPress Enter to continue..."); Console.WriteLine("\n\nPress Enter to continue...");
Console.ReadLine(); Console.ReadLine();
Skeleton skeleton1 = new Skeleton(); Skeleton skeleton1 = new Skeleton();
Skeleton skeleton2 = new Skeleton(); Skeleton skeleton2 = new Skeleton();
monsters.AddRange(skeleton1, skeleton2); Amarok amarok1 = new Amarok();
monsters.AddRange(skeleton1, skeleton2, amarok1);
} }
if (currentRound == 3) if (currentRound == 3)
{ {
Console.Clear(); Console.Clear();
Console.WriteLine("You have completed the second battle in your assualt on the" ColoredConsole.WriteLine("You have completed the second battle in your assualt on the"
+ " Uncoded One's fortress!"); + " Uncoded One's fortress!", ConsoleColor.Green);
Thread.Sleep(2000); Thread.Sleep(1500);
Console.WriteLine("\nAs you move deeper into the fortress, you come upon two great" 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" + "\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" + "\nfind yourself in the Uncoded One's throne room. The Uncoded One stands"
+ "\nfrom his throne of blackened steel and hisses, \"You have finally" + "\nfrom his throne of blackened steel and hisses, \"You have finally"
+ "\nappeared before me True Programmer. Now you will die, and the world" + "\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.WriteLine("\n\nPress Enter to continue...");
Console.ReadLine(); Console.ReadLine();
Amarok amarok1 = new Amarok();
Amarok amarok2 = new Amarok();
Skeleton skeleton1 = new Skeleton(); Skeleton skeleton1 = new Skeleton();
Skeleton skeleton2 = new Skeleton(); Skeleton skeleton2 = new Skeleton();
Skeleton skeleton3 = new Skeleton(); Skeleton skeleton3 = new Skeleton();
UncodedOne uncodedOne = new UncodedOne(); UncodedOne uncodedOne = new UncodedOne();
monsters.AddRange(skeleton1, skeleton2, skeleton3, uncodedOne); monsters.AddRange(skeleton1, skeleton2, skeleton3, amarok1, amarok2, uncodedOne);
} }
} }
public void HerosWin() public void HerosWin()
{ {
Console.Clear(); Console.Clear();
Thread.Sleep(2000); Thread.Sleep(1500);
Console.WriteLine("As you strike the Uncoded One down, the sky brightens and the" ColoredConsole.WriteLine("As you strike the Uncoded One down, the sky brightens and the"
+ " miasma\nsurrounding his dark fortress begins to lift...\n\n" + " miasma\nsurrounding his dark fortress begins to lift...\n\n", ConsoleColor.Cyan);
+ "You are victorious!\n\nTrue Programming has been restored to the lands, and" 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" + " 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.WriteLine("\nPress Enter to exit your final challenge, True Programmer!");
Console.ReadLine(); Console.ReadLine();
} }
@@ -215,11 +249,11 @@ public sealed class GameState
public void MonstersWin() public void MonstersWin()
{ {
Console.Clear(); Console.Clear();
Thread.Sleep(2000); Thread.Sleep(1500);
Console.WriteLine("You have been brutally struck down by the Uncoded One and his evil\n" 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" + "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" + "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(); Console.ReadLine();
} }
} }

107
Item.cs Normal file
View File

@@ -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";
}
}

35
Menu.cs Normal file
View File

@@ -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");
}
}

View File

@@ -2,20 +2,43 @@ public class Player : Character
{ {
public Player() public Player()
{ {
maxHP = 10;
currentHP = maxHP;
name = GetName(); name = GetName();
//List<IherosAction>CharacterEnabledActions = new List<IAction>(); maxHP = 25;
//CharacterEnabledActions.Add(Actions.Instance.DoNothing() currentHP = maxHP;
dead = false;
CharacterEnabledActions.AddRange("Punch", "Health Potion", "Items", "Do Nothing");
} }
public string GetName() public string GetName()
{ {
string? input; string input = null;
Console.Write("Enter your player's name: "); if (GameState.Instance.herosAIControl == false)
input = Console.ReadLine(); {
return input; 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";
}
} }
} }

View File

@@ -1,62 +1,56 @@
string? input; string? input;
Console.Clear(); Console.Clear();
Console.WriteLine("Welcome True Programmer, to the final battle for the realms of C#."); ColoredConsole.WriteLine("------------------------------------------------------------------", ConsoleColor.Cyan);
Console.WriteLine("------------------------------------------------------------------"); ColoredConsole.WriteLine("Welcome True Programmer, to the final battle for the realms of C#.", ConsoleColor.Cyan);
Thread.Sleep(1000); Thread.Sleep(1000);
Console.WriteLine("\nThis will be the final battle against the Uncoded One..." ColoredConsole.WriteLine("\nThis will be the final battle against the Uncoded One..."
+ "\nAre you ready?"); + "\nAre you ready?", ConsoleColor.Cyan);
Console.WriteLine("--------------------------------------------------------" ColoredConsole.WriteLine("--------------------------------------------------------"
+ "--------------"); + "----------", ConsoleColor.Cyan);
Console.ReadLine(); Console.ReadLine();
while (true) while (true)
{ {
Console.Clear(); try
Console.Write("\nWould you like the heroes party to be controlled by AI? (yes/no): ");
input = Console.ReadLine().ToLower();
if (input == "yes" || input == "no")
{ {
if (input == "yes") Console.Clear();
{ ColoredConsole.WriteLine("Game mode:", ConsoleColor.Green);
GameState.Instance.herosAIControl = true; Console.WriteLine("\n1. Player vs Computer\n2. Player vs Player\n3. Computer vs Computer");
} ColoredConsole.WriteLine("-----------------------", ConsoleColor.Cyan);
if (input == "no") input = ColoredConsole.Prompt("Enter a game mode");
if (input == "1")
{ {
GameState.Instance.herosAIControl = false; 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; GameState.Instance.monstersAIControl = true;
break;
} }
if (input == "no") if (input == "2")
{ {
GameState.Instance.herosAIControl = false;
GameState.Instance.monstersAIControl = 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); Thread.Sleep(1000);
continue; continue;
} }
break;
} }
Player player = new Player(); Player player = new Player();

View File

@@ -5,5 +5,6 @@ public class Skeleton : Character
maxHP = 5; maxHP = 5;
currentHP = maxHP; currentHP = maxHP;
name = "Skeleton"; name = "Skeleton";
CharacterEnabledActions.AddRange("Bone Crunch", "Health Potion", "Do Nothing");
} }
} }

View File

@@ -5,5 +5,6 @@ public class UncodedOne : Character
maxHP = 15; maxHP = 15;
currentHP = maxHP; currentHP = maxHP;
name = "The Uncoded One"; name = "The Uncoded One";
CharacterEnabledActions.AddRange("Unraveling", "Health Potion", "Do Nothing");
} }
} }

10
VinFletcher.cs Normal file
View File

@@ -0,0 +1,10 @@
class VinFletcher : Character
{
public VinFletcher()
{
maxHP = 15;
currentHP = maxHP;
name = "Vin Fletcher";
CharacterEnabledActions.AddRange("Punch", "Health Potion", "Items", "Do Nothing");
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("FinalBattle")] [assembly: System.Reflection.AssemblyCompanyAttribute("FinalBattle")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+69e6699e26437733347c699bdfce91e200b6319c")]
[assembly: System.Reflection.AssemblyProductAttribute("FinalBattle")] [assembly: System.Reflection.AssemblyProductAttribute("FinalBattle")]
[assembly: System.Reflection.AssemblyTitleAttribute("FinalBattle")] [assembly: System.Reflection.AssemblyTitleAttribute("FinalBattle")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
15175f65f6f63f0c4c3ae8d13187889e73fe451b685fbc2643b44dd8e1084a87 e00ffe98b8c56894d814e7bb3259dda6570fc0986ec9409909259c374f9f4a7c

View File

@@ -1 +1 @@
3235bef0a15147595cd9d8b95c54ad6a8e17ed84b619b5a0ff9feb9b9eb6f2e3 fc5e7a79401482b5116e4f706afeb0a9e24e4ee24b315420ef0280d76b87f3ac

Binary file not shown.

Binary file not shown.

Binary file not shown.