Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IWeapon
- {
- public float WeaponCooldown { get; }
- public int WeaponDamage { get; }
- public void Attack();
- public bool IsReloading();
- }
- public interface IMover
- {
- public float MovementDirectionX { get; }
- public float MovementDirectionY { get; }
- public float MovementSpeed { get; }
- public void Move();
- }
- public class Weapon : IWeapon
- {
- public Weapon(float weaponCooldown, int weaponDamage)
- {
- if (weaponCooldown < 0)
- {
- throw new ArgumentException("Cooldown не может быть отрицательным.", nameof(weaponCooldown));
- }
- if (weaponDamage < 0)
- {
- throw new ArgumentException("Damage не может быть отрицательным.", nameof(weaponDamage));
- }
- WeaponCooldown = weaponCooldown;
- WeaponDamage = weaponDamage;
- }
- public float WeaponCooldown { get; private set; }
- public int WeaponDamage { get; private set; }
- public void Attack()
- {
- }
- public bool IsReloading()
- {
- throw new NotImplementedException();
- }
- }
- public class Mover : IMover
- {
- public Mover(float directionX, float directionY, float speed)
- {
- if (speed < 0)
- {
- throw new ArgumentException("Скорость не может быть отрицательной.", nameof(speed));
- }
- MovementDirectionX = directionX;
- MovementDirectionY = directionY;
- MovementSpeed = speed;
- }
- public float MovementDirectionX { get; private set; }
- public float MovementDirectionY { get; private set; }
- public float MovementSpeed { get; private set; }
- public void Move()
- {
- }
- }
- public class Player
- {
- private readonly IWeapon _weapon;
- private readonly IMover _mover;
- public Player(string name, int age, IWeapon weapon, IMover mover)
- {
- if (string.IsNullOrWhiteSpace(name))
- {
- throw new ArgumentException("Имя не может быть пустым или состоять из пробелов.", nameof(name));
- }
- if (age < 0)
- {
- throw new ArgumentException("Возраст не может быть отрицательным.", nameof(age));
- }
- if (weapon == null)
- {
- throw new ArgumentNullException("Оружие не может быть null.", nameof(weapon));
- }
- if (mover == null)
- {
- throw new ArgumentNullException("Mover не может быть null.", nameof(mover));
- }
- Name = name;
- Age = age;
- _weapon = weapon;
- _mover = mover;
- }
- public string Name { get; private set; }
- public int Age { get; private set; }
- public void Attack()
- {
- _weapon.Attack();
- }
- public void Move()
- {
- _mover.Move();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement