Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Weapon
- {
- private readonly int _damage;
- private int _bullets;
- public bool CanFire => _bullets > 0;
- public void Fire(IDamagable target)
- {
- if(target == null)
- throw new ArgumentNullException("target");
- if (CanFire)
- {
- target.TakeDamage(_damage);
- _bullets--;
- }
- }
- }
- class Player : IDamagable
- {
- private int _health;
- public bool IsAlive => _health > 0;
- public void TakeDamage(int damage)
- {
- if (damage < 0)
- throw new ArgumentOutOfRangeException();
- if (IsAlive)
- _health = Math.Max(_health - damage, 0);
- }
- }
- class Bot
- {
- private Weapon _weapon;
- public Bot(Weapon weapon)
- {
- if (_weapon == null)
- throw new ArgumentNullException();
- _weapon = weapon;
- }
- public void OnSeePlayer(Player player)
- {
- if (player == null)
- throw new ArgumentNullException();
- if (player.IsAlive && _weapon.CanFire)
- _weapon.Fire(player);
- }
- }
- interface IDamagable
- {
- public void TakeDamage(int damage) { }
- }
Advertisement
Add Comment
Please, Sign In to add comment