Exemple #1
0
        private void PlaceDoors(LabyrinthDungeon dungeon)
        {
            foreach (var room in dungeon.Rooms)
            {
                var hasNorthDoor = false;
                var hasSouthDoor = false;
                var hasWestDoor  = false;
                var hasEastDoor  = false;

                // TODO: Convert this into 4 loops on the sides of the room.
                for (var row = 0; row < room.Rows; row++)
                {
                    for (var column = 0; column < room.Columns; column++)
                    {
                        var cellLocation = new Vector2I(column, row);

                        // Translate the room cell location to its location in the dungeon:
                        var dungeonLocation = new Vector2I(room.Bounds.X, room.Bounds.Y) + cellLocation;

                        // Check if we are on the west boundary of our roomand if there is a corridor to the west:
                        if (!hasWestDoor && (cellLocation.X == 0) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.West))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.West);
                            hasWestDoor = true;
                        }

                        // Check if we are on the east boundary of our room and if there is a corridor to the east
                        if (!hasEastDoor && (cellLocation.X == room.Columns - 1) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.East))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.East);
                            hasEastDoor = true;
                        }

                        // Check if we are on the north boundary of our room and if there is a corridor to the north
                        if (!hasNorthDoor && (cellLocation.Y == 0) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.North))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.North);
                            hasNorthDoor = true;
                        }

                        // Check if we are on the south boundary of our room and if there is a corridor to the south
                        if (!hasSouthDoor && (cellLocation.Y == room.Rows - 1) &&
                            dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.South))
                        {
                            dungeon.CreateDoor(dungeonLocation, Direction.South);
                            hasSouthDoor = true;
                        }
                    }
                }
            }
        }
		private void PlaceDoors(LabyrinthDungeon dungeon)
		{
			foreach (var room in dungeon.Rooms)
			{
				var hasNorthDoor = false;
				var hasSouthDoor = false;
				var hasWestDoor = false;
				var hasEastDoor = false;

				// TODO: Convert this into 4 loops on the sides of the room.
				for (var row = 0; row < room.Rows; row++)
				{
					for (var column = 0; column < room.Columns; column++)
					{
						var cellLocation = new Vector2I(column, row);

						// Translate the room cell location to its location in the dungeon:
						var dungeonLocation = new Vector2I(room.Bounds.X, room.Bounds.Y) + cellLocation;

						// Check if we are on the west boundary of our roomand if there is a corridor to the west:
						if (!hasWestDoor && (cellLocation.X == 0) &&
							dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.West))
						{
							dungeon.CreateDoor(dungeonLocation, Direction.West);
							hasWestDoor = true;
						}

						// Check if we are on the east boundary of our room and if there is a corridor to the east
						if (!hasEastDoor && (cellLocation.X == room.Columns - 1) &&
							dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.East))
						{
							dungeon.CreateDoor(dungeonLocation, Direction.East);
							hasEastDoor = true;
						}

						// Check if we are on the north boundary of our room and if there is a corridor to the north
						if (!hasNorthDoor && (cellLocation.Y == 0) &&
							dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.North))
						{
							dungeon.CreateDoor(dungeonLocation, Direction.North);
							hasNorthDoor = true;
						}

						// Check if we are on the south boundary of our room and if there is a corridor to the south
						if (!hasSouthDoor && (cellLocation.Y == room.Rows - 1) &&
							dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.South))
						{
							dungeon.CreateDoor(dungeonLocation, Direction.South);
							hasSouthDoor = true;
						}
					}
				}
			}
		}