Ejemplo n.º 1
0
 public Robot(int TableMaxSize, int TableMinSize)
 {
     _forwardStep = 1;
     _message = string.Empty;
     _currentPosition = new Position();
     _tableMaxSize = TableMaxSize;
     _tableMinSize = TableMinSize;
     _isToyPlaced = false;
 }
Ejemplo n.º 2
0
 public PlaceCommand(Toy toy, Position placePosition, MoveDirection moveDirection)
     : base(toy)
 {
     this._toy.CurrentPosition = placePosition;
     this._toy.Facing = moveDirection;
 }
Ejemplo n.º 3
0
        public override bool Move()
        {
            if (_isToyPlaced)
            {
                Position tempPosition = new Position() { X = _currentPosition.X, Y = _currentPosition.Y };
                switch (_facing)
                {
                    case MoveDirection.North:
                        tempPosition.Y += _forwardStep;
                        break;
                    case MoveDirection.East:
                        tempPosition.X += _forwardStep;
                        break;
                    case MoveDirection.West:
                        tempPosition.X -= _forwardStep;
                        break;
                    case MoveDirection.South:
                        tempPosition.Y -= _forwardStep;
                        break;
                }

                if (tempPosition.X > _tableMaxSize || tempPosition.X < _tableMinSize || tempPosition.Y > _tableMaxSize || tempPosition.Y < _tableMinSize)
                {
                    _message = "robot is prevented from falling to destruction.";
                    return false;
                }

                _currentPosition = tempPosition;
                _message = "Done";
                return true;
            }
            else
            {
                _message = "The first valid command to the robot is a PLACE command.";
                return false;
            }
        }
Ejemplo n.º 4
0
 public ToyArgs()
 {
     _action = ToyActions.Invalid;
     _direction = MoveDirection.Invalid;
     _position = new Position();
 }