Advertisement
TwinFrame

Class_Palyer_name_armor_damage

Jan 21st, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clight_21_OOP_ClassPlayer
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Player playerTeamA = new Player();
  10. int heightPlayerStats = 7;
  11.  
  12. while (true)
  13. {
  14. playerTeamA.ShowStat();
  15. int stepDamage;
  16. int stepArmor;
  17. stepDamage = checkInputUser("Введите силу удара", 100, heightPlayerStats, 0);
  18. stepArmor = checkInputUser("Введите степень защиты", 100, heightPlayerStats, 1);
  19. playerTeamA.Armor = stepArmor;
  20. playerTeamA.TakeDamage(stepDamage);
  21. if (playerTeamA.Health <= 0)
  22. {
  23. Console.SetCursorPosition(0, 11);
  24. Console.WriteLine("Вы победили соперника в неравном бою. Пока!");
  25. Console.ReadKey();
  26. Environment.Exit(0);
  27. }
  28. Console.Clear();
  29. }
  30.  
  31. }
  32. public static int checkInputUser(string text, int maxValue, int cursorY, int plusY)
  33. {
  34. bool goodInputUser = false;
  35. bool badCheckInput = true;
  36. int value = 0;
  37.  
  38. while (badCheckInput)
  39. {
  40. Console.SetCursorPosition(0, cursorY + plusY);
  41. Console.Write($"{text}. Максимум {maxValue}: ");
  42. goodInputUser = Int32.TryParse(Console.ReadLine(), out int goodValue);
  43.  
  44. if (goodInputUser != true)
  45. {
  46. Console.SetCursorPosition(0, cursorY + 5);
  47. Console.Write("Введите корректное число.");
  48. Console.ReadKey();
  49. Console.SetCursorPosition(0, cursorY + plusY);
  50. Console.Write(" ");
  51. Console.SetCursorPosition(0, cursorY + 5);
  52. Console.Write(" ");
  53. }
  54. else if (goodInputUser && goodValue > maxValue)
  55. {
  56. value = maxValue;
  57. badCheckInput = false;
  58. }
  59. else if (goodInputUser)
  60. {
  61. value = goodValue;
  62. badCheckInput = false;
  63. }
  64. }
  65. return value;
  66. }
  67. }
  68.  
  69. class Player
  70. {
  71. public string Name;
  72. public char Avatar;
  73. public float Health;
  74. public int Armor;
  75. public int Damage;
  76.  
  77.  
  78. public Player(string name, char avatar, int healht, int armor, int damage)
  79. {
  80. Name = name;
  81. Avatar = avatar;
  82. Health = healht;
  83. Armor = armor;
  84. Damage = damage;
  85. }
  86.  
  87. public Player()
  88. {
  89. Name = "Player";
  90. Avatar = '#';
  91. Health = 300;
  92. Armor = 30;
  93. Damage = 100;
  94. }
  95.  
  96. public void ShowStat()
  97. {
  98. Console.WriteLine($"Жизни: {Health}\nИгрок: {Name}\nАватар: {Avatar}\nЗащита: {Armor}\nУрон: {Damage}\n");
  99. }
  100.  
  101. public void TakeDamage(int damage)
  102. {
  103. float armorWeight = 1 - Convert.ToSingle(Armor) / 100;
  104. Health -= damage * armorWeight;
  105. }
  106.  
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement