Ejemplo n.º 1
0
        public void SetStartPosition(Position position)
        {
            if (!_arena.IsValidPosition(position))
            {
                throw new ArgumentException("Argument: 'startingPosition' is invalid.");
            }

            Position = position;
        }
Ejemplo n.º 2
0
 private void NorthCommand(bool forward)
 {
     if (forward)
     {
         var newPosition = new Position(
             Position.XCoordinate, 
             Position.YCoordinate + 1,
             Position.Orientation);
         
         SetPosistionIfValid(newPosition);
     }
     else
     {
         Position.Orientation = Orientation.North;
     }
 }
        public bool IsValidPosition(Position position)
        {
            var isValid = true;

            // We take 1 off because it's a zero based grid..
            var x = position.XCoordinate;
            var y = position.YCoordinate;

            var gridWidth = _gridSize.X;

           
            // Caculates the index in the array for the position.
            // If out of bounds then the Position is invalid.
            if ((gridWidth * x + y) > (_grid.Length - 1) || (gridWidth * x + y) < 0)
            {
                isValid = false;
            }
               
            return isValid;
        }
Ejemplo n.º 4
0
        private void SetPosistionIfValid(Position newPosition)
        {
            if (!_arena.IsValidPosition(newPosition))
            {
                throw new InvalidOperationException("Move Invalid For Arena Size");
            }

            Position = newPosition;
        }
Ejemplo n.º 5
0
 private void WestCommand(bool forward)
 {
     if (forward)
     {
         var newPosition = new Position(
             Position.XCoordinate - 1, 
             Position.YCoordinate,
             Orientation.West);
         
         SetPosistionIfValid(newPosition);
     }
     else
     {
         Position.Orientation = Orientation.West;
     }
 }