Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace BossAttack
- {
- class Program
- {
- static void Main(string[] args)
- {
- User Player = new User();
- MessageForUser Message = new MessageForUser();
- Boss Pavel = new Boss();
- Battlefield Field = new Battlefield(Player, Pavel);
- Pavel.AllAttacks = Pavel.CreateBossAttack(Message, Field);
- Field.Fight(Message);
- }
- }
- public class MessageForUser
- {
- public void PrintTheMessage(ConsoleColor color, string message)
- {
- ConsoleColor oldColor = Console.ForegroundColor;
- Console.ForegroundColor = color;
- Console.WriteLine(message);
- Console.ForegroundColor = oldColor;
- }
- }
- public class Attack
- {
- public string NameAttack;
- public string TextAttack;
- public int Damage;
- public ConsoleColor Color;
- public Attack(string nameAttack, string textAttack, int damage)
- {
- NameAttack = nameAttack;
- TextAttack = textAttack;
- Damage = damage;
- }
- public void BossAttacks(User player, int armor)
- {
- player.Health = player.Health - (Damage - armor);
- }
- }
- public class Boss
- {
- public int attackNumber = 0;
- public bool isRandomAttack = (DateTime.Now.Millisecond % 2) == 0;
- int rand = DateTime.Now.Millisecond % 3;
- public Attack[] AllAttacks = new Attack[0];
- public void Apply(int number, MessageForUser message, User player)
- {
- message.PrintTheMessage(AllAttacks[number].Color, AllAttacks[number].TextAttack);
- AllAttacks[number].BossAttacks(player, player.Armor);
- }
- public ConsoleColor GetColor()
- {
- ConsoleColor userInputColor = ConsoleColor.White;
- string color = Console.ReadLine();
- switch (color.ToLower())
- {
- case "красный":
- userInputColor = ConsoleColor.Red;
- break;
- case "зеленый":
- userInputColor = ConsoleColor.Green;
- break;
- case "синий":
- userInputColor = ConsoleColor.Blue;
- break;
- case "желтый":
- userInputColor = ConsoleColor.Yellow;
- break;
- case "белый":
- userInputColor = ConsoleColor.White;
- break;
- case "серый":
- userInputColor = ConsoleColor.Gray;
- break;
- }
- return userInputColor;
- }
- public Attack[] CreateBossAttack(MessageForUser message, Battlefield field)
- {
- Attack[] ArrayAttacks = new Attack[0];
- while (ArrayAttacks.Length < 3)
- {
- Console.Clear();
- message.PrintTheMessage(ConsoleColor.Yellow, "Босс может атаковать в двух режимах: все атаки по очереди и случайной атакой");
- message.PrintTheMessage(ConsoleColor.Yellow, "Босс будет атаковать: " + (isRandomAttack ? "случайно" : "все атаки по очереди"));
- message.PrintTheMessage(ConsoleColor.White, "Перед началом боя необходимо создать три атаки босса со своим текстом, цветом и урном. Приступим:");
- message.PrintTheMessage(ConsoleColor.Cyan, "Введите название " + (ArrayAttacks.Length + 1) + " атаки:");
- string nameAttack = Console.ReadLine();
- message.PrintTheMessage(ConsoleColor.Cyan, "Введите текст " + (ArrayAttacks.Length + 1) + " атаки:");
- string textAttack = Console.ReadLine();
- message.PrintTheMessage(ConsoleColor.Cyan, "Введите урон " + (ArrayAttacks.Length + 1) + " атаки:");
- int.TryParse(Console.ReadLine(), out int damageAttack);
- message.PrintTheMessage(ConsoleColor.Cyan, "Введите цвет текста " + (ArrayAttacks.Length + 1) + " атаки" +
- "\nДоступные цвета: красный, зеленый, синий, желтый, белый, серый");
- Attack[] CreateNewAttack = new Attack[ArrayAttacks.Length + 1];
- for(int i = 0; i < ArrayAttacks.Length; i++) { CreateNewAttack[i] = ArrayAttacks[i]; }
- CreateNewAttack[CreateNewAttack.Length-1] = new Attack(nameAttack, textAttack, damageAttack);
- ArrayAttacks = CreateNewAttack;
- ArrayAttacks[ArrayAttacks.Length - 1].Color = GetColor();
- }
- message.PrintTheMessage(ConsoleColor.Green, "Нажмите enter для начала боя");
- return ArrayAttacks;
- }
- public void NextAttack(MessageForUser message, User player)
- {
- if (isRandomAttack)
- {
- Apply(rand, message, player);
- }
- else
- {
- Apply(attackNumber, message, player);
- attackNumber += 1;
- if (attackNumber > 2)
- {
- attackNumber = 0;
- }
- }
- }
- }
- public class Battlefield
- {
- User Player;
- Boss ThisBoss;
- public Battlefield(User player, Boss boss)
- {
- Player = player;
- ThisBoss = boss;
- }
- public void Fight(MessageForUser message)
- {
- while (Player.Health > 0)
- {
- Console.Clear();
- Console.WriteLine("Атаки босса:");
- foreach (var element in ThisBoss.AllAttacks)
- {
- Console.Write(element.NameAttack + "|");
- }
- Console.WriteLine();
- message.PrintTheMessage(ConsoleColor.Red, "У вас здоровья: " + Player.Health);
- ThisBoss.NextAttack(message, Player);
- Thread.Sleep(3000);
- }
- message.PrintTheMessage(ConsoleColor.DarkGreen, "Бой окончен, Вы погибли");
- }
- }
- public class User
- {
- public int Health { get; set; } = 1000;
- public int Armor { get; } = 20;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement