Fixed entrance rooms starting off of the boarder and improved clarity of printed map.
This commit is contained in:
parent
64fbb67397
commit
024e0ae514
3 changed files with 65 additions and 42 deletions
|
|
@ -24,7 +24,8 @@ namespace DungeonGenerator
|
|||
_yLength = 28;
|
||||
|
||||
Random random = new Random();
|
||||
_entrancePoints = GenerateEntrancePoints(_xLength, _yLength, random.Next(1,4));
|
||||
List<Room> entranceRooms = GenerateEntranceRooms(_xLength, _yLength, random.Next(1,4));
|
||||
_entrancePoints = entranceRooms.SelectMany(room => room.GetPointsInRoom()).ToList();
|
||||
|
||||
EvenDisperser disperser = new EvenDisperser(_xLength, _yLength, _entrancePoints); //TODO calculate L and W from length
|
||||
int numberOfMonsterRooms = 7; // TODO: Calculate from ratio
|
||||
|
|
@ -41,6 +42,7 @@ namespace DungeonGenerator
|
|||
|
||||
public void PrintMap()
|
||||
{
|
||||
List<Point> monsterRoomPoints = _monsterRooms.SelectMany(room => room.GetPointsInRoom()).ToList();
|
||||
char[,] mapMatrix = new Char[_xLength, _yLength];
|
||||
for (int x = 0; x < _xLength; x++)
|
||||
{
|
||||
|
|
@ -50,13 +52,13 @@ namespace DungeonGenerator
|
|||
{
|
||||
mapMatrix[x, y] = '*';
|
||||
}
|
||||
else if (_monsterRooms.Any(room => room.PositionOfTopLeft.Equals(new Point(x,y))))
|
||||
else if (monsterRoomPoints.Contains(new Point(x,y)))
|
||||
{
|
||||
mapMatrix[x, y] = 'X';
|
||||
}
|
||||
else
|
||||
{
|
||||
mapMatrix[x, y] = 'O';
|
||||
mapMatrix[x, y] = '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -86,15 +88,15 @@ namespace DungeonGenerator
|
|||
Left
|
||||
}
|
||||
|
||||
private List<Point> GenerateEntrancePoints(int xLengthOfDungeon, int yLengthOfDungeon, int numberOfEntranceLines)
|
||||
private List<Room> GenerateEntranceRooms(int xLengthOfDungeon, int yLengthOfDungeon, int numberOfEntranceLines)
|
||||
{
|
||||
if (numberOfEntranceLines > 4)
|
||||
{
|
||||
throw new Exception("Number of entrance lines cannot be greater than 4");
|
||||
}
|
||||
|
||||
const int entranceSpaces = 12;
|
||||
List<Point> entrancePoints = new List<Point>();
|
||||
const int numEntranceRooms = 12;
|
||||
List<Room> entranceRooms = new List<Room>();
|
||||
Random random = new Random();
|
||||
Dictionary<Side, int> sidesToEnterOn = new()
|
||||
{
|
||||
|
|
@ -118,30 +120,31 @@ namespace DungeonGenerator
|
|||
}
|
||||
}
|
||||
|
||||
int pointsPerLine = entranceSpaces / numberOfEntranceLines;
|
||||
int roomsPerLine = numEntranceRooms / numberOfEntranceLines;
|
||||
int bottom = yLengthOfDungeon - SIDE_LENGTH_OF_NORMAL;
|
||||
int oneRoomFromBottom = bottom - SIDE_LENGTH_OF_NORMAL;
|
||||
int right = xLengthOfDungeon - SIDE_LENGTH_OF_NORMAL;
|
||||
// Generate entrance lines on each side
|
||||
switch (sidesToEnterOn[Side.Top])
|
||||
{
|
||||
case 2:
|
||||
// Add half of points for this entrance line to the top left side
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(i,0));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(i,0)));
|
||||
}
|
||||
|
||||
// Add the rest of the points for this entrance line to the top right side.
|
||||
int pointsRemaining = pointsPerLine;
|
||||
for (var i = 0; i < pointsRemaining; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point((xLengthOfDungeon - 1) - i,0));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right - i,0)));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
int midpoint = xLengthOfDungeon / 2;
|
||||
int startOfLine = midpoint - (pointsPerLine / 2);
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
int startOfLine = GetStartOfCenteredLine(xLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL);
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(startOfLine + i, 0));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL,new Point(startOfLine + i, 0)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -150,23 +153,22 @@ namespace DungeonGenerator
|
|||
{
|
||||
case 2:
|
||||
// Add points for this entrance line to the top right side
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(xLengthOfDungeon - 1, i + 1));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, i + SIDE_LENGTH_OF_NORMAL)));
|
||||
}
|
||||
|
||||
// Add the rest of the points for this entrance line to the bottom right side.
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(xLengthOfDungeon - 1, (yLengthOfDungeon - 2) - i));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, oneRoomFromBottom - i)));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
int midpoint = yLengthOfDungeon / 2;
|
||||
int startOfLine = midpoint - (pointsPerLine / 2);
|
||||
for (int i = 0; i < pointsPerLine; i++)
|
||||
int startOfLine = GetStartOfCenteredLine(xLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL);
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(xLengthOfDungeon - 1, startOfLine + i));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(right, startOfLine + i)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -175,23 +177,22 @@ namespace DungeonGenerator
|
|||
{
|
||||
case 2:
|
||||
// Add half of points for this entrance line to the bottom left side
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(i, yLengthOfDungeon - 1));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(i, bottom)));
|
||||
}
|
||||
|
||||
// Add the rest of the points for this entrance line to the bottom right side.
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point((xLengthOfDungeon - 1) - i, yLengthOfDungeon - 1));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point((xLengthOfDungeon - 1) - i, bottom)));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
int midpoint = xLengthOfDungeon / 2;
|
||||
int startOfLine = midpoint - (pointsPerLine / 2);
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
int startOfLine = GetStartOfCenteredLine(xLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL);
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(startOfLine + i, yLengthOfDungeon - 1));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(startOfLine + i, bottom)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -200,28 +201,33 @@ namespace DungeonGenerator
|
|||
{
|
||||
case 2:
|
||||
// Add half of points for this entrance line to the top left side
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(0, i + 1));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, i + SIDE_LENGTH_OF_NORMAL)));
|
||||
}
|
||||
|
||||
// Add the rest of the points for this entrance line to the bottom left side.
|
||||
for (var i = 0; i < pointsPerLine; i++)
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(0, (yLengthOfDungeon - 1) - i));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, oneRoomFromBottom - i)));
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
int midpoint = yLengthOfDungeon / 2;
|
||||
int startOfLine = midpoint - (pointsPerLine / 2);
|
||||
for (int i = 0; i < pointsPerLine; i++)
|
||||
int startOfLine = GetStartOfCenteredLine(xLengthOfDungeon, roomsPerLine, SIDE_LENGTH_OF_NORMAL);
|
||||
for (var i = 0; i < roomsPerLine * SIDE_LENGTH_OF_NORMAL; i += SIDE_LENGTH_OF_NORMAL)
|
||||
{
|
||||
entrancePoints.Add(new Point(0, startOfLine + i));
|
||||
entranceRooms.Add(new Room(RoomType.Entrance, SIDE_LENGTH_OF_NORMAL, SIDE_LENGTH_OF_NORMAL, new Point(0, startOfLine + i)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return entrancePoints;
|
||||
return entranceRooms;
|
||||
}
|
||||
|
||||
private int GetStartOfCenteredLine(int length, int numberOfRooms, int sizeOfRoom)
|
||||
{
|
||||
int midpoint = length / 2;
|
||||
return midpoint - (numberOfRooms * sizeOfRoom / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue