예제 #1
0
    string GetLinearRegionConditions(int linearDir, Tile tile, Maze maze, int height, List <int> wallsShouldntContain)
    {
        Utilities.TryCatchError(((linearDir < 0) || (linearDir > 1)), "Input parameter 'linearDir' can only be North or East");
        if (wallsShouldntContain.Contains(linearDir))
        {
            wallsShouldntContain.Remove(linearDir);
        }

        string region = "";
        int    startID;
        int    length;

        if (linearDir == 0)
        {
            startID = tile.Z;
            length  = maze.mazeLength;
        }
        else
        {
            startID = tile.X;
            length  = maze.mazeWidth;
        }

        for (int i = startID; i < length; i++)
        {
            Tile currTile;
            bool containWrongWalls = false;

            // Get current tile based on linear direction
            if (linearDir == 0)
            {
                currTile = maze.mazeTile[tile.X, i];
            }
            else
            {
                currTile = maze.mazeTile[i, tile.Z];
            }

            // Check if this tile contains walls we don't want
            foreach (int wall in wallsShouldntContain)
            {
                if (MazeUTL.WallOnDir(currTile, wall))
                {
                    containWrongWalls = true;
                    break;
                }
            }
            if (containWrongWalls)
            {
                break;
            }

            // Pass check, add the tile to region
            region += MazeUTL.GetTileAddress(currTile.X, currTile.Z);

            // After adding, check if we can keep going to the next tile
            if (region.Length == height)
            {
                break;
            }
            if (MazeUTL.WallOnDir(currTile, linearDir))
            {
                break;
            }
        }

        return(region);
    }