public void MoveForward() { GridPoint newPosition; switch (CompassCurrentOrientation) { case CompassDirection.NORTH: newPosition = _planetTerrainGrid.AdvanceNorth(CurrentGridPosition); break; case CompassDirection.SOUTH: newPosition = _planetTerrainGrid.AdvanceSouth(CurrentGridPosition); break; case CompassDirection.EAST: newPosition = _planetTerrainGrid.AdvanceEast(CurrentGridPosition); break; case CompassDirection.WEST: newPosition = _planetTerrainGrid.AdvanceWest(CurrentGridPosition); break; default: newPosition = CurrentGridPosition; break; } if (_planetTerrainGrid.ObstacleExists(newPosition)) { return; } CurrentGridPosition = newPosition; }
public void TestAdvanceNorthWhenAtEdgeOfGrid() { var originalPosition = new GridPoint(2, 9); _terrainGridInstance = new TerrainGrid(10, 10); var newPosition = _terrainGridInstance.AdvanceNorth(originalPosition); Assert.IsTrue(newPosition.X == originalPosition.X); Assert.IsTrue(newPosition.Y == 0); }