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 num1
- {
- class Program
- {
- static void Main()
- {
- Enemy enem = new Enemy();
- IDamageable damageable = null;
- Kill(enem);
- }
- static void Kill(IDamageable damageable)
- {
- damageable.Damage(100);
- if (damageable.IsAlive())
- {
- Console.WriteLine("Цель ещё жива");
- }
- else
- {
- Console.WriteLine("Цель мертва");
- }
- }
- }
- class Enemy : IDamageable
- {
- private int _hp = 100;
- public void Damage(int damage)
- {
- _hp -= damage;
- }
- public bool IsAlive()
- {
- return _hp > 0;
- }
- }
- interface IDamageable
- {
- void Damage(int damage);
- bool IsAlive();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment