Esempio n. 1
0
        public Board resize(int mapMargin)
        {
            if (mapMargin < 0)
            {
                return(this);
            }

            Board resized = new Board(rows() + mapMargin * 2, cols() + mapMargin * 2);

            foreach (IShape each in _roomsAndCorridors)
            {
                if (each is Room)
                {
                    Room r         = (Room)each;
                    Cell vert      = r.topLeftVertex().plusCell(mapMargin, mapMargin);
                    Room relocated = new Room(vert, r.grid());
                    resized.addRoom(relocated);
                }
                else
                {
                    Corridor             c         = (Corridor)each;
                    Cell                 vert      = c.topLeftVertex().plusCell(mapMargin, mapMargin);
                    Corridor.Orientation orient    = c.isOrizontal() ? Corridor.Orientation.horizontal : Corridor.Orientation.vertical;
                    Corridor             relocated = new Corridor(vert, c.grid(), orient);
                    resized.addCorridor(relocated);
                }
            }
            return(resized);
        }
Esempio n. 2
0
        private Corridor generateCorridor(CardinalPoint mapDirection, Room lastRoom, IntInRangePicker corrLengthPicker, IntInRangePicker corrWidthPicker, CellInRangePicker cellRangePicker)
        {
            int corridorLenght  = corrLengthPicker.draw();
            int corridorSection = corrWidthPicker.draw();

            Corridor.Orientation corrOrient = 0;
            Grid grid        = null;
            Cell topLeftCell = lastRoom.topLeftVertex();

            if (mapDirection == CardinalPoint.NORD)
            {
                grid       = new Grid(corridorLenght, corridorSection);
                corrOrient = Corridor.Orientation.vertical;
                Cell topLeftVertexMin = lastRoom.topLeftVertex().minusSize(corridorLenght, 0);
                Cell topLeftVertexMax = topLeftVertexMin.plusCell(0, lastRoom.width() - corridorSection);
                //Excluding cells to avoid Inward and Outward Corner Walls Overlapping
                Cell excludeOne = topLeftVertexMin.plusCell(0, 1);
                Cell excludeTwo = topLeftVertexMax.minusCell(0, 1);
                topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo);
                _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo);
            }
            else if (mapDirection == CardinalPoint.EST)
            {
                grid       = new Grid(corridorSection, corridorLenght);
                corrOrient = Corridor.Orientation.horizontal;
                Cell topLeftVertexMin = lastRoom.topRightVertex();
                Cell topLeftVertexMax = topLeftVertexMin.plusCell(lastRoom.height() - corridorSection, 0);
                //Excluding cells to avoid Inward and Outward Corner Walls Overlapping
                Cell excludeOne = topLeftVertexMin.plusCell(1, 0);
                Cell excludeTwo = topLeftVertexMax.minusCell(1, 0);
                topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo);
                _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo);
            }
            else if (mapDirection == CardinalPoint.SUD)
            {
                grid       = new Grid(corridorLenght, corridorSection);
                corrOrient = Corridor.Orientation.vertical;
                Cell topLeftVertexMin = lastRoom.bottomLeftVertex();
                Cell topLeftVertexMax = topLeftVertexMin.plusCell(0, lastRoom.width() - corridorSection);
                //Excluding cells to avoid Inward and Outward Corner Walls Overlapping
                Cell excludeOne = topLeftVertexMin.plusCell(0, 1);
                Cell excludeTwo = topLeftVertexMax.minusCell(0, 1);
                topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo);
                _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo);
            }
            else if (mapDirection == CardinalPoint.WEST)
            {
                grid       = new Grid(corridorSection, corridorLenght);
                corrOrient = Corridor.Orientation.horizontal;
                Cell topLeftVertexMin = lastRoom.topLeftVertex().minusSize(0, corridorLenght);
                Cell topLeftVertexMax = topLeftVertexMin.plusCell(lastRoom.height() - corridorSection, 0);
                //Excluding cells to avoid Inward and Outward Corner Walls Overlapping
                Cell excludeOne = topLeftVertexMin.plusCell(1, 0);
                Cell excludeTwo = topLeftVertexMax.minusCell(1, 0);
                topLeftCell = cellRangePicker.drawBetweenWithExclusion(topLeftVertexMin, topLeftVertexMax, excludeOne, excludeTwo);
                _logger.info("Min: " + topLeftVertexMin + " Max: " + topLeftVertexMax + " Selected: " + topLeftCell + " Exclusions: " + excludeOne + " - " + excludeTwo);
            }
            return(new Corridor(topLeftCell, grid, corrOrient));
        }
Esempio n. 3
0
        public Board crop(int marginToAddAfterCrop)
        {
            Cell upperTopLeftVert       = null;
            Cell righterBottomRightVert = null;
            Cell downerBottomRightVert  = null;
            Cell lefterTopLeftVert      = null;

            foreach (Room each in rooms())
            {
                if (upperTopLeftVert == null)
                {
                    upperTopLeftVert       = each.topLeftVertex();
                    righterBottomRightVert = each.bottomRightVertex();
                    downerBottomRightVert  = righterBottomRightVert;
                    lefterTopLeftVert      = upperTopLeftVert;
                }
                else
                {
                    if (each.topLeftVertex().isRowLesserThan(upperTopLeftVert))
                    {
                        upperTopLeftVert = each.topLeftVertex();
                    }
                    if (each.bottomRightVertex().isColGreatherThan(righterBottomRightVert))
                    {
                        righterBottomRightVert = each.bottomRightVertex();
                    }
                    if (each.bottomRightVertex().isRowGreatherThan(downerBottomRightVert))
                    {
                        downerBottomRightVert = each.bottomRightVertex();
                    }
                    if (each.topLeftVertex().isColLesserThan(lefterTopLeftVert))
                    {
                        lefterTopLeftVert = each.topLeftVertex();
                    }
                }
            }

            int rows = downerBottomRightVert.row() - upperTopLeftVert.row() + 1 + marginToAddAfterCrop * 2;
            int cols = righterBottomRightVert.col() - lefterTopLeftVert.col() + 1 + marginToAddAfterCrop * 2;

            int cropUp   = upperTopLeftVert.row() - marginToAddAfterCrop;
            int cropLeft = lefterTopLeftVert.col() - marginToAddAfterCrop;

            Board cropped = new Board(rows, cols);

            foreach (IShape each in _roomsAndCorridors)
            {
                if (each is Room)
                {
                    Room r         = (Room)each;
                    Cell vert      = r.topLeftVertex().minus(cropUp, cropLeft);
                    Room relocated = new Room(vert, r.grid());
                    cropped.addRoom(relocated);
                }
                else
                {
                    Corridor             c         = (Corridor)each;
                    Cell                 vert      = c.topLeftVertex().minus(cropUp, cropLeft);
                    Corridor.Orientation orient    = c.isOrizontal() ? Corridor.Orientation.horizontal : Corridor.Orientation.vertical;
                    Corridor             relocated = new Corridor(vert, c.grid(), orient);
                    cropped.addCorridor(relocated);
                }
            }
            return(cropped);
        }