/** * Grow the wall one step * * @return bool - success of operation, true if wall grown, false if not */ public bool Grow(System.Random rnd) { if (l.CountWallsConnectedToJoint(x, y) > 1) { // preventing T-juncture return(false); } List <Wall> walls = new List <Wall>(3); // check all walls from this joint: // West if (l.CountWallsConnectedToJoint(x - 1, y) == 0) { walls.Add(new Wall(x, y, true, true)); } // North if (l.CountWallsConnectedToJoint(x, y + 1) == 0) { walls.Add(new Wall(x, y + 1, false, false)); } // East if (l.CountWallsConnectedToJoint(x + 1, y) == 0) { walls.Add(new Wall(x + 1, y, true, false)); } // South if (l.CountWallsConnectedToJoint(x, y - 1) == 0) { walls.Add(new Wall(x, y, false, true)); } // choose a path to grow if (walls.Count == 0) { return(false); } Wall growTo = walls[rnd.Next(0, walls.Count)]; // advance this head to a new position if (growTo.top) { // growTo.x -= (growTo.nextCell ? 1 : 0); l[growTo.x, growTo.y].top = false; } else { // growTo.y -= (growTo.nextCell ? 1 : 0); l[growTo.x, growTo.y].right = false; } x = growTo.x + (growTo.nextCell && growTo.top ? -1 : 0); y = growTo.y + (growTo.nextCell && !growTo.top ? -1 : 0); return(true); }
private void FillLabyrinthBlanksWithSnakes() { for (int i = 1; i < width; i++) { for (int j = 1; j < height; j++) { if (layout.CountWallsConnectedToJoint(i, j) == 0) { Snakewallhead snake = new Snakewallhead(i, j, layout); snake.AutoGrow(rnd); } } } }