Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace RPGGame
- {
- class Program
- {
- #region
- // set variables
- static string difficulty;
- static int playerHealth = 125;
- static int monsterHealth = 100;
- static string playerName;
- static int playerAttackValue;
- static int monsterAttackValue;
- static string playerChoice;
- static String monsterName;
- #endregion
- static void Main(string[] args)
- {
- welcome();
- getDifficulty();
- initiateGame();
- }
- // difficulty is increased by making monster have higher attack value and lower player health
- private static void getDifficulty()
- {
- do
- {
- Console.Write("Choose difficulty (e)asy or (h)ard: ");
- difficulty = Console.ReadLine();
- if (difficulty == "e")
- {
- playerAttackValue = 10;
- monsterAttackValue = 5;
- break;
- }
- else if (difficulty == "h")
- {
- playerHealth = 110;
- playerAttackValue = 5;
- monsterAttackValue = 10;
- break;
- }
- else
- {
- Console.WriteLine("Not a valid option");
- }
- }
- while (difficulty != "e" && difficulty != "h");
- }
- static void welcome()
- {
- // Add a list of monster names
- List<string> monsterNames = new List<string>();
- monsterNames.Add("Orcman");
- monsterNames.Add("Wolf Man");
- monsterNames.Add("Giant Goldfish");
- monsterNames.Add("Evil Zombie");
- monsterNames.Add("Oprah Winfrey");
- monsterNames.Add("Snap Turtle");
- // welcome the player and tell who player is fighting
- Console.WriteLine("Welcome to monster fighting game"); Console.WriteLine();
- Console.Write("Please enter your name: ");
- playerName = Console.ReadLine(); Console.WriteLine();
- Console.WriteLine("Welcome " + playerName + " to the battle"); Console.WriteLine();
- Random nameMonster = new Random();
- monsterName = monsterNames[nameMonster.Next(0, 5)];
- Console.Write("You will be fighting "); Console.ForegroundColor = ConsoleColor.Red; Console.Write(monsterName);
- Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(" today");
- Console.WriteLine();
- }
- private static void initiateGame()
- {
- // Create a loop that runs as long as either player or monster
- // are above 0 health
- do
- {
- Console.WriteLine();
- Console.WriteLine("You have " + playerHealth + " health left " + monsterName + " has " + monsterHealth + " health left");
- Console.Write("Please (a)ttack, (d)efend or (q)uit: ");
- playerChoice = Console.ReadLine(); Console.WriteLine();
- if (playerChoice == "a")
- {
- // damage is worked out by assigning a random number 1 to 5 then multiplying by attack value
- Random rand = new Random();
- int attackDamage = (rand.Next(1, 5) * playerAttackValue);
- monsterHealth = monsterHealth - attackDamage;
- Console.WriteLine("You hit " + monsterName + " for {0} damage", attackDamage);
- monsterAttack();
- }
- else if (playerChoice == "d")
- {
- Console.WriteLine(monsterName + " attacks you");
- monsterAttack('d');
- }
- else if (playerChoice == "q")
- {
- Console.WriteLine(); Console.WriteLine("Thanks for playing");
- break;
- }
- else
- {
- Console.WriteLine("Invalid selection");
- }
- } while (monsterHealth > 0 && playerHealth > 0);
- // If monsters health is zero then player wins
- if (monsterHealth < 0)
- {
- Console.WriteLine("\n\n\nCongratulations you have slain " + monsterName);
- Console.WriteLine("\n\n\nThanks for playing");
- Console.ReadLine();
- }
- // if players health is zero player loses.
- else if (playerHealth < 0)
- {
- Console.WriteLine("\n\n\nYou have been killed by " + monsterName + "!");
- Console.WriteLine("\n\n\nThanks for playing");
- Console.ReadLine();
- }
- }
- // This is to work out monster damage
- static void monsterAttack()
- {
- Random rand = new Random();
- List<string> attacks = new List<string>();
- attacks.Add("swoops down a bites you");
- attacks.Add("jumps over an punches you in the chest");
- attacks.Add("spits out a watermelon");
- attacks.Add("throws a shoe");
- attacks.Add("shoots a lightning bolt");
- attacks.Add("spinning back kicks");
- attacks.Add("double punches");
- string attackStyle = attacks[rand.Next(0, 5)];
- int attackDamage = (rand.Next(1, 6) * monsterAttackValue);
- playerHealth = playerHealth - attackDamage;
- Console.WriteLine("{0} {1} hitting you for {2} damage", monsterName, attackStyle, attackDamage);
- }
- // This is to work out blocked damage
- static void monsterAttack(char d)
- {
- Random rand = new Random();
- List<string> attacks = new List<string>();
- attacks.Add("swoops down a bites you");
- attacks.Add("jumps over an punches you in the chest");
- attacks.Add("spits out a watermelon");
- attacks.Add("throws a shoe");
- attacks.Add("shoots a lightning bolt");
- attacks.Add("spinning back kicks");
- attacks.Add("double punches");
- string attackStyle = attacks[rand.Next(0, 5)];
- int attackDamage = (rand.Next(1, 6) * monsterAttackValue);
- int damageBlocked = attackDamage / 2;
- playerHealth = playerHealth - damageBlocked;
- Console.WriteLine("{0} {1} hitting you for {2} damage but you blocked {3}", monsterName, attackStyle, attackDamage, damageBlocked);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement