private void createIsland(Board3D board, Vector3D beginning, Vector3D lastIsland, List <Island3D> islands, Vector3D direction) { Island3D tempIsland; updateBoard(board, beginning, lastIsland, direction); tempIsland = new Island3D(lastIsland); board.set(tempIsland); islands.Add(tempIsland); }
private void updateBoard(Board3D board, Vector3D startPoint, Vector3D endPoint, Vector3D direction) { bool isDouble = Random.Range(0, 2) == 1 ? true : false; if (direction == Vector3D.UP) { for (int i = startPoint.y - 1; i >= endPoint.y; i--) { board.set(new Bridge3D(startPoint.x, i, startPoint.z, isDouble, direction)); } } else if (direction == Vector3D.DOWN) { for (int i = startPoint.y + 1; i <= endPoint.y; i++) { board.set(new Bridge3D(startPoint.x, i, startPoint.z, isDouble, direction)); } } else if (direction == Vector3D.LEFT) { for (int i = startPoint.x - 1; i >= endPoint.x; i--) { board.set(new Bridge3D(i, startPoint.y, startPoint.z, isDouble, direction)); } } else if (direction == Vector3D.RIGHT) { for (int i = startPoint.x + 1; i <= endPoint.x; i++) { board.set(new Bridge3D(i, startPoint.y, startPoint.z, isDouble, direction)); } } else if (direction == Vector3D.FORWARD) { for (int i = startPoint.z - 1; i >= endPoint.z; i--) { board.set(new Bridge3D(startPoint.x, startPoint.y, i, isDouble, direction)); } } else { for (int i = startPoint.z + 1; i <= endPoint.z; i++) { board.set(new Bridge3D(startPoint.x, startPoint.y, i, isDouble, direction)); } } }
public Board3D generate(int x, int y, int z, int number) { Board3D board = new Board3D(x, y, z); List <Island3D> islands = new List <Island3D> (); islands.Add(new Island3D(Random.Range(0, x), Random.Range(0, y), Random.Range(0, z))); board.set(islands[0]); int i = 0; Island3D firstNode; Vector3D randomDirection; while (i < number - 1) { if (islands.Count == 0) { return(generate(x, y, z, number)); } firstNode = islands[Random.Range(0, islands.Count)]; if (firstNode.getDirectionsCount() == 0) { islands.Remove(firstNode); continue; } randomDirection = firstNode.getDirections(Random.Range(0, firstNode.getDirectionsCount())); if (generateNewIsland(board, islands, randomDirection, firstNode.getPosition())) { i++; continue; } else { firstNode.removeDirection(randomDirection); continue; } } islands.Clear(); return(board); }