Beispiel #1
0
        public CaveBoard asBoard()
        {
            checkConstraints();

            Board board = _dunGen.asBoard();
            ShapeCellularAutomaton     roomAlgo    = new ShapeCellularAutomaton(_seed, _cellularFillChance, _cellularSmoothingStep);
            CustomSeededPickerStrategy shapePicker = new CustomSeededPickerStrategy(_seed);

            CaveBoard      result    = new CaveBoard(board.rows(), board.cols());
            List <IXShape> onlyRooms = new List <IXShape>();

            _logger.info("Rooms: " + board.rooms().Length);
            foreach (Room each in board.rooms())
            {
                Cell       leftVert = each.topLeftVertex();
                int        rows     = each.height();
                int        cols     = each.width();
                APolyShape currentRoom; //Select a shape for the Room
                if (shapePicker.drawBetween(0, 100) < 50)
                {
                    currentRoom = new RectShape(leftVert, new OIGrid(rows, cols));
                }
                else
                {
                    currentRoom = new ElliShape(leftVert, new OIGrid(rows, cols));
                }
                _logger.info("Shape type: " + currentRoom.GetType());
                roomAlgo.applyOn(currentRoom);

                _logger.info("Shape regions before clean: " + currentRoom.regionsNumber());
                if (!currentRoom.hasRegions())
                {
                    _logger.warning("No Region found. Room will be skipped!!!");
                    continue;
                }
                currentRoom.deleteRegionsButTheBiggest();
                _logger.info("Shape regions after clean: " + currentRoom.regionsNumber());


                onlyRooms.Add(currentRoom);
                if (onlyRooms.Count > 1)
                {
                    IXShape  previousRoom    = onlyRooms[onlyRooms.Count - 2];
                    int      corrIndex       = onlyRooms.Count - 2;
                    Corridor corr            = board.corridors()[corrIndex];
                    int      corridorSection = corr.isVertical() ? corr.width() : corr.height();
                    result.addCorridor(CaveCorridorFactory.createCorrShape(previousRoom, currentRoom, corridorSection));
                }
                result.addRoom(currentRoom);
            }
            return(result);
        }
Beispiel #2
0
    public static void printForTest(int seed, params APolyShape[] rooms)
    {
        ShapeCellularAutomaton auto = new ShapeCellularAutomaton(seed, 75, 4);
        CaveBoard board             = new CaveBoard(50, 50);

        for (int i = 0; i < rooms.Length; i++)
        {
            APolyShape currRoom = rooms[i];
            auto.applyOn(currRoom);
            currRoom.deleteRegionsButTheBiggest();

            if (i > 0)
            {
                IXShape prevRoom = rooms[i - 1];
                IXShape corr     = CaveCorridorFactory.createCorrShape(prevRoom, currRoom, 2);
                board.addCorridor(corr);
            }
            board.addRoom(currRoom);
        }

        printForTest(board);
    }