Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace задача_полиморф_1
- {
- class Programm
- {
- static void Main()
- {
- IDamageable damageable = new Wolf();
- Kill(damageable);
- Kill(damageable);
- Console.WriteLine();
- IDamageable damageable1 = new Dragon();
- Kill(damageable1);
- Kill(damageable1);
- Kill(damageable1);
- Kill(damageable1);
- Kill(damageable1);
- Console.ReadKey();
- }
- static void Kill(IDamageable damageable)
- {
- damageable.Damage(100);
- if (damageable.IsAlive())
- {
- Console.WriteLine("Цель ещё жива");
- }
- else
- {
- Console.WriteLine("Цель мертва");
- }
- }
- }
- interface IDamageable
- {
- void Damage(int damage);
- bool IsAlive();
- }
- class Wolf:IDamageable
- {
- public int Health { get; set; }
- public bool isAlive { get; set; }
- public Wolf()
- {
- Health = 200;
- isAlive = true;
- }
- public bool IsAlive()
- {
- if(this.Health<=0)
- {
- this.isAlive = false;
- }
- return this.isAlive;
- }
- public void Damage(int damage)
- {
- this.Health -= damage;
- }
- }
- class Dragon : Wolf, IDamageable
- {
- public Dragon() : base()
- {
- Health = 450;
- isAlive = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment