-
-
Save GigaOrts/f7c8e39518fa399b7fdad4a4c03d5df0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Weapon | |
{ | |
private readonly int _damage; | |
private int _bullets; | |
public Weapon(int damage, int bullets) | |
{ | |
if (damage < 0) | |
throw new ArgumentOutOfRangeException(nameof(damage)); | |
if (bullets < 0) | |
throw new ArgumentOutOfRangeException(nameof(bullets)); | |
_damage = damage; | |
_bullets = bullets; | |
} | |
public bool CanShoot => _bullets > 0; | |
public void Fire(Player player) | |
{ | |
if (CanShoot) | |
{ | |
_bullets--; | |
player.TakeDamage(_damage); | |
} | |
} | |
} | |
class Player | |
{ | |
private int _health; | |
public Player(int health) | |
{ | |
if (health <= 0) | |
throw new ArgumentOutOfRangeException(nameof(health)); | |
_health = health; | |
} | |
public bool IsAlive => _health > 0; | |
public void TakeDamage(int damage) | |
{ | |
if (IsAlive) | |
_health -= damage; | |
} | |
} | |
class Bot | |
{ | |
private readonly Weapon _weapon; | |
public Bot(Weapon weapon) | |
{ | |
_weapon = weapon; | |
} | |
public void OnSeePlayer(Player player) | |
{ | |
_weapon.Fire(player); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment