Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.68 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.AllAttacks = 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)
  45.         {
  46.             player.Health = player.Health - (Damage - armor);
  47.         }
  48.        
  49.     }
  50.     public class Boss
  51.     {
  52.         public int attackNumber = 0;
  53.         public bool isRandomAttack = (DateTime.Now.Millisecond % 2) == 0;
  54.         int rand = DateTime.Now.Millisecond % 3;
  55.         public Attack[] AllAttacks = new Attack[0];
  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);
  60.         }
  61.         public ConsoleColor GetColor()
  62.         {
  63.             ConsoleColor userInputColor = ConsoleColor.White;
  64.             string color = Console.ReadLine();
  65.             switch (color.ToLower())
  66.             {
  67.                 case "красный":
  68.                     userInputColor = ConsoleColor.Red;
  69.                     break;
  70.                 case "зеленый":
  71.                     userInputColor = ConsoleColor.Green;
  72.                     break;
  73.                 case "синий":
  74.                     userInputColor = ConsoleColor.Blue;
  75.                     break;
  76.                 case "желтый":
  77.                     userInputColor = ConsoleColor.Yellow;
  78.                     break;
  79.                 case "белый":
  80.                     userInputColor = ConsoleColor.White;
  81.                     break;
  82.                 case "серый":
  83.                     userInputColor = ConsoleColor.Gray;
  84.                     break;
  85.             }
  86.             return userInputColor;
  87.         }
  88.         public Attack[] CreateBossAttack(MessageForUser message, Battlefield field)
  89.         {
  90.             Attack[] ArrayAttacks = new Attack[0];
  91.             while (ArrayAttacks.Length < 3)
  92.             {
  93.                 Console.Clear();
  94.                 message.PrintTheMessage(ConsoleColor.Yellow, "Босс может атаковать в двух режимах: все атаки по очереди и случайной атакой");
  95.                 message.PrintTheMessage(ConsoleColor.Yellow, "Босс будет атаковать: " + (isRandomAttack ? "случайно" : "все атаки по очереди"));
  96.                 message.PrintTheMessage(ConsoleColor.White, "Перед началом боя необходимо создать три атаки босса со своим текстом, цветом и урном. Приступим:");
  97.  
  98.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите название " + (ArrayAttacks.Length + 1) + " атаки:");
  99.                 string nameAttack = Console.ReadLine();
  100.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите текст " + (ArrayAttacks.Length + 1) + " атаки:");
  101.                 string textAttack = Console.ReadLine();
  102.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите урон " + (ArrayAttacks.Length + 1) + " атаки:");
  103.                 int.TryParse(Console.ReadLine(), out int damageAttack);
  104.                 message.PrintTheMessage(ConsoleColor.Cyan, "Введите цвет текста " + (ArrayAttacks.Length + 1) + " атаки" +
  105.                     "\nДоступные цвета: красный, зеленый, синий, желтый, белый, серый");
  106.  
  107.                 Attack[] CreateNewAttack = new Attack[ArrayAttacks.Length + 1];
  108.                 for(int i = 0; i < ArrayAttacks.Length; i++) { CreateNewAttack[i] = ArrayAttacks[i]; }
  109.                 CreateNewAttack[CreateNewAttack.Length-1] = new Attack(nameAttack, textAttack, damageAttack);
  110.                 ArrayAttacks = CreateNewAttack;
  111.                 ArrayAttacks[ArrayAttacks.Length - 1].Color = GetColor();
  112.             }
  113.             message.PrintTheMessage(ConsoleColor.Green, "Нажмите enter для начала боя");
  114.             return ArrayAttacks;
  115.         }
  116.         public void NextAttack(MessageForUser message, User player)
  117.         {
  118.             if (isRandomAttack)
  119.             {
  120.                 Apply(rand, message, player);
  121.             }
  122.             else
  123.             {
  124.                 Apply(attackNumber, message, player);
  125.  
  126.                 attackNumber += 1;
  127.                 if (attackNumber > 2)
  128.                 {
  129.                     attackNumber = 0;
  130.                 }
  131.             }
  132.         }
  133.     }
  134.     public class Battlefield
  135.     {
  136.         User Player;
  137.         Boss ThisBoss;
  138.        
  139.        
  140.         public Battlefield(User player, Boss boss)
  141.         {
  142.             Player = player;
  143.             ThisBoss = boss;
  144.         }
  145.         public void Fight(MessageForUser message)
  146.         {
  147.             while (Player.Health > 0)
  148.             {
  149.                 Console.Clear();
  150.                 Console.WriteLine("Атаки босса:");
  151.                 foreach (var element in ThisBoss.AllAttacks)
  152.                 {
  153.                     Console.Write(element.NameAttack + "|");
  154.                 }
  155.                 Console.WriteLine();
  156.                 message.PrintTheMessage(ConsoleColor.Red, "У вас здоровья: " + Player.Health);
  157.                 ThisBoss.NextAttack(message, Player);
  158.                 Thread.Sleep(3000);
  159.             }
  160.             message.PrintTheMessage(ConsoleColor.DarkGreen, "Бой окончен, Вы погибли");
  161.         }
  162.        
  163.     }
  164.  
  165.     public class User
  166.     {
  167.         public int Health { get; set; } = 1000;
  168.         public int Armor { get; } = 20;
  169.     }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement