Advertisement
Guest User

4. Доп.ДЗ

a guest
May 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.57 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace Delegates
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int Health = 1000;
  11.             int Armor = 20;
  12.  
  13.             string[] arrAttaksString = { "Босс атаковал с немыслимой яростью своими руками", "Босс исполнил новый альбом Ольги Бузовой", "Босс паник и рассказал вам о своём долгом пути и дал пару советов, после выпил ритуальный стопарь боярки" };
  14.             ConsoleColor[] arrAttaksColor = { ConsoleColor.DarkRed, ConsoleColor.DarkMagenta, ConsoleColor.DarkGray };
  15.             int[] arrAttaksDamage = { 100, 140, 80 };
  16.  
  17.             bool isRandomAttack = (DateTime.Now.Millisecond % 2) == 0;
  18.             int attackNumber = -1;
  19.  
  20.             showMessage(ConsoleColor.Yellow, "Босс может атаковать в двух режимах: все атаки по очереди и случайной атакой" +
  21.                 "\nБосс будет атаковать: " + (isRandomAttack ? "случайно" : "все атаки по очереди"));
  22.             showMessage(ConsoleColor.Green, "Нажмите enter для начала боя");
  23.             Console.ReadLine();
  24.  
  25.             while (Health > 0)
  26.             {
  27.                 Console.Clear();
  28.  
  29.                 showMessage(ConsoleColor.Red, "У вас здоровья: " + Health);
  30.  
  31.                 if (isRandomAttack)
  32.                 {
  33.                     attackNumber = DateTime.Now.Millisecond % 3;
  34.                 }
  35.                 else
  36.                 {
  37.                     attackNumber++;
  38.                     if (attackNumber > 2)
  39.                     {
  40.                         attackNumber = 0;
  41.                     }
  42.                 }
  43.  
  44.                 showMessage(arrAttaksColor[attackNumber], arrAttaksString[attackNumber], arrAttaksDamage[attackNumber]);
  45.                 Thread.Sleep(4000);
  46.             }
  47.  
  48.             showMessage(ConsoleColor.DarkGray, "Бой закончен, вы погибли");
  49.             Console.ReadKey();
  50.  
  51.             void showMessage(ConsoleColor consColor, string Message, int Damage = 0)
  52.             {
  53.                 ConsoleColor oldColor = Console.ForegroundColor;
  54.                 Console.ForegroundColor = consColor;
  55.                 Console.WriteLine(Message);
  56.                 Console.ForegroundColor = oldColor;
  57.                 Health = Health - (Damage - Armor);
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement