Ejemplo n.º 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;
            }
        }
    }
Ejemplo n.º 2
0
        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);
        }
    private void RandomFlagPick(int count)
    {
        var tempColorArr = ShuffleUtility <FlagColor> .GetShuffledArray((FlagColor[])Enum.GetValues(typeof(FlagColor)));

        Array.Resize(ref tempColorArr, count);

        for (var i = 0; i < count; i++)
        {
            flagList.Add(tempColorArr[i]);
        }
        uiFlagDisplay.FlagUIInitialize(tempColorArr);
    }
Ejemplo n.º 4
0
    private void Awake()
    {
        if (npcCount > spawnPoint.Length)
        {
            Debug.LogError("[ERROR] NPC Count is higher then NPC Spawn Point. Reduced to Spawn Point Count.");
            npcCount = spawnPoint.Length;
        }

        NPCNames = ShuffleUtility <string> .GetShuffledArray(NPCNames, 2);

        spawnPoint = ShuffleUtility <Transform> .GetShuffledArray(spawnPoint, 2);

        dialogues = ShuffleUtility <DialogueData> .GetShuffledArray(dialogues, 2);

        flags = ShuffleUtility <FlagColor> .GetShuffledArray((FlagColor[])Enum.GetValues(typeof(FlagColor)));
    }
Ejemplo n.º 5
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++;
            }
        }
    }