-
-
Save MightyBlow/9d1f5b2a828a3262423995e151b70764 to your computer and use it in GitHub Desktop.
20. Группировка полей по префиксу
This file contains hidden or 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
class Player | |
{ | |
private readonly Mover _mover; | |
private readonly Weapon _weapon; | |
public Player(Mover mover, Weapon weapon) | |
{ | |
_mover = mover ?? throw new ArgumentNullException(nameof(mover)); | |
_weapon = weapon ?? throw new ArgumentNullException(nameof(weapon)); | |
} | |
public string Name { get; private set; } | |
public int Age { get; private set; } | |
public void Move() => | |
_mover.Move(); | |
public void Attack() | |
{ | |
if (_weapon.IsReloading() == false) | |
_weapon.Attack(); | |
} | |
} | |
public class Weapon | |
{ | |
public int Damage { get; private set; } | |
public float Cooldown { get; private set; } | |
public bool IsReloading() => | |
throw new NotImplementedException(); | |
public void Attack() => | |
throw new NotImplementedException(); | |
public void SetDamage(int damage) | |
{ | |
if (damage < 0) | |
throw new ArgumentOutOfRangeException(nameof(damage)); | |
Damage = damage; | |
} | |
public void SetCooldown(float cooldown) | |
{ | |
if (cooldown < 0) | |
throw new ArgumentOutOfRangeException(nameof(cooldown)); | |
Cooldown = cooldown; | |
} | |
} | |
public class Mover | |
{ | |
public float DirectionX { get; private set; } | |
public float DirectionY { get; private set; } | |
public float Speed { get; private set; } | |
public void Move() => | |
throw new NotImplementedException(); | |
public void SetSpeed(float speed) | |
{ | |
if (speed < 0) | |
throw new ArgumentOutOfRangeException(nameof(speed)); | |
Speed = speed; | |
} | |
public void SetDirectionX(float x) => | |
DirectionX = x; | |
public void SetDirectionY(float y) => | |
DirectionY = y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment