Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 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 Полиморфизм_и__наследование_145
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Wombat w = new Wombat();
  14.             w.Health = 100;
  15.             w.TakeDamage(101);
  16.         }
  17.     }
  18.  
  19.     class Figthter
  20.     {
  21.         public int Health;
  22.  
  23.         public virtual void TakeDamage(int damage)
  24.         {
  25.             Health -= damage;
  26.             Dead();
  27.         }
  28.  
  29.         public void Dead()
  30.         {
  31.             if (Health <= 0)
  32.             {
  33.                 Console.WriteLine("Я умер");
  34.             }
  35.         }
  36.     }
  37.     class Wombat : Figthter
  38.     {
  39.         public int Armor;
  40.  
  41.         public override void TakeDamage(int damage)
  42.         {
  43.             Health -= damage - Armor;
  44.             Dead();
  45.         }
  46.     }
  47.  
  48.     class Human : Figthter
  49.     {
  50.         public int Agility;
  51.  
  52.         public override void TakeDamage(int damage)
  53.         {
  54.             Health -= damage / Agility;
  55.             Dead();
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement