Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication5
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Hero player1 = new Hero("Raiden", 120, 1000);
  14. Hero player2 = new Hero("Scorpion", 80, 800);
  15. Hero player3 = new Hero("SubZero", 85, 720);
  16.  
  17. player2.fight(player3);
  18.  
  19. Console.ReadLine();
  20. }
  21. }
  22.  
  23. class Hero
  24. {
  25. // properties
  26. string name;
  27. int power;
  28. int health;
  29.  
  30. // constructor
  31. public Hero(string nName, int nPower, int nHealth)
  32. {
  33. name = nName;
  34. power = nPower;
  35. health = nHealth;
  36. }
  37.  
  38. public void fight(Hero enemy) {
  39. while (health > 0 && enemy.health > 0)
  40. {
  41. Console.WriteLine(name + " hit " + enemy.name + " for " + power);
  42. enemy.health -= power;
  43. Console.WriteLine(enemy.name + " hit " + name + " for " + enemy.power);
  44. health -= enemy.power;
  45.  
  46. Console.WriteLine("Player 1 : " + health + " vs " + enemy.health + " Player 2");
  47.  
  48. Console.ReadKey();
  49. }
  50.  
  51. if (health > enemy.health)
  52. {
  53. Console.WriteLine("The winner is " + name + "("+health+")");
  54. }
  55. else
  56. {
  57. Console.WriteLine("The winner is " + enemy.name + "(" + health + ")");
  58. }
  59.  
  60. }
  61.  
  62. }
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement