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