redSkywalker

Задача_3 с абстрактным классом

Feb 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 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 задача_3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Human Jack = new Human(25, 5);
  14.             Human Bobby = new Human(15, 3);
  15.             Wombat Wombo = new Wombat(20, 15);
  16.  
  17.             Console.WriteLine("Битва началась.");
  18.             Console.WriteLine("Вомбат нападает!");
  19.             Bobby.TakeDamage(20);
  20.             Console.WriteLine("Джек наносит удар вомбату");
  21.             Wombo.TakeDamage(25);
  22.             Console.WriteLine("Бобби наносит удар вомбату");
  23.             Wombo.TakeDamage(10);
  24.             Console.WriteLine("Вомбат нападает!");
  25.             Jack.TakeDamage(45);
  26.             Console.WriteLine("Вомбат нападает!");
  27.             Jack.TakeDamage(100);
  28.             Console.WriteLine("Бобби наносит удар вомбату");
  29.             Wombo.TakeDamage(50);            
  30.  
  31.             Console.ReadKey();
  32.  
  33.  
  34.  
  35.         }
  36.     }
  37.  
  38.     abstract class Mammals
  39.     {
  40.         public int Health;
  41.         public abstract void TakeDamage(int damage);      
  42.  
  43.     }
  44.  
  45.     class Wombat:Mammals
  46.     {
  47.        
  48.         public int Armor;
  49.  
  50.         public Wombat(int health, int armor)
  51.         {
  52.             Health = health;
  53.             Armor = armor;
  54.         }
  55.  
  56.         public override void TakeDamage(int damage)
  57.         {
  58.             Health -= damage - Armor;
  59.             if (Health <= 0)
  60.             {
  61.                 Console.WriteLine("Я умер");
  62.             }
  63.         }
  64.     }
  65.  
  66.     class Human : Mammals
  67.     {
  68.        
  69.         public int Agility;
  70.  
  71.         public Human(int health, int agility)
  72.         {
  73.             Health = health;
  74.             Agility = agility;
  75.         }
  76.  
  77.         public override void TakeDamage(int damage)
  78.         {
  79.             Health -= damage / Agility;
  80.             if (Health <= 0)
  81.             {
  82.                 Console.WriteLine("Я умер");
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment