Advertisement
TwinFrame

Gladiators workVersion

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