Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- public class Character
- {
- static Random random = new Random(Environment.TickCount); // Static -- each instance of Character class uses this same variable.
- static int attackRoll;
- // Member variables. Each instance of the Character class gets a copy of all.
- public string Name;
- public int Strength, Dexterity, Intelligence, Health, MaxHitPoints, HitPoints, Speed, WeaponSkill, Armor;
- public bool Alive;
- public Character(string name, int strength, int dexterity, int intelligence, int health, int maxHitPoints, int hitPoints, int speed,
- int weaponSkill, int armor, bool alive) // Constructor.
- {
- // Begin initializing member variables:
- Name = name;
- Strength = strength;
- Dexterity = dexterity;
- Intelligence = intelligence;
- MaxHitPoints = maxHitPoints;
- HitPoints = hitPoints;
- Speed = speed;
- WeaponSkill = weaponSkill;
- Armor = armor;
- Alive = alive;
- } // End constructor.
- public void Combat(Character target) //Combat function.
- {
- Console.WriteLine("\nDo you wish to (A)ttack, (D)efend, Attack to (H)it Location, or chose a (T)actical Option?\n");
- string combatChoice = Console.ReadLine();
- switch (combatChoice.ToUpper())
- {
- case "A":
- Console.WriteLine("\nDo you wish to (S)wing or (T)hrust?\n");
- string swingOrThrust = Console.ReadLine();
- switch (swingOrThrust.ToUpper())
- {
- case "S":
- Swing(target);
- break;
- case "T":
- Thrust(target);
- break;
- default:
- break; // Break from swingOrThrust block.
- } // Break from swingOrThrust block.
- break; // Break from case "A" and combatChoice block.
- default:
- Console.WriteLine("\nNot a valid option!\n Press any key to continue...\n");
- Console.ReadKey();
- Console.Clear();
- break; // Break from combatChoice block.
- } //End combatChoice swtich block.
- } // End Combat function.
- public void Swing(Character target)
- {
- attackRoll = random.Next(3, 18);
- Console.WriteLine("\nDebug: Roll = {0}.\n", attackRoll);
- if (attackRoll <= WeaponSkill)
- {
- Console.WriteLine("\n{0}'s attack was successfull!\n", Name);
- SwingDamageRoll(target);
- Console.WriteLine("\n{0} has {1} HP!\n", target.Name, target.HitPoints);
- Console.WriteLine("\nPress any key to continue...\n");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- Console.WriteLine("\nThe attack misses!\n");
- Console.WriteLine("\nPress any key to continue...\n");
- Console.ReadKey();
- Console.Clear();
- }
- } // End Swing function.
- public void Thrust(Character target)
- {
- attackRoll = random.Next(3, 18);
- Console.WriteLine("\nDebug: Roll = {0}.\n", attackRoll);
- if (attackRoll <= WeaponSkill)
- {
- Console.WriteLine("\n{0}'s attack was successfull!\n", Name);
- ThrustDamageRoll(target);
- Console.WriteLine("\n{0} has {1} HP!\n", target.Name, target.HitPoints);
- Console.WriteLine("\nPress any key to continue...\n");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- Console.WriteLine("\nThe attack misses!\n");
- Console.WriteLine("\nPress any key to continue...\n");
- Console.ReadKey();
- Console.Clear();
- }
- } // End Thrust function.
- public void SwingDamageRoll(Character target)
- {
- int damageRoll, basicDamage, injury;
- if (Strength == 10)
- {
- damageRoll = random.Next(1, 6);
- basicDamage = Math.Max((damageRoll - target.Armor), 0);
- injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
- target.HitPoints -= injury;
- Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
- AliveOrDead(target);
- }
- if (Strength == 22)
- {
- damageRoll = random.Next(4, 24);
- basicDamage = Math.Max((damageRoll - target.Armor), 0);
- injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
- target.HitPoints -= injury;
- Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
- AliveOrDead(target);
- }
- else
- {
- }
- } // End Swing Damage Roll function.
- public void ThrustDamageRoll(Character target)
- {
- int damageRoll, basicDamage, injury;
- if (Strength == 10)
- {
- damageRoll = Math.Max((random.Next(1, 6) - 2), 0);
- basicDamage = Math.Max((damageRoll - target.Armor), 0);
- injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
- target.HitPoints -= injury;
- Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
- AliveOrDead(target);
- }
- if (Strength == 22)
- {
- damageRoll = random.Next(2, 12);
- basicDamage = Math.Max((damageRoll - target.Armor), 0);
- injury = basicDamage; // Injury will = basic damage * int damage type. Damage type is based on weapon.
- target.HitPoints -= injury;
- Console.WriteLine("\nRolling for damage... {0} rolled {1} and did {2} damage.\n", Name, damageRoll, injury);
- AliveOrDead(target);
- }
- else
- {
- }
- } // End Thrust Damage Roll function.
- public void AliveOrDead(Character target)
- {
- if (target.HitPoints <= 0)
- {
- target.Alive = false;
- Console.WriteLine("\n{0} was slain!\n", target.Name);
- }
- } // End Alive Or Dead function.
- } // End Character class.
- class Program
- {
- // Declare the Random class, give it the name "random," then make a new instance of the Random class:
- static Random random = new Random(Environment.TickCount);
- static void Main(string[] args) //The Main function.
- {
- // Create instances of the Character class:
- // (string name, int strength, int dexterity, int intelligence, int health, int maxHitPoints, int hitPoints, int speed, int weaponSkill, int armor, bool alive)
- Character player = new Character("", 0, 0, 0, 0, 0, 0, 0, 0, 0, true);
- Character goblin = new Character("the goblin", 10, 0, 0, 0, 10, 10, 7, 12, 1, true);
- Character orc = new Character("the orc", 10, 0, 0, 0, 14, 14, 5, 12, 2, true);
- // Begin game:
- Console.WriteLine(@"
- ENTER...
- ___________ __ _____
- \__ ___/| |__ ____ / _ \_______ ____ ____ _____
- ╔═══| |═══| | \_/ __ \═══/ /_\ \_ __ \_/ __ \ / \\__ \════╗
- ║ | | | Y \ ___/ / | \ | \/\ ___/| | \/ __ \_ ║
- ║ |____| |___| /\___ > \____|__ /__| \___ >___| (____ / ║
- ╚═════════════════\/═════\/══════════\/════════════\/═════\/═════\/═══╝
- ...IF YOU DARE!
- Press any key...
- ''The Arena'' by Richard D. Sharpe
- camaro_driver@hotmail.com
- *** Special thanks to GameDev.net! ***
- version 0.102511.04");
- Console.ReadKey();
- Console.Clear();
- bool gameRunning = true;
- while (gameRunning)
- {
- Console.WriteLine(@"
- ╔═════════════════ MAIN MENU ═════════════════╗
- ║ (C)reate a Character ╔═══ Character ═══╗ ║
- ║ (D)isplay Character ║ Name:{0} ║ ║
- ║ (E)quipment ║ Hit Points: {1} ║ ║
- ║ (S)leep ║ Level: ║ ║
- ║ (H)ealer ║ EXP: ║ ║
- ║ (A)rmory ║ Gold: ║ ║
- ║ (F)ight in the arena! ╚═════════════════╝ ║
- ╚═════════════════════════════════════════════╝", player.Name.PadLeft(10), player.HitPoints.ToString().PadLeft(3));
- Console.WriteLine("\n");
- Console.WriteLine(" Make your selection: \n");
- string menuChoice = Console.ReadLine();
- switch (menuChoice.ToUpper())
- {
- case "C":
- Console.Clear();
- if (player.Name == "")
- {
- Console.WriteLine("\nCurrently, no character creation functions are available in this version.\n");
- Console.WriteLine("\nName your character: \n");
- player.Name = Console.ReadLine();
- player.Strength = 22;
- player.Dexterity = 10;
- player.Intelligence = 10;
- player.Health = 10;
- player.MaxHitPoints = 22;
- player.HitPoints = 22;
- player.WeaponSkill = 12;
- player.Speed = 6;
- Console.WriteLine("\nCharacter created!\n");
- }
- else
- {
- Console.WriteLine("You have already created a character named {0}.\n", player.Name);
- }
- Console.WriteLine("\nPress any key to continue... ");
- Console.ReadKey();
- Console.Clear();
- break; // End 'C' case.
- case "D":
- Console.Clear();
- Console.WriteLine(@"
- ╔═══════════════ CHARACTER SHEET ═══════════════╗
- ║ ║
- ║ Name: {0} ║
- ║ Species: ║
- ║ Class: ║
- ║ ║
- ║ ╔═══ Attributes ════╗╔══ Characteristics ═══╗ ║
- ║ ║ Strength: {1} ║║ Hit Points: {5} ║ ║
- ║ ║ Dexterity: {2} ║║ Willpower: ║ ║
- ║ ║ Intelligence: {3} ║║ Perception: ║ ║
- ║ ║ Health: {4} ║║ Fatigue Points: ║ ║
- ║ ╚═══════════════════╝╚══════════════════════╝ ║
- ║ ╔═══════ Armor ════════╦════ Equipment ═════╗ ║
- ║ ║ Helmet: ║ R. Hand: ║ ║
- ║ ║ Body: ║ L. Hand: ║ ║
- ║ ║ Arms: ╠════════════════════╣ ║
- ║ ║ Hands: ║ Gold: ║ ║
- ║ ║ Legs: ║ Ring: ║ ║
- ║ ║ Feet: ║ Necklace: ║ ║
- ║ ╚══════════════════════╩════════════════════╝ ║
- ╚═══════════════════════════════════════════════╝", player.Name.PadRight(10),
- player.Strength.ToString().PadLeft(3),
- player.Dexterity.ToString().PadLeft(3),
- player.Intelligence.ToString().PadLeft(3),
- player.Health.ToString().PadLeft(3),
- player.MaxHitPoints.ToString().PadLeft(3));
- Console.WriteLine("\nPress any key to continue... ");
- Console.ReadKey();
- Console.Clear();
- break;
- case "E":
- Console.Clear();
- Console.WriteLine("This selection not yet implemented.");
- Console.WriteLine("\nPress any key...");
- Console.ReadKey();
- Console.Clear();
- break;
- case "S":
- Console.Clear();
- Console.WriteLine("This selection not yet implemented.");
- Console.WriteLine("\nPress any key...");
- Console.ReadKey();
- Console.Clear();
- break;
- case "H":
- Console.Clear();
- Console.WriteLine("This selection not yet implemented.");
- Console.WriteLine("\nPress any key...");
- Console.ReadKey();
- Console.Clear();
- break;
- case "A":
- Console.Clear();
- Console.WriteLine("This selection not yet implemented.");
- Console.WriteLine("\nPress any key...");
- Console.ReadKey();
- Console.Clear();
- break;
- case "F":
- Console.Clear();
- Console.WriteLine("\nChose your opponent: (G)oblin, (O)rc.\n");
- string opponentChoice = Console.ReadLine();
- switch (opponentChoice.ToUpper())
- {
- case "G":
- Console.Clear();
- Console.WriteLine("\nYou're fighting a goblin!\n");
- do
- {
- if (player.Speed >= goblin.Speed)
- {
- if (player.Alive == true)
- {
- player.Combat(goblin);
- }
- if (goblin.Alive == true)
- {
- Console.WriteLine("\nThe goblin is attacking!\n");
- goblin.Swing(player);
- }
- }
- else
- {
- if (goblin.Alive == true)
- {
- Console.WriteLine("\nThe goblin is attacking!\n");
- goblin.Swing(player);
- }
- if (player.Alive == true)
- {
- player.Combat(goblin);
- }
- }
- } while (player.Alive == true && goblin.Alive == true);
- break; // Break from combat with the goblin.
- case "O":
- Console.Clear();
- Console.WriteLine("\nYou're fighting an orc!\n");
- do
- {
- if (player.Speed >= orc.Speed)
- {
- if (player.Alive == true)
- {
- player.Combat(orc);
- }
- if (orc.Alive == true)
- {
- Console.WriteLine("\nThe orc is attacking!\n");
- orc.Swing(player);
- }
- }
- else
- {
- if (orc.Alive == true)
- {
- Console.WriteLine("\nThe orc is attacking!\n");
- orc.Swing(player);
- }
- if (player.Alive == true)
- {
- player.Combat(orc);
- }
- }
- } while (player.Alive == true && orc.Alive == true);
- break; // Break from combat with the orc.
- default:
- Console.Clear();
- Console.WriteLine("Not a valid choice.");
- break;
- } // End opponenet choice.
- break;
- default:
- Console.Clear();
- Console.WriteLine("Not a valid selection.");
- Console.WriteLine("\nPress any key...");
- Console.ReadKey();
- Console.Clear();
- break;
- } // End main menu switch.
- } // End game running loop.
- } // End Main.
- } // End Program class.
- } // End namespace.
Add Comment
Please, Sign In to add comment