Exemple #1
0
    private void Connect(bool[,] maze, int x, int y)
    {
        int[,] directions = new int[, ]
        {
            { -1, 0 },
            { 1, 0 },
            { 0, -1 },
            { 0, 1 }
        };

        ShuffleUtility.Shuffle(directions);

        for (int i = 0; i < directions.GetLength(0); i++)
        {
            // Нужно направление умножать на 2
            // чтоб оставлять стенку размером в 1 ячейку
            int neighborX = x + directions[i, 0] * 2;
            int neighborY = y + directions[i, 1] * 2;

            if (MazeHelper.IsRoad(maze, neighborX, neighborY))
            {
                int connectorX = x + directions[i, 0];
                int connectorY = y + directions[i, 1];
                maze[connectorY, connectorX] = true;

                return;
            }
        }
    }
        public void SuffleMockNone()
        {
            var array           = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var expected        = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var randomizeHelper = new RandomizeNone();
            var result          = ShuffleUtility.Shuffle(array, randomizeHelper);

            Assert.Equal(expected, result);
        }
Exemple #3
0
    private void AddGaps(bool[,] maze, float gapsChance)
    {
        int shortCutsTarget = (int)(maze.Length * gapsChance);
        int shortcuts       = 0;

        if (shortCutsTarget <= 0)
        {
            return;
        }

        List <Tuple <int, int> > allWalls = new List <Tuple <int, int> >();

        for (int i = 0; i < maze.GetLength(0); i++)
        {
            for (int j = 0; j < maze.GetLength(1); j++)
            {
                if (maze[i, j] == false)
                {
                    allWalls.Add(new Tuple <int, int>(i, j));
                }
            }
        }

        ShuffleUtility.Shuffle(allWalls);

        for (int i = 0; i < allWalls.Count && shortcuts < shortCutsTarget; i++)
        {
            int x = allWalls[i].Item2;
            int y = allWalls[i].Item1;

            if (CanBeShortCut(maze, x, y))
            {
                maze[y, x] = true;
                shortcuts++;
            }
        }
    }