Skip to content

Instantly share code, notes, and snippets.

@talatari
Forked from HolyMonkey/medium8-1-4.cs
Last active January 23, 2024 14:57
Show Gist options
  • Save talatari/9d1f5b2a828a3262423995e151b70764 to your computer and use it in GitHub Desktop.
Save talatari/9d1f5b2a828a3262423995e151b70764 to your computer and use it in GitHub Desktop.
20. Группировка полей по префиксу
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