Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.35 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace BossAttack
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             User Player = new User();
  11.             MessageForUser Message = new MessageForUser();
  12.             Boss Pavel = new Boss();
  13.             Battlefield Field = new Battlefield(Player, Pavel);
  14.            
  15.             Pavel.CreateBossAttack(Message, Field);
  16.             Field.Fight(Message);
  17.         }
  18.     }
  19.     public class MessageForUser
  20.     {
  21.         public void PrintTheMessage(ConsoleColor color, string message)
  22.         {
  23.             ConsoleColor oldColor = Console.ForegroundColor;
  24.             Console.ForegroundColor = color;
  25.             Console.WriteLine(message);
  26.             Console.ForegroundColor = oldColor;
  27.         }
  28.  
  29.     }
  30.     public class Attack
  31.     {
  32.         public string NameAttack;
  33.         public string TextAttack;
  34.         public int Damage;
  35.         public ConsoleColor Color;
  36.  
  37.        
  38.         public Attack(string nameAttack, string textAttack, int damage)
  39.         {
  40.             NameAttack = nameAttack;
  41.             TextAttack = textAttack;
  42.             Damage = damage;
  43.         }
  44.         public void BossAttacks(User player, int armor, int forceAttack)
  45.         {
  46.             player.Health = player.Health - (forceAttack - armor);
  47.         }
  48.        
  49.     }
  50.     public class Boss
  51.     {
  52.         public int attackNumber = 0;
  53.         public bool isRandomAttack = (DateTime.Now.Millisecond % 2) == 0;
  54.         public int countAttack = 0;
  55.         public Attack[] AllAttacks = new Attack[3];
  56.         public void Apply(int number, MessageForUser message, User player)
  57.         {
  58.             message.PrintTheMessage(AllAttacks[number].Color, AllAttacks[number].TextAttack);
  59.             AllAttacks[number].BossAttacks(player, player.Armor, AllAttacks[number].Damage);
  60.         }
  61.         public void SelectColorText(ref ConsoleColor userInputColor)
  62.         {
  63.             string color = Console.ReadLine();
  64.             switch (color.ToLower())
  65.             {
  66.                 case "красный":
  67.                     userInputColor = ConsoleColor.Red;
  68.                     break;
  69.                 case "зеленый":
  70.                     userInputColor = ConsoleColor.Green;
  71.                     break;
  72.                 case "синий":
  73.                     userInputColor = ConsoleColor.Blue;
  74.                     break;
  75.                 case "желтый":
  76.                     userInputColor = ConsoleColor.Yellow;
  77.                     break;
  78.                 case "белый":
  79.                     userInputColor = ConsoleColor.White;
  80.                     break;
  81.                 case "серый":
  82.                     userInputColor = ConsoleColor.Gray;
  83.                     break;
  84.             }
  85.         }
  86.         public void CreateBossAttack(MessageForUser message, Battlefield field)
  87.         {
  88.             while (countAttack < 3)
  89.             {
  90.                 Console.Clear();
  91.                 message.PrintTheMessage(ConsoleColor.Yellow, "Босс может атаковать в двух режимах: все атаки по очереди и случайной атакой");
  92.                 message.PrintTheMessage(ConsoleColor.Yellow, "Босс будет атаковать: " + (isRandomAttack ? "случайно" : "все атаки по очереди"));
  93.                 message.PrintTheMessage(ConsoleColor.White, "Перед началом боя необходимо создать три атаки босса со своим текстом, цветом и урном. Приступим:");
  94.  
  95.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите название " + (countAttack + 1) + " атаки:");
  96.                 string nameAttack = Console.ReadLine();
  97.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите текст " + (countAttack + 1) + " атаки:");
  98.                 string textAttack = Console.ReadLine();
  99.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите урон " + (countAttack + 1) + " атаки:");
  100.                 int.TryParse(Console.ReadLine(), out int damageAttack);
  101.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите цвет текста " + (countAttack + 1) + " атаки" +
  102.                     "\nДоступные цвета: красный, зеленый, синий, желтый, белый, серый");
  103.                
  104.                 AllAttacks[countAttack] = new Attack(nameAttack, textAttack, damageAttack);
  105.                 SelectColorText(ref AllAttacks[countAttack].Color);
  106.                 countAttack++;
  107.             }
  108.             message.PrintTheMessage(ConsoleColor.Green, "Нажмите enter для начала боя");
  109.         }
  110.         public void NextAttack(MessageForUser message, User player)
  111.         {
  112.             if (isRandomAttack)
  113.             {
  114.                 int rand = DateTime.Now.Millisecond % 3;
  115.                 Apply(rand, message, player);
  116.             }
  117.             else
  118.             {
  119.                 Apply(attackNumber, message, player);
  120.  
  121.                 attackNumber += 1;
  122.                 if (attackNumber > 2)
  123.                 {
  124.                     attackNumber = 0;
  125.                 }
  126.             }
  127.         }
  128.     }
  129.     public class Battlefield
  130.     {
  131.         User Player;
  132.         Boss ThisBoss;
  133.        
  134.        
  135.         public Battlefield(User player, Boss boss)
  136.         {
  137.             Player = player;
  138.             ThisBoss = boss;
  139.         }
  140.         public void Fight(MessageForUser message)
  141.         {
  142.             while (Player.Health > 0)
  143.             {
  144.                 Console.Clear();
  145.                 Console.WriteLine("Атаки босса:");
  146.                 foreach (var element in ThisBoss.AllAttacks)
  147.                 {
  148.                     Console.Write(element.NameAttack + "|");
  149.                 }
  150.                 Console.WriteLine();
  151.                 message.PrintTheMessage(ConsoleColor.Red, "У вас здоровья: " + Player.Health);
  152.                 ThisBoss.NextAttack(message, Player);
  153.                 Thread.Sleep(3000);
  154.             }
  155.             message.PrintTheMessage(ConsoleColor.DarkGreen, "Бой окончен, Вы погибли");
  156.         }
  157.        
  158.     }
  159.  
  160.     public class User
  161.     {
  162.         public int Health { get; set; } = 1000;
  163.         public int Armor { get; } = 20;
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement