View difference between Paste ID: nwME900Z and KFhEkeGv
SHOW: | | - or go back to the newest paste.
1
class Weapon
2
{
3
    private readonly int _damage;
4
    private int _bullets;
5
6-
    public Weapon() { }
6+
7
    {
8
        if (damage < 0)
9
            throw new ArgumentOutOfRangeException();
10
11
        if (bullets < 0)
12
            throw new ArgumentOutOfRangeException();
13
14
        _damage = damage ;
15
        _bullets = bullets;
16-
        _damage = damage;
16+
17
18
    public bool CanFire => _bullets > 0;
19
20
    public void Fire(IDamagable target)
21
    {
22
        if (target == null)
23
            throw new ArgumentNullException("target");
24
25
        if (CanFire)
26
        {
27
            target.TakeDamage(_damage);
28
            _bullets--;
29
        }
30
    }
31
}
32
33
class Player : IDamagable
34
{
35
    private int _health;
36
37
    public Player(int health)
38
    {
39-
    public Player() { }
39+
40
            throw new ArgumentOutOfRangeException();
41
42
        _health = health;
43
    }
44
45
    public bool IsAlive => _health > 0;
46
47
    public void TakeDamage(int damage)
48
    {
49
        if (damage < 0)
50
            throw new ArgumentOutOfRangeException();
51
52
        if (IsAlive)
53
            _health = Math.Max(_health - damage, 0);
54
    }
55
}
56
57
class Bot
58
{
59
    private readonly Weapon _weapon;
60
61
    public Bot(Weapon weapon) => _weapon = weapon ?? throw new ArgumentNullException();
62
63-
    private Weapon _weapon;
63+
    public void OnSee(Player player)
64
    {
65-
    public Bot() { }
65+
66
            throw new ArgumentNullException();
67-
    public Bot(Weapon weapon)
67+
68
        if (player.IsAlive && _weapon.CanFire)
69-
        if (_weapon == null)
69+
70
    }
71
}
72-
        _weapon = weapon;
72+
73
interface IDamagable
74
{
75-
    public void OnSeePlayer(Player player)
75+
76
}
77
78