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;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ProjectX
- {
- class Project
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter first hero's name: ");
- String nameFirst = Console.ReadLine();
- Console.WriteLine("Enter first herp's HP: ");
- int hpFirst = int.Parse(Console.ReadLine());
- Console.WriteLine("Enter first hero's attack damage: ");
- int dmgFirst = int.Parse(Console.ReadLine());
- Hero firstHero = new Hero(nameFirst, hpFirst, dmgFirst);
- firstHero.speed = 0.5;
- Console.WriteLine("Enter second hero's name: ");
- String nameSecond = Console.ReadLine();
- Console.WriteLine("Enter second hero's HP: ");
- int hpSecond = int.Parse(Console.ReadLine());
- Console.WriteLine("Enter second hero's attack damage: ");
- int dmgSecond = int.Parse(Console.ReadLine());
- Hero secondHero = new Hero(nameSecond, hpSecond, dmgSecond);
- secondHero.speed = 0.4;
- firstHero.Fight(secondHero);
- Console.ReadKey();
- }
- }
- class Hero
- {
- //properties
- public string name;
- public int health;
- public int damage;
- public double speed;
- Random rand = new Random();
- //constructor
- public Hero(string name,int health,int damage)
- {
- this.name = name;
- this.health = health;
- this.damage = damage;
- }
- public void GetStats()
- {
- Console.WriteLine("Hero: " + name + " | Health: " + health + " | Damage: " + damage);
- }
- public void Attack(Hero enemy)
- {
- Thread.Sleep(1000);
- rand = new Random();
- int randomDefence = rand.Next(4);
- if(randomDefence != 1)
- {
- Console.WriteLine(this.name + " attacks " + enemy.name + " for " + this.damage);
- Console.WriteLine(enemy.name + " has.. " + enemy.health + " HP left.");
- enemy.health -= this.damage;
- }
- else
- {
- Console.BackgroundColor = ConsoleColor.DarkRed;
- Console.WriteLine(enemy.name + "blocked " + this.name + "'s attack.");
- }
- }
- public void Fight(Hero enemy)
- {
- while(this.health > 0 && enemy.health > 0)
- {
- if(this.speed > enemy.speed)
- {
- Console.BackgroundColor = ConsoleColor.DarkBlue;
- this.Attack(enemy);
- Console.BackgroundColor = ConsoleColor.DarkGreen;
- enemy.Attack(this);
- }
- else
- {
- Console.BackgroundColor = ConsoleColor.DarkGreen;
- enemy.Attack(this);
- Console.BackgroundColor = ConsoleColor.DarkBlue;
- this.Attack(enemy);
- }
- }
- if(this.health > enemy.health)
- {
- Console.WriteLine("You have WON the fight against " + enemy.name);
- }
- else
- {
- Console.BackgroundColor = ConsoleColor.Red;
- Console.WriteLine("You have LOST the battle against " + enemy.name);
- }
- this.GetStats();
- enemy.GetStats();
- }
- }
- }
Add Comment
Please, Sign In to add comment