Advertisement
Guest User

C#GameProject

a guest
Nov 22nd, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace RPGGame
  6. {
  7.     class Program
  8.     {
  9.         #region
  10.         // set variables
  11.         static string difficulty;
  12.         static int playerHealth = 125;
  13.         static int monsterHealth = 100;
  14.         static string playerName;
  15.         static int playerAttackValue;
  16.         static int monsterAttackValue;
  17.         static string playerChoice;
  18.        
  19.         static String monsterName;
  20.         #endregion
  21.  
  22.         static void Main(string[] args)
  23.         {
  24.             welcome();
  25.             getDifficulty();
  26.             initiateGame();
  27.         }
  28.  
  29.         // difficulty is increased by making monster have higher attack value and lower player health
  30.         private static void getDifficulty()
  31.         {
  32.             do
  33.             {
  34.                 Console.Write("Choose difficulty (e)asy or (h)ard: ");
  35.                 difficulty = Console.ReadLine();
  36.                 if (difficulty == "e")
  37.                 {
  38.                     playerAttackValue = 10;
  39.                     monsterAttackValue = 5;
  40.                     break;
  41.                 }
  42.                 else if (difficulty == "h")
  43.                 {
  44.                     playerHealth = 110;
  45.                     playerAttackValue = 5;
  46.                     monsterAttackValue = 10;
  47.                     break;
  48.                 }
  49.                 else
  50.                 {
  51.                     Console.WriteLine("Not a valid option");
  52.                 }  
  53.             }
  54.             while (difficulty != "e" && difficulty != "h");
  55.         }
  56.  
  57.         static void welcome()
  58.         {
  59.            
  60.             // Add a list of monster names
  61.             List<string> monsterNames = new List<string>();
  62.             monsterNames.Add("Orcman");
  63.             monsterNames.Add("Wolf Man");
  64.             monsterNames.Add("Giant Goldfish");
  65.             monsterNames.Add("Evil Zombie");
  66.             monsterNames.Add("Oprah Winfrey");
  67.             monsterNames.Add("Snap Turtle");
  68.  
  69.             // welcome the player and tell who player is fighting
  70.             Console.WriteLine("Welcome to monster fighting game"); Console.WriteLine();
  71.             Console.Write("Please enter your name: ");
  72.             playerName = Console.ReadLine(); Console.WriteLine();
  73.             Console.WriteLine("Welcome " + playerName + " to the battle"); Console.WriteLine();
  74.             Random nameMonster = new Random();
  75.             monsterName = monsterNames[nameMonster.Next(0, 5)];
  76.             Console.Write("You will be fighting "); Console.ForegroundColor = ConsoleColor.Red; Console.Write(monsterName);
  77.             Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(" today");
  78.             Console.WriteLine();
  79.  
  80.         }
  81.  
  82.         private static void initiateGame()
  83.         {
  84.             // Create a loop that runs as long as either player or monster
  85.             // are above 0 health
  86.             do
  87.             {
  88.                 Console.WriteLine();
  89.                 Console.WriteLine("You have " + playerHealth + " health left " + monsterName + " has " + monsterHealth + " health left");
  90.                 Console.Write("Please (a)ttack, (d)efend or (q)uit: ");
  91.                 playerChoice = Console.ReadLine(); Console.WriteLine();
  92.  
  93.                 if (playerChoice == "a")
  94.                 {
  95.                     // damage is worked out by assigning a random number 1 to 5 then multiplying by attack value
  96.                     Random rand = new Random();
  97.                     int attackDamage = (rand.Next(1, 5) * playerAttackValue);
  98.                     monsterHealth = monsterHealth - attackDamage;
  99.                     Console.WriteLine("You hit " + monsterName + " for {0} damage", attackDamage);
  100.                     monsterAttack();
  101.                 }
  102.                 else if (playerChoice == "d")
  103.                 {
  104.                     Console.WriteLine(monsterName + " attacks you");
  105.                     monsterAttack('d');
  106.                 }
  107.                 else if (playerChoice == "q")
  108.                 {
  109.                     Console.WriteLine(); Console.WriteLine("Thanks for playing");
  110.                     break;
  111.                 }
  112.                 else
  113.                 {
  114.                     Console.WriteLine("Invalid selection");
  115.                 }
  116.  
  117.             } while (monsterHealth > 0 && playerHealth > 0);
  118.            
  119.             // If monsters health is zero then player wins
  120.             if (monsterHealth < 0)
  121.             {
  122.               Console.WriteLine("\n\n\nCongratulations you have slain " + monsterName);
  123.                
  124.                 Console.WriteLine("\n\n\nThanks for playing");
  125.                 Console.ReadLine();
  126.             }
  127.  
  128.             // if players health is zero player loses.
  129.             else if (playerHealth < 0)
  130.             {
  131.                 Console.WriteLine("\n\n\nYou have been killed by " + monsterName + "!");
  132.                 Console.WriteLine("\n\n\nThanks for playing");
  133.                 Console.ReadLine();
  134.             }
  135.         }
  136.  
  137.         // This is to work out monster damage
  138.         static void monsterAttack()
  139.         {
  140.             Random rand = new Random();
  141.             List<string> attacks = new List<string>();
  142.             attacks.Add("swoops down a bites you");
  143.             attacks.Add("jumps over an punches you in the chest");
  144.             attacks.Add("spits out a watermelon");
  145.             attacks.Add("throws a shoe");
  146.             attacks.Add("shoots a lightning bolt");
  147.             attacks.Add("spinning back kicks");
  148.             attacks.Add("double punches");
  149.             string attackStyle = attacks[rand.Next(0, 5)];
  150.             int attackDamage = (rand.Next(1, 6) * monsterAttackValue);
  151.             playerHealth = playerHealth - attackDamage;
  152.             Console.WriteLine("{0} {1} hitting you for {2} damage", monsterName, attackStyle, attackDamage);
  153.            
  154.         }
  155.  
  156.         // This is to work out blocked damage
  157.         static void monsterAttack(char d)
  158.         {
  159.             Random rand = new Random();
  160.             List<string> attacks = new List<string>();
  161.             attacks.Add("swoops down a bites you");
  162.             attacks.Add("jumps over an punches you in the chest");
  163.             attacks.Add("spits out a watermelon");
  164.             attacks.Add("throws a shoe");
  165.             attacks.Add("shoots a lightning bolt");
  166.             attacks.Add("spinning back kicks");
  167.             attacks.Add("double punches");
  168.             string attackStyle = attacks[rand.Next(0, 5)];
  169.             int attackDamage = (rand.Next(1, 6) * monsterAttackValue);
  170.             int damageBlocked = attackDamage / 2;
  171.             playerHealth = playerHealth - damageBlocked;
  172.             Console.WriteLine("{0} {1} hitting you for {2} damage but you blocked {3}", monsterName, attackStyle, attackDamage, damageBlocked);
  173.          }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement