Пример #1
0
        public void CorridorRoomWorks()
        {
            var room = new CorridorRoom(3, 10, 3);

            Assert.True(room.HasDoorwayTo(3));
            Assert.True(room.HasDoorwayTo(1));
        }
Пример #2
0
        public void RoomCanHaveEnemies()
        {
            var room = new CorridorRoom(10, 10, 2);

            Assert.That(room.Enemies == 0);

            room.Enemies = 4;

            Assert.That(room.Enemies == 4);
        }
Пример #3
0
        /// <summary>
        /// Create and place and DungeonRooms and Corridors from the generated dungeons.
        /// </summary>
        /// <param name="dungeon">The dungeon that was just generated.</param>
        /// <param name="levelNumber">The number of the level.</param>
        /// <param name="timer">The current used DungeonTimer.</param>
        /// <returns></returns>
        public IEnumerator CreateRooms(Dungeon dungeon, int levelNumber, DungeonConfig config, DungeonTimer timer)
        {
            List <DungeonRoom> dungeonRooms = new List <DungeonRoom>();

            DungeonDict.Instance.ResetRooms(dungeon.Rooms.Length + dungeon.Corridors.Length);

            GameObject prefabDoorLR = RegionDict.Instance.PrefabDoorLR;
            GameObject prefabDoorUD = RegionDict.Instance.PrefabDoorUD;

            // Create DungeonRooms
            for (int i = 0; i < dungeon.Rooms.Length; i++)
            {
                GameObject dungeonRoomObject = Instantiate(DungeonCreator.Instance.PrefabDungeonRoom);
                dungeonRoomObject.transform.parent = DungeonCreator.Instance.RoomsContainer;

                DungeonRoom dungeonRoom = SetRoomType(dungeon.Rooms[i], dungeonRoomObject, levelNumber, config);
                // set room id
                dungeonRoom.id = i;

                DungeonDict.Instance.Register(dungeonRoom);

                SetRoomBorder(dungeon, i, dungeonRoom);
                SetRoomObjects(dungeon.Rooms[i], dungeonRoomObject, dungeonRoom);
                SetDoors(dungeon, prefabDoorLR, prefabDoorUD, i, dungeonRoomObject, dungeonRoom);

                dungeonRooms.Add(dungeonRoom);
                dungeonRoom.OnFullyCreated();

                if (timer.ShouldWait())
                {
                    yield return(timer.Wait(0.9f + ((i * 1.0f / dungeon.Rooms.Length) * 0.05f)));
                }
            }
            // Create corridors.
            for (int i = 0; i < dungeon.Corridors.Length; i++)
            {
                Corridor   corridor       = dungeon.Corridors[i];
                GameObject corridorObject = new GameObject("Corridor_" + i);
                corridorObject.transform.parent = DungeonCreator.Instance.CorridorContainer;

                CorridorRoom corridorRoom = corridorObject.AddComponent <CorridorRoom>();
                corridorRoom.id            = dungeon.Rooms.Length + i;
                corridorRoom.walkableTiles = corridor.GetWalkableTiles();
                corridorRoom.direction     = corridor.Size.y == 3;
                SetCorridorBorder(corridor, corridorRoom);
                DungeonDict.Instance.Register(corridorRoom);
            }
        }
Пример #4
0
        /// <summary>
        /// Sets the Border of a corridor.
        /// </summary>
        /// <param name="corridor">The current Corridor.</param>
        /// <param name="corridorRoom">The current generated CorridorRoom.</param>
        private void SetCorridorBorder(Corridor corridor, CorridorRoom corridorRoom)
        {
            switch (corridor.Direction)
            {
            case Direction.Right:
                corridorRoom.ForceBorder(new Rect(corridor.Position.x + 1, corridor.Position.y, corridor.Size.x - 1, corridor.Size.y));
                break;

            case Direction.Left:
                corridorRoom.ForceBorder(new Rect(corridor.Position.x, corridor.Position.y, corridor.Size.x - 1, corridor.Size.y));
                break;

            case Direction.Up:
                corridorRoom.ForceBorder(new Rect(corridor.Position.x, corridor.Position.y + 1, corridor.Size.x, corridor.Size.y - 1));
                break;

            case Direction.Down:
                corridorRoom.ForceBorder(new Rect(corridor.Position.x, corridor.Position.y, corridor.Size.x, corridor.Size.y - 1));
                break;

            default:
                break;
            }
        }