Advertisement
RedFlys

Warrior_V2.0

Jan 12th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FightWarriorV2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int userInput;
  14.             int chooseEnemyAttack;
  15.             Enemy enemy = new Enemy();
  16.             Render render = new Render();
  17.             Random random = new Random();
  18.            
  19.             Console.WriteLine("Выберите класс: \n1. Лучник \n2. Берсерк");
  20.             userInput = Convert.ToInt32(Console.ReadLine());
  21.  
  22.             Warrior player = ChooseClase(userInput);
  23.             Console.Clear();
  24.  
  25.             while (player.Health > 0 && enemy.Health > 0)
  26.             {
  27.                 render.RenderPlayerInfo(player.Name, player.Health);
  28.                 render.RenderEnemyInfo(enemy.Name, enemy.Health);
  29.                 render.ChooseAttack(player.Spell);
  30.                 userInput = Convert.ToInt32(Console.ReadLine());
  31.                 render.RenderPlayerAttack(player.Spell[userInput - 1].About, enemy.ProceduralDamage(player.Spell[userInput - 1].Damage, player.RangeAttack()));
  32.                 enemy.TakeDamage(player.Spell[userInput - 1].Damage, player.RangeAttack());                
  33.  
  34.                 if (enemy.Health <= 0)
  35.                     break;
  36.  
  37.                 if (!player.RangeAttack())
  38.                 {
  39.                     player.TakeDamage(enemy.Spell[3].Damage);
  40.                     Console.WriteLine($"Противник наносит контрудар на {player.ProceduralDamage(enemy.Spell[3].Damage)}");
  41.                 }                              
  42.  
  43.                 chooseEnemyAttack = random.Next(0, 3);
  44.                 render.RenderEnemyAttack(enemy.Spell[chooseEnemyAttack].About, player.ProceduralDamage(enemy.Spell[chooseEnemyAttack].Damage));
  45.                 player.TakeDamage(enemy.Spell[chooseEnemyAttack].Damage);
  46.                
  47.                 if (player.Health <= 0)
  48.                     break;
  49.  
  50.                 Console.ReadKey();
  51.                 Console.Clear();
  52.             }
  53.         }
  54.  
  55.         static Warrior ChooseClase(int userInput)
  56.         {
  57.             switch (userInput)
  58.             {
  59.                 case 1:
  60.                     return new Archer();
  61.                 case 2:
  62.                     return new Berserk();
  63.                 default:
  64.                     return null;
  65.             }
  66.         }
  67.     }
  68.  
  69.     abstract class Warrior
  70.     {
  71.         public string Name { get; protected set; }
  72.         public float Health { get; protected set; }
  73.         public Spell[] Spell { get; protected set; }
  74.  
  75.         public abstract bool RangeAttack();            
  76.  
  77.         public void TakeDamage(float damage)
  78.         {
  79.             Health -= ProceduralDamage(damage);
  80.         }
  81.  
  82.         public abstract float ProceduralDamage(float damage);
  83.     }
  84.  
  85.     class Archer : Warrior
  86.     {
  87.         public Archer(string name = "Лучник", float health = 60)
  88.         {
  89.             Spell[] spell =
  90.             {
  91.                 new Spell("Точный выстрел", 10),
  92.                 new Spell("Двойной выстрел", 20),
  93.                 new Spell("Тройной выстрел", 30)
  94.             };
  95.  
  96.             Name = name;
  97.             Health = health;
  98.             Spell = spell;
  99.         }
  100.  
  101.         public override bool RangeAttack()
  102.         {
  103.             return true;
  104.         }
  105.  
  106.         public override float ProceduralDamage(float damage)
  107.         {
  108.             return damage * 1.5f;
  109.         }
  110.     }
  111.  
  112.     class Berserk : Warrior
  113.     {
  114.         public Berserk(string name = "Берсерк", float health = 60)
  115.         {
  116.             Spell[] spell =
  117.             {
  118.                 new Spell("Удар сверху", 10),
  119.                 new Spell("Размашистый удар", 15),
  120.                 new Spell("Вихрь клинков", 20)
  121.             };
  122.  
  123.             Name = name;
  124.             Health = health;
  125.             Spell = spell;
  126.         }        
  127.  
  128.         public override bool RangeAttack()
  129.         {
  130.             return false;
  131.         }
  132.  
  133.         public override float ProceduralDamage(float damage)
  134.         {
  135.             return damage * 0.7f;
  136.         }        
  137.     }
  138.  
  139.     class Spell
  140.     {
  141.         public string About;
  142.         public int Damage;
  143.  
  144.         public Spell(string about, int damage)
  145.         {
  146.             About = about;
  147.             Damage = damage;
  148.         }
  149.     }
  150.  
  151.     class Enemy
  152.     {
  153.         public string Name = "Лерой Дженкинс";
  154.         public float Health = 50;
  155.         public Spell[] Spell = {new Spell("Удар в лоб", 10), new Spell("Крик - Лирооооооой Дженкинс", 15), new Spell("Пробежка по логову драконов", 20), new Spell("Контрудар", 5)};
  156.  
  157.         public void TakeDamage(float damage, bool range)
  158.         {
  159.             Health -= ProceduralDamage(damage, range);
  160.         }
  161.  
  162.         public float ProceduralDamage(float damage, bool range)
  163.         {
  164.             if (range)
  165.                 return damage * 0.8f;
  166.             else
  167.                 return damage * 1.2f;
  168.         }        
  169.     }
  170.  
  171.     class Render
  172.     {
  173.         public void RenderPlayerInfo(string name, float health)
  174.         {
  175.             Console.SetCursorPosition(0, 0);
  176.             Console.WriteLine($"Вы, {name}");
  177.             Console.SetCursorPosition(0, 1);
  178.             Console.WriteLine($"Ваше здоровье: {health}");
  179.         }
  180.  
  181.         public void RenderEnemyInfo(string name, float health)
  182.         {
  183.             Console.SetCursorPosition(50, 0);
  184.             Console.WriteLine($"Ваш враг, {name}");
  185.             Console.SetCursorPosition(50, 1);
  186.             Console.WriteLine($"Здоровье врага: {health}");
  187.         }
  188.  
  189.         public void ChooseAttack(Spell[] spell)
  190.         {
  191.             Console.WriteLine("Выберите атаку:");
  192.  
  193.             for (int i = 0; i < spell.GetLength(0); i++)
  194.             {
  195.                 Console.WriteLine($"{i+1}. {spell[i].About}. Урон: {spell[i].Damage}.");
  196.             }
  197.         }
  198.  
  199.         public void RenderPlayerAttack(string attack, float damage)
  200.         {
  201.             Console.WriteLine($"Вы используете {attack} и наносите {damage} урона.");
  202.         }
  203.  
  204.         public void RenderEnemyAttack(string attack, float damage)
  205.         {
  206.             Console.WriteLine($"Враг использует {attack} и наносит {damage} урона.");
  207.         }
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement