Advertisement
OwlyOwl

glads_v2

Jul 11th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Glads
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Rogue rogue = new Rogue(60, 1);
  11.             Paladin paladin = new Paladin(100, 6);
  12.             Vampire vampire = new Vampire(50, 10);
  13.             Druid druid = new Druid(80, 7);
  14.             Shaman shaman = new Shaman(70, 8);
  15.             List<Fighter> fighterList = new List<Fighter>();
  16.             fighterList.Add(rogue);
  17.             fighterList.Add(paladin);
  18.             fighterList.Add(vampire);
  19.             fighterList.Add(druid);
  20.             fighterList.Add(shaman);
  21.  
  22.             Console.WriteLine("Выберите бойцов (Поочередно введите две цифры):\n1 - Rogue\n2 - Paladin\n3 - Vampire\n4 - Druid\n5 - Shaman");
  23.             int userInput1 = Convert.ToInt32(Console.ReadLine());
  24.             int userInput2 = Convert.ToInt32(Console.ReadLine());
  25.             fighterList[userInput1 - 1].startFight(fighterList[userInput1 - 1], fighterList[userInput2 - 1]);
  26.         }
  27.  
  28.  
  29.         abstract class Fighter
  30.         {
  31.             protected int Health;
  32.             protected int Damage;
  33.  
  34.             public Fighter(int health, int damage)
  35.             {
  36.                 Health = health;
  37.                 Damage = damage;
  38.             }
  39.  
  40.             public void startFight(Fighter fighter1, Fighter fighter2)
  41.             {
  42.                 Console.WriteLine("Start!");
  43.                 while (fighter1.Health >= 0 && fighter2.Health >= 0)
  44.                 {
  45.                     fighter1.TakeDamage(fighter2.Damage);
  46.                     fighter2.TakeDamage(fighter1.Damage);
  47.                     fighter1.SpecialAbility();
  48.                     fighter2.SpecialAbility();
  49.                     fighter1.ShowInfo(1);
  50.                     fighter2.ShowInfo(2);
  51.                     Console.ReadKey();
  52.                     Console.Clear();
  53.                 }
  54.                 if (fighter1.Health > 0)
  55.                 {
  56.                     Console.WriteLine("Победил первый боец!");
  57.                 }
  58.                 else
  59.                 {
  60.                     Console.WriteLine("Победил второй боец!");
  61.                 }
  62.             }
  63.  
  64.             public void TakeDamage(int damageAmount)
  65.             {
  66.                 Health -= damageAmount;
  67.             }
  68.  
  69.             abstract public void SpecialAbility();
  70.  
  71.             public void ShowInfo(int fighterNumber)
  72.             {
  73.                 Console.WriteLine($"Здоровье бойца номер: {fighterNumber} = {Health}");
  74.             }
  75.         }
  76.  
  77.         class Rogue : Fighter
  78.         {
  79.             public Rogue(int health, int damage) : base(health, damage) { }
  80.             public override void SpecialAbility()
  81.             {
  82.                 Damage += 3;
  83.             }
  84.         }
  85.  
  86.         class Paladin : Fighter
  87.         {
  88.             public Paladin(int health, int damage) : base(health, damage) { }
  89.  
  90.             public override void SpecialAbility()
  91.             {
  92.                 Health += 1;
  93.             }
  94.         }
  95.  
  96.         class Vampire : Fighter
  97.         {
  98.             public Vampire(int health, int damage) : base(health, damage) { }
  99.  
  100.             public override void SpecialAbility()
  101.             {
  102.                 Damage += 1;
  103.                 Health += 2;
  104.             }
  105.         }
  106.  
  107.         class Druid : Fighter
  108.         {
  109.             public Druid(int health, int damage) : base(health, damage) { }
  110.  
  111.             public override void SpecialAbility()
  112.             {
  113.                 if (Health <= 20)
  114.                 {
  115.                     Damage += 15;
  116.                 }
  117.             }
  118.         }
  119.  
  120.         class Shaman : Fighter
  121.         {
  122.             public Shaman(int health, int damage) : base(health, damage) { }
  123.             private bool cooldown = false;
  124.  
  125.             public override void SpecialAbility()
  126.             {
  127.  
  128.                 if (Health <= 15 && cooldown != true)
  129.                 {
  130.                     Health += 50;
  131.                     cooldown = true;
  132.                 }
  133.             }
  134.         }
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement