Advertisement
Guest User

Untitled

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