Example #1
0
    /**
     * Flips LabyrinthLayout in horizontal direction (mirror plane is vertical)
     *
     * @return new LabyrinthLayout - new object, this one is not modified
     */
    public LabyrinthLayout FlipHorizCellsArray()
    {
        int size_x = cells.GetLength(0);
        int size_y = cells.GetLength(1);

        LabyrinthLayout t = new LabyrinthLayout(size_x - 1, size_y - 1); // filled with closed cells

        for (int i = 1; i < size_x; i++)
        {
            for (int j = 0; j < size_y; j++)
            {
                int flip_column = size_x - i; // from 1 to size_x
                t.cells[i - 1, j].right = cells[flip_column, j].right;
                t.cells[i, j].right     = cells[flip_column - 1, j].right;
                t.cells[i, j].top       = cells[flip_column, j].top;
            }
        }

        return(t);
    }
Example #2
0
    /**
     * Flips LabyrinthLayout in vertical direction (mirror plane is horizontal)
     *
     * @return new LabyrinthLayout - new object, this one is not modified
     */
    public LabyrinthLayout FlipVertCellsArray()
    {
        int size_x = cells.GetLength(0);
        int size_y = cells.GetLength(1);

        LabyrinthLayout t = new LabyrinthLayout(size_x - 1, size_y - 1); // filled with closed cells

        for (int i = 0; i < size_x; i++)
        {
            for (int j = 1; j < size_y; j++)
            {
                int flip_row = size_y - j; // from 1 to size_y-1
                t.cells[i, j - 1].top = cells[i, flip_row].top;
                t.cells[i, j].top     = cells[i, flip_row - 1].top;
                t.cells[i, j].right   = cells[i, flip_row].right;
            }
        }

        return(t);
    }
Example #3
0
    /**
     * Flips LabyrinthLayout array by diagonal (0,0) to (n, n)
     *
     * @return new LabyrinthLayout - new object, this one is not modified
     *   null if dimensions of original array are not equal or othe error
     */
    public LabyrinthLayout FlipTurnCellsArray()
    {
        int size_x = cells.GetLength(0);
        int size_y = cells.GetLength(1);

        if (size_y != size_x)
        {
            return(null);
        }

        LabyrinthLayout t = new LabyrinthLayout(size_x - 1, size_y - 1);

        for (int i = 0; i < size_x; i++)
        {
            for (int j = 0; j < size_y; j++)
            {
                // turn+flip single cell
                CellStruct t_cell = new CellStruct(cells[i, j].right, cells[i, j].top);
                t.cells[j, i] = t_cell;
            }
        }

        return(t);
    }
Example #4
0
    // 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();
    }
Example #5
0
 public Snakewallhead(int _x, int _y, LabyrinthLayout _l)
 {
     x = _x; y = _y; l = _l;
 }