private void ConvertBPToTiles()
        {
            int minMonsterRooms = roomRegions.Count / 4;
            int maxMonsterRooms = (int)(roomRegions.Count / 1.5f);

            List <byte> temp = roomRegions;

            temp.RemoveAt(0);

            monsterRegions = GeneratorUtility.GetRandomListofByteFromList
                                 (rand, temp, minMonsterRooms, maxMonsterRooms);

            TileTexture textureType;

            Point startTile = GetStartTile();

            playerStart = GetTileCenter(startTile.X, startTile.Y);

            bossRoom = FindRoomFurthestFromStarAndMakeDictionaryWithRoomLengthsFromStart(startTile.X, startTile.Y);

            for (int y = 0; y < dungeonBP.GetLength(0); y++)
            {
                for (int x = 0; x < dungeonBP.GetLength(1); x++)
                {
                    textureType = TilePicker(x, y);
                    if (dungeonBP[y, x] == 0)
                    {
                        tiles[y, x] = new Tile(TileType.Wall, tileSet.GetTexture(TilePicker(x, y), dungeonBP[y, x]), false);
                    }
                    else
                    {
                        if (monsterRegions.Contains(dungeonBP[y, x]))
                        {
                            tiles[y, x] = new Tile(TileType.MonsterTile, tileSet.GetTexture(TilePicker(x, y), dungeonBP[y, x]), true);
                        }
                        else
                        {
                            tiles[y, x] = new Tile(TileType.basic, tileSet.GetTexture(TilePicker(x, y), dungeonBP[y, x]), true);
                        }
                    }
                }
            }

            tiles[startTile.Y, startTile.X].type = TileType.Portal;
            gameObjects.Add(new Point(startTile.X, startTile.Y), new Object.Portal(textures.portal, playerStart, true));
        }
        private void ConnectRegions()
        {
            byte r1, r2;

            List <Connector> connections = new List <Connector>();

            for (int y = 1; y < dungeonBP.GetLength(0) - 1; y++)
            {
                for (int x = 1; x < dungeonBP.GetLength(1) - 1; x++)
                {
                    if (dungeonBP[y, x] == 0 && ConnectionCheck(x, y, out r1, out r2))
                    {
                        connections.Add(new Connector(x, y, r1, r2));
                    }
                }
            }

            RemoveUnconnectableRegions(connections);

            List <byte> connectedRegions = new List <byte>();

            byte connectingTo = 1;

            connectedRegions.Add(1);
            List <int> possibleConnections = new List <int>();

            int index;

            HashSet <int> exlude = new HashSet <int>();

            while (connectedRegions.Count < totalRegions)
            {
                index        = GeneratorUtility.GetRandomNumberExcluding(rand, exlude, 0, connectedRegions.Count - 1);
                connectingTo = connectedRegions[index];

                possibleConnections.Clear();
                for (int i = 0; i < connections.Count; i++)
                {
                    if ((connections[i].Region1 == connectingTo || connections[i].Region2 == connectingTo) &&
                        (connectedRegions.Contains(connections[i].Region1) != connectedRegions.Contains(connections[i].Region2)))
                    {
                        possibleConnections.Add(i);
                    }
                }
                if (possibleConnections.Count > 0)
                {
                    index = rand.Next(0, possibleConnections.Count - 1);
                    dungeonBP[connections[possibleConnections[index]].Y, connections[possibleConnections[index]].X] = connections[possibleConnections[index]].Region1;
                    if (connectingTo == connections[possibleConnections[index]].Region1)
                    {
                        connectedRegions.Add(connections[possibleConnections[index]].Region2);
                    }
                    else
                    {
                        connectedRegions.Add(connections[possibleConnections[index]].Region1);
                    }
                    connections.RemoveAt(possibleConnections[index]);
                }
                else
                {
                    for (int i = 0; i < connectedRegions.Count; i++)
                    {
                        if (connectedRegions[i] == connectingTo)
                        {
                            exlude.Add(i);
                            break;
                        }
                    }
                }
            }

            int extraConnectorPercentage = 3;

            for (int i = 0; i < connections.Count; i++)
            {
                if (rand.Next(0, 100) < extraConnectorPercentage)
                {
                    dungeonBP[connections[i].Y, connections[i].X] = connections[i].Region1;
                }
            }

            //Fortsätt här
        }
        private bool GenerateMaze(Point start, byte region)
        {
            List <Point> floodList = new List <Point>();

            floodList.Clear();
            dungeonBP[start.Y, start.X] = region;
            floodList.Add(start);

            HashSet <int> exludePaths = new HashSet <int>();

            int  dir, index, connections;
            bool tileAdded;

            connections = 0;

            while (floodList.Count > 0)
            {
                exludePaths.Clear();
                tileAdded = false;
                index     = floodList.Count - 1;
                while (exludePaths.Count < 4 && !tileAdded)
                {
                    dir = GeneratorUtility.GetRandomNumberExcluding(rand, exludePaths, 0, 3);
                    if (dir == 0)
                    {
                        if (floodList[index].Y > 1 && floodList[index].X
                            > 0 && floodList[index].X < tiles.GetLength(1) - 1)
                        {
                            if (SampleDirectionReturnFalseIfNotSameNumber(floodList[index], new Point(0, -1), 0, 2))
                            {
                                dungeonBP[floodList[index].Y - 1, floodList[index].X] = region;
                                floodList.Add(floodList[index] + new Point(0, -1));
                                tileAdded = true;
                                connections++;
                            }
                        }
                    }
                    else if (dir == 1)
                    {
                        if (floodList[index].Y > 0 && floodList[index].Y
                            < tiles.GetLength(0) - 1 && floodList[index].X < tiles.GetLength(1) - 2)
                        {
                            if (SampleDirectionReturnFalseIfNotSameNumber(floodList[index], new Point(1, 0), 0, 2))
                            {
                                dungeonBP[floodList[index].Y, floodList[index].X + 1] = region;
                                floodList.Add(floodList[index] + new Point(1, 0));
                                tileAdded = true;
                                connections++;
                            }
                        }
                    }
                    else if (dir == 2)
                    {
                        if (floodList[index].X > 0 && floodList[index].Y
                            < tiles.GetLength(0) - 2 && floodList[index].X < tiles.GetLength(1) - 1)
                        {
                            if (SampleDirectionReturnFalseIfNotSameNumber(floodList[index], new Point(0, 1), 0, 2))
                            {
                                dungeonBP[floodList[index].Y + 1, floodList[index].X] = region;
                                floodList.Add(floodList[index] + new Point(0, 1));
                                tileAdded = true;
                                connections++;
                            }
                        }
                    }
                    else if (dir == 3)
                    {
                        if (floodList[index].X > 1 && floodList[index].Y
                            < tiles.GetLength(0) - 1 && floodList[index].Y > 0)
                        {
                            if (SampleDirectionReturnFalseIfNotSameNumber(floodList[index], new Point(-1, 0), 0, 2))
                            {
                                dungeonBP[floodList[index].Y, floodList[index].X - 1] = region;
                                floodList.Add(floodList[index] + new Point(-1, 0));
                                tileAdded = true;
                                connections++;
                            }
                        }
                    }
                    exludePaths.Add(dir);
                }
                if (!tileAdded)
                {
                    floodList.RemoveAt(index);
                }
            }

            if (connections == 0)
            {
                dungeonBP[start.Y, start.X] = 0;
                return(false);
            }
            return(true);
        }