public void SetStartPosition(Position position) { if (!_arena.IsValidPosition(position)) { throw new ArgumentException("Argument: 'startingPosition' is invalid."); } Position = position; }
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; }
private void SetPosistionIfValid(Position newPosition) { if (!_arena.IsValidPosition(newPosition)) { throw new InvalidOperationException("Move Invalid For Arena Size"); } Position = newPosition; }
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; } }