예제 #1
0
        public void Move(string direction, bool startMoving)
        {
            if (LinearDirections.Valid(direction))
            {
                switch (direction)
                {
                case "Left":
                    Moving.Left = startMoving;
                    _velocityUpdater(this);
                    break;

                case "Right":
                    Moving.Right = startMoving;
                    break;

                case "Up":
                    Moving.Up = startMoving;
                    break;

                case "Down":
                    Moving.Down = startMoving;
                    break;
                }

                _velocityUpdater(this);
                UpdateRotation();
                OnMove(new MoveEvent(direction, startMoving));
            }
            else
            {
                throw new InvalidOperationException(direction + " is an unknown direction.");
            }
        }
        public LinearMovementController(IMoveable[] moveables, double moveSpeed, bool rotateWithMovements, bool multiDirectional)
            : base(moveables)
        {
            Moving = new LinearDirections();
            _moveSpeed = moveSpeed;
            _rotateWithMovements = rotateWithMovements;

            OnMove = _ => { };

            if (multiDirectional)
            {
                _velocityUpdater = UpdateVelocityWithMultiDirection;
            }
            else
            {
                _velocityUpdater = UpdateVelocityNoMultiDirection;
            }
        }
예제 #3
0
        public LinearMovementController(IMoveable[] moveables, double moveSpeed, bool rotateWithMovements, bool multiDirectional)
            : base(moveables)
        {
            Moving               = new LinearDirections();
            _moveSpeed           = moveSpeed;
            _rotateWithMovements = rotateWithMovements;

            OnMove = _ => { };

            if (multiDirectional)
            {
                _velocityUpdater = UpdateVelocityWithMultiDirection;
            }
            else
            {
                _velocityUpdater = UpdateVelocityNoMultiDirection;
            }
        }