public Coordinates findCoordinatesInDirection(Direction.AllDirections direction) { switch (direction) { case Direction.AllDirections.up: return(new Coordinates(x, z - 1)); case Direction.AllDirections.down: return(new Coordinates(x, z + 1)); case Direction.AllDirections.left: return(new Coordinates(x - 1, z)); case Direction.AllDirections.right: return(new Coordinates(x + 1, z)); case Direction.AllDirections.upper_left: return(new Coordinates(x - 1, z - 1)); case Direction.AllDirections.upper_right: return(new Coordinates(x + 1, z - 1)); case Direction.AllDirections.lower_left: return(new Coordinates(x - 1, z + 1)); case Direction.AllDirections.lower_right: return(new Coordinates(x + 1, z + 1)); } throw new Exception("Invalid Direction supplied!"); }
public Coordinates randomDirectionAround() { // get directions that are forbidden base on coordinates. List <Direction.AllDirections> directionsToRemove = findDirectionsOffWorldMap(this); // get a random allowable direction Direction.AllDirections direction = getRandomDirection(directionsToRemove); // Convert that into the new coordinates return(findCoordinatesInDirection(direction)); }