Implemented bi-directional linking between rooms
This commit is contained in:
parent
e0c65bd66e
commit
eb7c43a4f1
2 changed files with 30 additions and 47 deletions
|
|
@ -46,14 +46,6 @@ namespace DungeonGenerator
|
||||||
return dungeonMap;
|
return dungeonMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RoomSide
|
|
||||||
{
|
|
||||||
Top,
|
|
||||||
Bottom,
|
|
||||||
Left,
|
|
||||||
Right
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddNormalRoomsAroundMonsterRooms(DungeonMap dungeon)
|
private void AddNormalRoomsAroundMonsterRooms(DungeonMap dungeon)
|
||||||
{
|
{
|
||||||
HashSet<Point> unoccupiedPoints = dungeon.GetUnoccupiedPoints();
|
HashSet<Point> unoccupiedPoints = dungeon.GetUnoccupiedPoints();
|
||||||
|
|
@ -130,6 +122,7 @@ namespace DungeonGenerator
|
||||||
Room newRoom = CreateAdjacentRoom(RoomType.Normal, unoccupiedPointsOnSide, side);
|
Room newRoom = CreateAdjacentRoom(RoomType.Normal, unoccupiedPointsOnSide, side);
|
||||||
if (newRoom != null)
|
if (newRoom != null)
|
||||||
{
|
{
|
||||||
|
monsterRoom.AddAdjacentRoom(newRoom, side);
|
||||||
newRooms.Add(newRoom);
|
newRooms.Add(newRoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,17 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Unity.VisualScripting;
|
using Unity.VisualScripting;
|
||||||
|
|
||||||
namespace DungeonGenerator
|
namespace DungeonGenerator
|
||||||
{
|
{
|
||||||
|
public enum RoomSide
|
||||||
|
{
|
||||||
|
Top,
|
||||||
|
Bottom,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}
|
||||||
public enum RoomType
|
public enum RoomType
|
||||||
{
|
{
|
||||||
Normal,
|
Normal,
|
||||||
|
|
@ -22,10 +30,7 @@ namespace DungeonGenerator
|
||||||
PositionOfTopLeft = positionOfTopLeft;
|
PositionOfTopLeft = positionOfTopLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Room> _topAdjacentRooms = new List<Room>();
|
private readonly Dictionary<RoomSide, List<Room>> _adjacentRooms = new();
|
||||||
private List<Room> _bottomAdjacentRooms = new List<Room>();
|
|
||||||
private List<Room> _leftAdjacentRooms = new List<Room>();
|
|
||||||
private List<Room> _rightAdjacentRooms = new List<Room>();
|
|
||||||
|
|
||||||
public RoomType TypeOfRoom { get; set; }
|
public RoomType TypeOfRoom { get; set; }
|
||||||
public int Height { get; set; }
|
public int Height { get; set; }
|
||||||
|
|
@ -58,44 +63,29 @@ namespace DungeonGenerator
|
||||||
return new Point(PositionOfTopLeft.X + Width / 2, PositionOfTopLeft.Y + Height / 2);
|
return new Point(PositionOfTopLeft.X + Width / 2, PositionOfTopLeft.Y + Height / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTopAdjacentRoom(Room room)
|
public void AddAdjacentRoom(Room room, RoomSide side)
|
||||||
{
|
{
|
||||||
_topAdjacentRooms.Add(room);
|
if (!_adjacentRooms.ContainsKey(side))
|
||||||
|
{
|
||||||
|
_adjacentRooms[side] = new List<Room>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Room> GetTopAdjaceRooms()
|
// Prevent duplicates
|
||||||
|
if (!_adjacentRooms[side].Contains(room))
|
||||||
{
|
{
|
||||||
return _topAdjacentRooms;
|
_adjacentRooms[side].Add(room);
|
||||||
|
room.AddAdjacentRoom(this, GetOppositeSide(side)); // Ensure bidirectional linkage
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddBottomAdjacentRoom(Room room)
|
// Helper method to get the opposite side
|
||||||
|
private RoomSide GetOppositeSide(RoomSide side) => side switch
|
||||||
{
|
{
|
||||||
_bottomAdjacentRooms.Add(room);
|
RoomSide.Top => RoomSide.Bottom,
|
||||||
}
|
RoomSide.Bottom => RoomSide.Top,
|
||||||
|
RoomSide.Left => RoomSide.Right,
|
||||||
public List<Room> GetBottomAdjaceRooms()
|
RoomSide.Right => RoomSide.Left,
|
||||||
{
|
_ => throw new ArgumentException("Invalid RoomSide", nameof(side))
|
||||||
return _bottomAdjacentRooms;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public void AddLeftAdjacentRoom(Room room)
|
|
||||||
{
|
|
||||||
_leftAdjacentRooms.Add(room);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Room> GetLeftAdjaceRooms()
|
|
||||||
{
|
|
||||||
return _leftAdjacentRooms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddRightAdjacentRoom(Room room)
|
|
||||||
{
|
|
||||||
_rightAdjacentRooms.Add(room);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Room> GetRightAdjaceRooms()
|
|
||||||
{
|
|
||||||
return _rightAdjacentRooms;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue