public void connectAllWayPoints(Tile[,] tiles) { for (int row = 0; row < tiles.GetLength(0); row++) { for (int column = 0; column < tiles.GetLength(1); column++) { if (tiles[row, column] != null) { bool addWest = false; bool addEast = false; bool addNorth = false; bool addSouth = false; switch (tiles[row, column].direction) { case directions.EastNorthSouthWest: addEast = true; addNorth = true; addSouth = true; addWest = true; break; case directions.NorthSouthWest: addNorth = true; addSouth = true; addWest = true; break; case directions.EastNorthSouth: addEast = true; addNorth = true; addSouth = true; break; case directions.EastNorthWest: addEast = true; addNorth = true; addWest = true; break; case directions.EastSouthWest: addEast = true; addSouth = true; addWest = true; break; case directions.NorthSouth: addNorth = true; addSouth = true; break; case directions.NorthWest: addNorth = true; addWest = true; break; case directions.EastNorth: addEast = true; addNorth = true; break; case directions.SouthWest: addSouth = true; addWest = true; break; case directions.EastSouth: addEast = true; addSouth = true; break; case directions.EastWest: addEast = true; addWest = true; break; case directions.East: addEast = true; break; case directions.West: addWest = true; break; case directions.South: addSouth = true; break; case directions.North: addNorth = true; break; case directions.Invalid: throw new ArgumentException("invalid direction encountered"); default: break; } Waypoint current = tiles[row, column].wp; if (addWest) { Waypoint west = tiles[row, column - 1].wp; current.AddPath(west); } if (addEast) { Waypoint east = tiles[row, column + 1].wp; current.AddPath(east); } if (addNorth) { Waypoint north = tiles[row - 1, column].wp; current.AddPath(north); } if (addSouth) { Waypoint south = tiles[row + 1, column].wp; current.AddPath(south); } } } } }