Example #1
0
		private int CalculateRoomPlacementScore(Vector2I location, LabyrinthDungeon dungeon, Room room)
		{
			// Check if the room at the given location will fit inside the bounds of the map.
			if (Contains(dungeon.Bounds, location, room))
			{
				var roomPlacementScore = 0;

				// Loop for each cell in the room.
				for (var column = 0; column < room.Columns; column++)
				{
					for (var row = 0; row < room.Rows; row++)
					{
						// Translate the room cell location to its location in the dungeon.
						var dungeonLocation = location + new Vector2I(column, row);

						// Add 1 point for each adjacent corridor to the cell.
						if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.North))
						{
							roomPlacementScore++;
						}
						if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.South))
						{
							roomPlacementScore++;
						}
						if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.West))
						{
							roomPlacementScore++;
						}
						if (dungeon.AdjacentCellInDirectionIsCorridor(dungeonLocation, Direction.East))
						{
							roomPlacementScore++;
						}

						// Add 3 points if the cell overlaps an existing corridor.
						if (dungeon[dungeonLocation].IsCorridor)
						{
							roomPlacementScore += 3;
						}

						// Add 100 points if the cell overlaps any existing room cells.
						foreach (var dungeonRoom in dungeon.Rooms)
						{
							if (dungeonRoom.Bounds.Contains(dungeonLocation))
							{
								roomPlacementScore += 100;
							}
						}
					}
				}

				return roomPlacementScore;
			}
			else
			{
				return int.MaxValue;
			}
		}
Example #2
0
		private Room CreateRoom()
		{
			var room = new Room(_random.Next(MinRoomRows, MaxRoomRows + 1), _random.Next(MinRoomColumns, MaxRoomColumns + 1));
			room.InitializeRoomCells();
			return room;
		}
Example #3
0
		private bool Contains(RectI bounds, Vector2I roomLocation, Room room)
		{
			return
				bounds.Contains(roomLocation.X, roomLocation.Y) &&
				bounds.Contains(roomLocation.X + room.Columns - 1, roomLocation.Y) &&
				bounds.Contains(roomLocation.X + room.Columns - 1, roomLocation.Y + room.Rows - 1) &&
				bounds.Contains(roomLocation.X, roomLocation.Y + room.Rows - 1);
		}
Example #4
0
		private void PlaceRoom(Vector2I location, LabyrinthDungeon dungeon, Room room)
		{
			// Offset the room origin to the new location.
			room.SetLocation(location);

			// Loop for each cell in the room
			for (var row = 0; row < room.Rows; row++)
			{
				for (var column = 0; column < room.Columns; column++)
				{
					// Translate the room cell location to its location in the dungeon.
					var dungeonLocation = location + new Vector2I(column, row);
					dungeon[dungeonLocation].NorthSide = room[row, column].NorthSide;
					dungeon[dungeonLocation].SouthSide = room[row, column].SouthSide;
					dungeon[dungeonLocation].WestSide = room[row, column].WestSide;
					dungeon[dungeonLocation].EastSide = room[row, column].EastSide;

					// TODO: This part may be unnecessary.
					// Create room walls on map (either side of the wall)
					if ((column == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.West)))
					{
						dungeon.CreateWall(dungeonLocation, Direction.West);
					}
					if ((column == room.Columns - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.East)))
					{
						dungeon.CreateWall(dungeonLocation, Direction.East);
					}
					if ((row == 0) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.North)))
					{
						dungeon.CreateWall(dungeonLocation, Direction.North);
					}
					if ((row == room.Rows - 1) && (dungeon.HasAdjacentCellInDirection(dungeonLocation, Direction.South)))
					{
						dungeon.CreateWall(dungeonLocation, Direction.South);
					}
				}
			}

			dungeon.Rooms.Add(room);
		}