Advertisement
SaNik74

gladiator_fights

Aug 19th, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. using System.Security.Cryptography.X509Certificates;
  2.  
  3. namespace gladiator_fights
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Arena arena = new Arena();
  10.  
  11. arena.Work();
  12. }
  13. }
  14.  
  15. class Healer
  16. {
  17. public Healer(int health = 150, int damage = 10, int rage = 0, string name = "Целитель")
  18. {
  19. Health = health;
  20. Damage = damage;
  21. Rage = rage;
  22. Name = name;
  23. }
  24.  
  25. public int Health { get; private set; }
  26. public int Damage { get; private set; }
  27. public int Rage { get; private set; }
  28. public string Name { get; private set; }
  29.  
  30. public int Attack()
  31. {
  32. return Damage;
  33. }
  34.  
  35. public void TakeDamage(int enemyDamage)
  36. {
  37. Health -= enemyDamage;
  38.  
  39. RageRegen();
  40. Heal();
  41. }
  42.  
  43. private void RageRegen()
  44. {
  45. int maxPointOfRageRegen = 8;
  46. int minPointOfRageRegen = 7;
  47. int pointOfRageRegen = UserUnits.GenerateRandomNumber(minPointOfRageRegen, maxPointOfRageRegen);
  48.  
  49. Rage += pointOfRageRegen;
  50.  
  51. if (Rage > 100) Rage = 100;
  52. }
  53.  
  54. public void Heal()
  55. {
  56. int pointOfHeal = 50;
  57.  
  58. if (Rage == 100)
  59. {
  60. Health += pointOfHeal;
  61. Rage = 0;
  62. }
  63.  
  64. if (Health > 150) Health = 150;
  65. }
  66. }
  67.  
  68. class Dredevil
  69. {
  70. private int _numerAttack = 0;
  71. private int _numberForDoubleAttack = 3;
  72.  
  73. public Dredevil(int health = 150, int damage = 10, string name = "Смельчак")
  74. {
  75. Health = health;
  76. Damage = damage;
  77. Name = name;
  78. }
  79.  
  80. public int Health { get; private set; }
  81. public int Damage { get; private set; }
  82. public string Name { get; private set; }
  83.  
  84. public int Attack()
  85. {
  86. _numerAttack++;
  87.  
  88. if (_numerAttack == _numberForDoubleAttack)
  89. {
  90. _numberForDoubleAttack = 0;
  91.  
  92. return Damage * 2;
  93. }
  94.  
  95. return Damage;
  96. }
  97.  
  98. public void TakeDamage(int enemyDamage)
  99. {
  100. Health -= enemyDamage;
  101. }
  102. }
  103.  
  104. class LuckyGuy
  105. {
  106. private int _numberForChanceDodge = 1;
  107.  
  108. public LuckyGuy(int health = 150, int damage = 10, string name = "Проныра")
  109. {
  110. Health = health;
  111. Damage = damage;
  112. Name = name;
  113. }
  114.  
  115. public int Health { get; private set; }
  116. public int Damage { get; private set; }
  117. public string Name { get; private set; }
  118.  
  119. public int Attack()
  120. {
  121. return Damage;
  122. }
  123.  
  124. public void TakeDamage(int enemyDamage)
  125. {
  126. if (IsDodge() == true) return;
  127.  
  128. Health -= enemyDamage;
  129. }
  130.  
  131. private bool IsDodge()
  132. {
  133. bool isDodge = false;
  134. int minRandomNumber = 1;
  135. int maxRandomNumber = 11;
  136.  
  137. if (_numberForChanceDodge == UserUnits.GenerateRandomNumber(minRandomNumber, maxRandomNumber)) return true;
  138.  
  139. return isDodge;
  140. }
  141. }
  142.  
  143. class Warlock
  144. {
  145. private int _manaNeedForFireBallAttack = 20;
  146.  
  147. public Warlock(int health = 150, int damage = 10, int damageForFireBall = 18, int mana = 100, string name = "Чернокнижник")
  148. {
  149. Health = health;
  150. Damage = damage;
  151. DamageForFireBall = damageForFireBall;
  152. Mana = mana;
  153. Name = name;
  154. }
  155.  
  156. public int Health { get; private set; }
  157. public int Damage { get; private set; }
  158. public int DamageForFireBall { get; private set; }
  159. public int Mana { get; private set; }
  160. public string Name { get; private set; }
  161.  
  162. public int Attack()
  163. {
  164. if (IsManaEnough()) return DamageForFireBall;
  165.  
  166. return Damage;
  167. }
  168.  
  169. public void TakeDamage(int enemyDamage)
  170. {
  171. Health -= enemyDamage;
  172. }
  173.  
  174. private bool IsManaEnough()
  175. {
  176. if (Mana >= _manaNeedForFireBallAttack)
  177. {
  178. Mana -= _manaNeedForFireBallAttack;
  179.  
  180. return true;
  181. }
  182.  
  183. return false;
  184. }
  185. }
  186.  
  187. class Knight
  188. {
  189. private int _numberForCriticalAttack = 1;
  190.  
  191. public Knight(int health = 150, int damage = 10, string name = "Рыцарь")
  192. {
  193. Health = health;
  194. Damage = damage;
  195. Name = name;
  196. }
  197.  
  198. public int Health { get; private set; }
  199. public int Damage { get; private set; }
  200. public string Name { get; private set; }
  201.  
  202. public int Attack()
  203. {
  204. if (IsChanseCriticalAttack()) return Damage * 2;
  205.  
  206. return Damage;
  207. }
  208.  
  209. public void TakeDamage(int enemyDamage)
  210. {
  211. Health -= enemyDamage;
  212. }
  213.  
  214. private bool IsChanseCriticalAttack()
  215. {
  216. bool isAttack = false;
  217. int minRandomNumber = 1;
  218. int maxRandomNumber = 11;
  219.  
  220. if (_numberForCriticalAttack == UserUnits.GenerateRandomNumber(minRandomNumber, maxRandomNumber)) return true;
  221.  
  222. return isAttack;
  223. }
  224. }
  225.  
  226. class Arena
  227. {
  228. public void Work()
  229. {
  230. dynamic fighterOne = ChooseFighter();
  231. dynamic fighterTwo = ChooseFighter();
  232.  
  233. Fight(fighterOne, fighterTwo);
  234. }
  235.  
  236. private void Fight(dynamic fighterOne, dynamic fighterTwo)
  237. {
  238. Console.Clear();
  239.  
  240. ShowInfo(fighterOne, fighterTwo);
  241.  
  242. while (fighterOne.Health > 0 && fighterTwo.Health > 0)
  243. {
  244. fighterTwo.TakeDamage(fighterOne.Attack());
  245.  
  246. ShowInfo(fighterOne, fighterTwo);
  247.  
  248. if (fighterTwo.Health <= 0)
  249. {
  250. Console.WriteLine($"{fighterOne.Name} победил.");
  251. return;
  252. }
  253.  
  254. fighterOne.TakeDamage(fighterTwo.Attack());
  255.  
  256. ShowInfo(fighterOne, fighterTwo);
  257. }
  258.  
  259. if (fighterOne.Health <= 0)
  260. {
  261. Console.WriteLine($"Игрок 2 {fighterTwo.Name} победил.");
  262. }
  263. else
  264. {
  265. Console.WriteLine($"Игрок 1 {fighterOne.Name} победил.");
  266. }
  267. }
  268.  
  269. private void ShowInfo(dynamic fighter, dynamic fighterTwo)
  270. {
  271. Console.WriteLine($"У 1 игрока {fighter.Name} осталось {fighter.Health} жизней.");
  272. Console.WriteLine($"У 2 игрока {fighterTwo.Name} осталось {fighterTwo.Health} жизней.");
  273. Console.ReadKey();
  274. Console.Clear();
  275. }
  276.  
  277. private dynamic ChooseFighter()
  278. {
  279. const int ChooseKnightCommand = 1;
  280. const int ChooseHealerCommand = 2;
  281. const int ChooseDredevilCommand = 3;
  282. const int ChooseWarlockCommand = 4;
  283. const int ChooseLuckyGuyCommand = 5;
  284.  
  285. Knight knight = new Knight();
  286. Healer healer = new Healer();
  287. Dredevil dredevil = new Dredevil();
  288. Warlock warlock = new Warlock();
  289. LuckyGuy luckyGuy = new LuckyGuy();
  290.  
  291. Console.Clear();
  292.  
  293. Console.WriteLine($"Выберете персонажа:'\n" +
  294. $"1. {knight.Name}\n" +
  295. $"2. {healer.Name}\n" +
  296. $"3. {dredevil.Name}\n" +
  297. $"4. {warlock.Name}\n" +
  298. $"5. {luckyGuy.Name}");
  299.  
  300. int userInput = UserUnits.ReadNumber();
  301.  
  302. switch (userInput)
  303. {
  304. case ChooseKnightCommand:
  305. return knight;
  306.  
  307. case ChooseHealerCommand:
  308. return healer;
  309.  
  310. case ChooseDredevilCommand:
  311. return dredevil;
  312.  
  313. case ChooseWarlockCommand:
  314. return warlock;
  315.  
  316. case ChooseLuckyGuyCommand:
  317. return luckyGuy;
  318.  
  319. default:
  320. Console.WriteLine("Вы ввели не верную команду.");
  321. break;
  322. }
  323.  
  324. return null;
  325. }
  326. }
  327.  
  328. class UserUnits
  329. {
  330. private static Random s_random = new Random();
  331.  
  332. public static int GenerateRandomNumber(int min, int max)
  333. {
  334. return s_random.Next(min, max);
  335. }
  336.  
  337. public static int ReadNumber()
  338. {
  339. bool isNumber = false;
  340. int result = 0;
  341.  
  342. while (isNumber == false)
  343. {
  344. if (int.TryParse(Console.ReadLine(), out result))
  345. {
  346. return result;
  347. }
  348. }
  349.  
  350. return result;
  351. }
  352. }
  353. }
  354.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement