Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace Delegates
- {
- class Program
- {
- static void Main(string[] args)
- {
- Attack[] attacks = new Attack[3]
- {
- new Attack(100, ConsoleColor.DarkRed, "Босс атаковал с немыслимой яростью своими руками"),
- new Attack(140, ConsoleColor.DarkMagenta, "Босс исполнил новый альбом Ольги бузовой"),
- new Attack(80, ConsoleColor.DarkGray, "Босс приуныл и рассказал вам о своём долгом пути и дал пару советов, после выпил ритуальный стопарь боярки"),
- };
- Enemy Boss = new Enemy(attacks);
- Player Player = new Player(1000, 20);
- Service.ShowMessage(ConsoleColor.Green, "Нажмите enter для начала боя");
- Console.ReadLine();
- Boss.Attack(Player);
- }
- }
- class Enemy
- {
- private Attack[] Attacks { get; set; }
- public bool IsRandomAttack { get; private set; }
- public Enemy(params Attack[] attacks)
- {
- Attacks = attacks;
- IsRandomAttack = (DateTime.Now.Millisecond % 2) == 0;
- Service.ShowMessage(ConsoleColor.Yellow, "Босс может атаковать в двух режимах: все атаки по очереди и случайной атакой");
- Service.ShowMessage(ConsoleColor.Yellow, "Босс будет атаковать: " + (IsRandomAttack ? "случайно" : "все атаки по очереди"));
- }
- public void Attack(Player player)
- {
- int attackNumber = 0;
- while (!player.IsDead)
- {
- int attackIndex = IsRandomAttack ? DateTime.Now.Millisecond % 3 : attackNumber;
- Attacks[attackIndex].Invoke(player);
- if (!IsRandomAttack)
- {
- attackNumber++;
- if (attackNumber > Attacks.Length - 1)
- attackNumber = 0;
- }
- Thread.Sleep(1000);
- }
- Console.ReadKey();
- }
- }
- class Attack
- {
- private string Message { get; set; }
- private int Damage { get; set; }
- private ConsoleColor ConsoleColor { get; set; }
- public Attack(int damage, ConsoleColor consoleColor, string message)
- {
- Damage = damage;
- ConsoleColor = consoleColor;
- Message = message;
- }
- public void Invoke(Player player)
- {
- Console.Clear();
- Service.ShowMessage(ConsoleColor, Message);
- player.TakeDamage(Damage);
- }
- }
- class Player
- {
- public int Health { get; private set; }
- public int Armor { get; private set; }
- public bool IsDead { get; private set; }
- public Player(int health, int armor)
- {
- Health = health;
- Armor = armor;
- IsDead = false;
- }
- public void TakeDamage(int damage)
- {
- Service.ShowMessage(ConsoleColor.Red, "У вас здоровья: " + Health);
- Health = Health - (damage - Armor);
- if (Health <= 0 && !IsDead)
- Death();
- }
- private void Death()
- {
- IsDead = true;
- Console.Clear();
- Service.ShowMessage(ConsoleColor.DarkGray, "Бой закончен, вы погибли");
- }
- }
- public static class Service
- {
- private static ConsoleColor oldColor = Console.ForegroundColor;
- public static void ShowMessage(ConsoleColor color, string message)
- {
- oldColor = Console.ForegroundColor;
- Console.ForegroundColor = color;
- Console.WriteLine(message);
- Console.ForegroundColor = oldColor;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement