redSkywalker

Задача_3 с интерфейсом

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