Advertisement
Guest User

Untitled

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