Пример #1
0
        public Tile GetRandomTile()
        {
            int row = DungeonGenerator.Rng.Next(FirstRow, FirstRow + Height);
            int col = DungeonGenerator.Rng.Next(FirstCol, FirstCol + Width);

            return(Dungeon.GetTile(row, col));
        }
Пример #2
0
        /// <summary>
        /// Determines if a room can be placed where it is, or if it must be discarded.
        /// Notably, all open tiles in the room must be rock.
        /// The walls of this room can overlap with walls of other rooms.
        /// </summary>
        /// <returns></returns>
        public bool CanRoomFit()
        {
            // Is origin corner within the dungeon?
            if (!Dungeon.IsTileWithinDungeon(Outer.FirstRow, Outer.FirstCol))
            {
                return(false);
            }
            // Is far corner within the dungeon?
            if (!Dungeon.IsTileWithinDungeon(Outer.FirstRow + Outer.Height - 1,
                                             Outer.FirstCol + Outer.Width - 1))
            {
                return(false);
            }

            // Does the room including outer walls overlap with anything?
            int rowToStop = Outer.FirstRow + Outer.Height;
            int colToStop = Outer.FirstCol + Outer.Width;

            for (int row = Outer.FirstRow; row < rowToStop; row++)
            {
                for (int col = Outer.FirstCol; col < colToStop; col++)
                {
                    // Existing room wall tiles are allowed to overlap
                    // This allows walls to be shared by rooms
                    if (Dungeon.GetTile(row, col).Space != Space.Rock &&
                        Dungeon.GetTile(row, col).Space != Space.Wall)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Finds all tiles surrounding the walkable room space.
        /// Also initializes the tiles' direction -- walls face outward.
        /// Corners are excluded.
        /// </summary>
        public void FindWallLocations()
        {
            walls = new List <Tile>();
            Tile tile;

            for (int row = FirstRow; row < FirstRow + Height; row++)
            {
                tile           = Dungeon.GetTile(row, Outer.FirstCol);
                tile.Direction = Direction.Left;
                walls.Add(tile);
                tile           = Dungeon.GetTile(row, Outer.FirstCol + Outer.Width - 1);
                tile.Direction = Direction.Right;
                walls.Add(tile);
            }
            for (int col = FirstCol; col < FirstCol + Width; col++)
            {
                tile           = Dungeon.GetTile(Outer.FirstRow, col);
                tile.Direction = Direction.Up;
                walls.Add(tile);
                tile           = Dungeon.GetTile(Outer.FirstRow + Outer.Height - 1, col);
                tile.Direction = Direction.Down;
                walls.Add(tile);
            }
        }