TheBulgarianWolf

FIGHT GAME(console)

Apr 19th, 2020
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ProjectX
  9. {
  10.     class Project
  11.     {
  12.        
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             Console.WriteLine("Enter first hero's name: ");
  17.             String nameFirst = Console.ReadLine();
  18.             Console.WriteLine("Enter first herp's HP: ");
  19.             int hpFirst = int.Parse(Console.ReadLine());
  20.             Console.WriteLine("Enter first hero's attack damage: ");
  21.             int dmgFirst = int.Parse(Console.ReadLine());
  22.             Hero firstHero = new Hero(nameFirst, hpFirst, dmgFirst);
  23.             firstHero.speed = 0.5;
  24.             Console.WriteLine("Enter second hero's name: ");
  25.             String nameSecond = Console.ReadLine();
  26.             Console.WriteLine("Enter second hero's HP: ");
  27.             int hpSecond = int.Parse(Console.ReadLine());
  28.             Console.WriteLine("Enter second hero's attack damage: ");
  29.             int dmgSecond = int.Parse(Console.ReadLine());
  30.             Hero secondHero = new Hero(nameSecond, hpSecond, dmgSecond);
  31.             secondHero.speed = 0.4;
  32.             firstHero.Fight(secondHero);
  33.             Console.ReadKey();
  34.  
  35.  
  36.         }
  37.     }
  38.  
  39.     class Hero
  40.     {
  41.         //properties
  42.         public string name;
  43.         public int health;
  44.         public int damage;
  45.         public double speed;
  46.         Random rand = new Random();
  47.  
  48.         //constructor
  49.         public Hero(string name,int health,int damage)
  50.         {
  51.             this.name = name;
  52.             this.health = health;
  53.             this.damage = damage;
  54.         }
  55.  
  56.         public void GetStats()
  57.         {
  58.             Console.WriteLine("Hero: " + name + " | Health: " + health + " | Damage: " + damage);
  59.         }
  60.  
  61.         public void Attack(Hero enemy)
  62.         {
  63.             Thread.Sleep(1000);
  64.             rand = new Random();
  65.             int randomDefence = rand.Next(4);
  66.             if(randomDefence != 1)
  67.             {
  68.                
  69.                 Console.WriteLine(this.name + " attacks " + enemy.name + " for " + this.damage);
  70.                 Console.WriteLine(enemy.name + " has.. " + enemy.health + " HP left.");
  71.                 enemy.health -= this.damage;
  72.             }
  73.             else
  74.             {
  75.                 Console.BackgroundColor = ConsoleColor.DarkRed;
  76.                 Console.WriteLine(enemy.name + "blocked " + this.name + "'s attack.");
  77.             }
  78.            
  79.         }
  80.  
  81.         public void Fight(Hero enemy)
  82.         {
  83.             while(this.health > 0 && enemy.health > 0)
  84.             {
  85.                
  86.                 if(this.speed > enemy.speed)
  87.                 {
  88.                     Console.BackgroundColor = ConsoleColor.DarkBlue;
  89.                     this.Attack(enemy);
  90.                     Console.BackgroundColor = ConsoleColor.DarkGreen;
  91.                     enemy.Attack(this);
  92.                 }
  93.                 else
  94.                 {
  95.                     Console.BackgroundColor = ConsoleColor.DarkGreen;
  96.                     enemy.Attack(this);
  97.                     Console.BackgroundColor = ConsoleColor.DarkBlue;
  98.                     this.Attack(enemy);
  99.                 }
  100.             }
  101.  
  102.             if(this.health > enemy.health)
  103.             {
  104.                
  105.                 Console.WriteLine("You have WON the fight against " + enemy.name);
  106.                
  107.             }
  108.             else
  109.             {
  110.                 Console.BackgroundColor = ConsoleColor.Red;
  111.                 Console.WriteLine("You have LOST the battle against " + enemy.name);
  112.             }
  113.             this.GetStats();
  114.             enemy.GetStats();
  115.         }
  116.     }
  117. }
Add Comment
Please, Sign In to add comment