Advertisement
TwinFrame

Gladiators question 2

Feb 6th, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.97 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Clight_26_OOP_GladiaotorFight
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int maxArmor = 100;
  10. while (true)
  11. {
  12.  
  13. Console.CursorVisible = false;
  14. Gladiator gladiator1 = new Gal("Нормус", 500, 80, 20, maxArmor);
  15. Gladiator gladiator2 = new Velit("Кникс", 500, 50, 40, maxArmor);
  16. Gladiator gladiator3 = new Gal("Галей", 500, 100, 10, maxArmor);
  17. Gladiator gladiator4 = new Velit("Бомбус", 500, 40, 50, maxArmor);
  18. Gladiator gladiator5 = new Velit("Фергнус", 500, 45, 45, maxArmor);
  19.  
  20. Gladiators gladiators = new Gladiators(new Gladiator[] { gladiator1, gladiator2, gladiator3, gladiator4, gladiator5 });
  21.  
  22. Console.WriteLine("Номер Тип Имя Жизни Сила Броня\n");
  23. gladiators.ShowAllGladiators();
  24.  
  25. int firstNumGladiator = checkUserInput("\nВыберите первого бойца для поединка", gladiators);
  26. int secondNumGladiator = checkUserInput("\nВыберите второго бойца для поединка", gladiators, firstNumGladiator);
  27.  
  28. Gladiator firstGladiator = gladiators.GetGladiator(firstNumGladiator);
  29. Gladiator secondGladiator = gladiators.GetGladiator(secondNumGladiator);
  30.  
  31. while (firstGladiator.GetHealth() > 0 && secondGladiator.GetHealth() > 0)
  32. {
  33. Console.WriteLine();
  34.  
  35. Console.ForegroundColor = ConsoleColor.Red;
  36. secondGladiator.TakeHealth(firstGladiator.GiveDamage(), maxArmor);
  37.  
  38. Console.ForegroundColor = ConsoleColor.Green;
  39. firstGladiator.TakeHealth(secondGladiator.GiveDamage(), maxArmor);
  40.  
  41. Console.ForegroundColor = ConsoleColor.White;
  42. firstGladiator.ShowCutInfo();
  43. secondGladiator.ShowCutInfo();
  44.  
  45. Console.WriteLine();
  46. Console.ReadKey();
  47. }
  48.  
  49. Console.WriteLine();
  50. if (firstGladiator.GetHealth() < 0 && secondGladiator.GetHealth() < 0)
  51. {
  52. Console.WriteLine("Ничья");
  53. }
  54. else if (firstGladiator.GetHealth() >= 0 && secondGladiator.GetHealth() < 0)
  55. {
  56. Console.WriteLine($"Выиграл гладиотор {firstGladiator.GetName()}");
  57. }
  58. else if (firstGladiator.GetHealth() < 0 && secondGladiator.GetHealth() >= 0)
  59. {
  60. Console.WriteLine($"Выиграл гладиотор {secondGladiator.GetName()}");
  61. }
  62. else
  63. {
  64. Console.WriteLine("Произошло не понятное и бой прервался на самом интересном месте");
  65. }
  66.  
  67. bool isPlay = true;
  68. char userInput = checkUserInput("\nХотите сыграть еще?\nY - да, N - нет", ref isPlay);
  69.  
  70. if (true)
  71. {
  72. Console.Clear();
  73. }
  74. else
  75. {
  76. Environment.Exit(0);
  77. }
  78. }
  79. }
  80.  
  81. static int checkUserInput(string text, Gladiators gladiators)
  82. {
  83. bool successCheck = false;
  84. int successNum = 0;
  85.  
  86. while (successCheck == false)
  87. {
  88. Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 2);
  89. Console.Write(text + ": ");
  90. string currentNumGladiator = Console.ReadLine();
  91.  
  92. bool success = Int32.TryParse(currentNumGladiator, out int num);
  93.  
  94. if (success != true || num > gladiators.GetLenghtGladiators() || num <= 0)
  95. {
  96. Console.Write("Укажите корректный номер гладиатора");
  97. Console.ReadKey();
  98. Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 3);
  99. Console.WriteLine(" ");
  100. Console.WriteLine(" ");
  101. }
  102. else
  103. {
  104. successNum = num - 1;
  105. successCheck = true;
  106. }
  107. }
  108. return successNum;
  109. }
  110.  
  111. static int checkUserInput(string text, Gladiators gladiators, int numEnemy)
  112. {
  113. bool successCheck = false;
  114. int successNum = 0;
  115.  
  116. while (successCheck == false)
  117. {
  118. Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 3);
  119. Console.Write(text + ": ");
  120. string currentNumGladiator = Console.ReadLine();
  121.  
  122. bool success = Int32.TryParse(currentNumGladiator, out int num);
  123.  
  124. if (numEnemy == num - 1)
  125. {
  126. string duplicateName = gladiators.GetGladiator(numEnemy).GetName();
  127. Console.Write($"Гладиатор по имени {duplicateName} уже выбран");
  128. Console.ReadKey();
  129. Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 4);
  130. Console.WriteLine(" ");
  131. Console.WriteLine(" ");
  132.  
  133. }
  134. else if (success != true || num > gladiators.GetLenghtGladiators() || num <= 0)
  135. {
  136.  
  137. Console.Write("Укажите корректный номер гладиатора");
  138. Console.ReadKey();
  139. Console.SetCursorPosition(0, gladiators.GetLenghtGladiators() + 4);
  140. Console.WriteLine(" ");
  141. Console.WriteLine(" ");
  142. }
  143. else
  144. {
  145. successNum = num - 1;
  146. successCheck = true;
  147. }
  148. }
  149. return successNum;
  150. }
  151.  
  152. static char checkUserInput(string text, ref bool isPlay)
  153. {
  154. bool goodCheck = false;
  155. char symbolUser = ' ';
  156. while (goodCheck != true)
  157. {
  158.  
  159. Console.Write(text + ": ");
  160. string currentNumGladiator = Console.ReadLine();
  161.  
  162. bool success = Char.TryParse(currentNumGladiator, out char symbol);
  163.  
  164. if (success != true)
  165. {
  166. Console.WriteLine("\nНе понятно");
  167.  
  168. }
  169. else if (symbol == 'Y' || symbol == 'y' || symbol == 'Н' || symbol == 'н')
  170. {
  171. symbolUser = 'Y';
  172. goodCheck = true;
  173. }
  174. else if (symbol == 'N' || symbol == 'n' || symbol == 'Т' || symbol == 'т')
  175. {
  176. symbolUser = 'N';
  177. isPlay = false;
  178. goodCheck = true;
  179. }
  180. else
  181. {
  182. Console.WriteLine("\nНажали не ту клавишу");
  183. }
  184. }
  185. return symbolUser;
  186. }
  187. }
  188.  
  189. class Gladiator
  190. {
  191. protected string _name;
  192. protected double _health;
  193. protected int _damage;
  194. protected double _armor;
  195.  
  196. Random random = new Random();
  197.  
  198. public Gladiator(string name, double health, int damage, double armor, int maxArmor)
  199. {
  200. _name = name;
  201. _health = health;
  202. _damage = damage;
  203.  
  204. if (armor > maxArmor)
  205. {
  206. _armor = maxArmor;
  207. }
  208. else
  209. {
  210. _armor = armor;
  211. }
  212. }
  213.  
  214. public void ShowInfo()
  215. {
  216. Console.WriteLine($"{_name} {_health} {_damage} {_armor}");
  217. }
  218.  
  219. public void ShowCutInfo()
  220. {
  221. Console.WriteLine($"{_name} {_health}");
  222. }
  223.  
  224.  
  225. public virtual void TakeHealth(double damage, int maxArmor)
  226. {
  227. double currentArmor = 1 - (_armor / maxArmor);
  228. _health -= Math.Round(damage * currentArmor, 0);
  229. }
  230.  
  231. public virtual double GiveDamage()
  232. {
  233. int text = random.Next(0, 4);
  234.  
  235. int weightDamage = random.Next(-20, 21);
  236.  
  237. double currentDamage = _damage + _damage * weightDamage / 100;
  238.  
  239. if (text == 0)
  240. {
  241. Console.WriteLine($"{_name} нанес удар");
  242. }
  243. else if (text == 1)
  244. {
  245. Console.WriteLine($"{_name} ударил в торс");
  246. }
  247. else if (text == 2)
  248. {
  249. Console.WriteLine($"попал {_name} по голове");
  250. }
  251. else
  252. {
  253. Console.WriteLine($"{_name} провел удар");
  254. }
  255.  
  256. return currentDamage;
  257. }
  258.  
  259. public double GetHealth()
  260. {
  261. return _health;
  262. }
  263.  
  264. public string GetName()
  265. {
  266. return _name;
  267. }
  268. }
  269.  
  270. class Gal : Gladiator
  271. {
  272. Random random = new Random(222);
  273. public Gal(string name, double health, int damage, double armor, int maxArmor) : base(name, health, damage, armor, maxArmor)
  274. { }
  275.  
  276. public override double GiveDamage()
  277. {
  278. double currentDamage;
  279. int weightDamage = random.Next(-20, 21);
  280.  
  281. int force = random.Next(1, 3);
  282. if (force == 2)
  283. {
  284. force = random.Next(1, 3);
  285. }
  286.  
  287. if (force == 2)
  288. {
  289. currentDamage = _damage * force;
  290. Console.ForegroundColor = ConsoleColor.Yellow;
  291. Console.WriteLine($"{_name} нанес удар с двойной силой");
  292. Console.ForegroundColor = ConsoleColor.White;
  293. }
  294. else
  295. {
  296. currentDamage = _damage + _damage * weightDamage / 100;
  297.  
  298. int text = random.Next(0, 4);
  299. if (text == 0)
  300. {
  301. Console.WriteLine($"{_name} нанес удар");
  302. }
  303. else if (text == 1)
  304. {
  305. Console.WriteLine($"{_name} ударил в торс");
  306. }
  307. else if (text == 2)
  308. {
  309. Console.WriteLine($"попал {_name} по голове");
  310. }
  311. else
  312. {
  313. Console.WriteLine($"{_name} провел удар");
  314. }
  315. }
  316.  
  317. return currentDamage;
  318. }
  319. }
  320.  
  321. class Velit : Gladiator
  322. {
  323. Random random = new Random(333);
  324.  
  325. public Velit(string name, double health, int damage, double armor, int maxArmor) : base(name, health, damage, armor, maxArmor)
  326. { }
  327.  
  328. public double GiveDamage()
  329. {
  330. double currentDamage = 0;
  331. return currentDamage;
  332. }
  333.  
  334. public override void TakeHealth(double damage, int maxArmor)
  335. {
  336. int block = random.Next(0, 2);
  337. if (block == 0)
  338. {
  339. block = random.Next(0, 2);
  340. if (block == 0)
  341. {
  342. Console.ForegroundColor = ConsoleColor.Yellow;
  343. Console.WriteLine($"{_name} поставил блок");
  344. Console.ForegroundColor = ConsoleColor.White;
  345. }
  346. }
  347.  
  348. double currentArmor = (1 - (_armor / maxArmor)) * block;
  349. _health -= Math.Round(damage * currentArmor, 0);
  350. }
  351. }
  352.  
  353. class Gladiators
  354. {
  355. protected Gladiator[] _gladiators;
  356.  
  357. public Gladiators(Gladiator[] gladiators)
  358. {
  359. _gladiators = gladiators;
  360. }
  361.  
  362. public void ShowAllGladiators()
  363. {
  364. for (int i = 0; i < _gladiators.Length; i++)
  365. {
  366. Console.Write($"{i + 1} {_gladiators[i].GetType().Name} ");
  367. _gladiators[i].ShowInfo();
  368. }
  369. }
  370.  
  371. public Gladiator GetGladiator(int num)
  372. {
  373. return _gladiators[num];
  374. }
  375.  
  376. public int GetLenghtGladiators()
  377. {
  378. return _gladiators.Length;
  379. }
  380. }
  381. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement