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); } } } }
// private void Crucify (int x, int y) { // for (int i=1; i < width; i++) { // layout[i, y].right = true; // } // for (int i=1; i < height; i++) { // layout[x, i].top = true; // } // } // /** // * Labyrinth generation with crosses. // */ // public void GenerateLabyrinthCrosses (int width, int height) { // layout = new LabyrinthLayout(width, height); // // player position // if (width >= 7) { // playerSpawnX = rnd.Next(4, width-2); // } else { // playerSpawnX = rnd.Next(1, width+1); // } // if (height >= 7) { // playerSpawnY = rnd.Next(4, height-2); // } else { // playerSpawnY = rnd.Next(1, height+1); // } // Crucify(playerSpawnX, playerSpawnY); // // int cross_count = top_dimention / 7 -1; // // while (cross_count > 0) { // // Crucify(rnd.Next(1, width), rnd.Next(1, height)); // // cross_count--; // // } // } /** * Labyrinth generation with crosses. */ public void GenerateLabyrinthWallsnakes(int width, int height) { layout = new LabyrinthLayout(width, height); // player position if (width >= 7) { playerSpawnX = rnd.Next(4, width - 2); } else { playerSpawnX = rnd.Next(1, width + 1); } if (height >= 7) { playerSpawnY = rnd.Next(4, height - 2); } else { playerSpawnY = rnd.Next(1, height + 1); } // clear all inner walls layout.OpenInnerWalls(); // create a bunch of wall seeds int seeds_count = width * height / 10; // generate snakes Snakewallhead[] heads = new Snakewallhead[seeds_count * 2]; for (int i = 0; i < seeds_count; i += 2) { int x = rnd.Next(1, width); int y = rnd.Next(1, height); heads[i] = new Snakewallhead(x, y, layout); heads[i + 1] = new Snakewallhead(x, y, layout); // duplicate } // grow wall snakes bool had_growth = true; while (had_growth) { had_growth = false; for (int i = 0; i < seeds_count; i++) { if (heads[i] != null) { if (heads[i].Grow(rnd)) { had_growth = true; } else { heads[i] = null; } } } } // problems: // 1: not touching the border // 2: can have dead ends // filter out the dead ends // detect blank spots and ELIMINATE! FillLabyrinthBlanksWithSnakes(); }