public virtual ILocationGenerator.CellType[,] Create(Random random, out Point[] places) { var cells = new ILocationGenerator.CellType[Width, Height]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (x == 0 || x == Width - 1 || y == 0 || y == Height - 1) { cells[x, y] = ILocationGenerator.CellType.Wall; } else { cells[x, y] = ILocationGenerator.CellType.Floor; } } } places = new Point[1]; places[0] = new Point((int)Width / 2, (int)Height / 2); return(cells); }
public ILocationGenerator.CellType[,] Create(Random random, out Point[] places) { var cells = new ILocationGenerator.CellType[Width, Height]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { cells[x, y] = ILocationGenerator.CellType.Wall; } } Rectangle[] rooms = new Rectangle[10]; for (int i = 0; i < 10; i++) { var room = gen(random); rooms[i] = room; for (int x = room.Left; x < room.Right; x++) { for (int y = room.Top; y < room.Bottom; y++) { cells[x, y] = ILocationGenerator.CellType.Floor; } } } for (int i = 0; i < 10; i++) { var startRoom = rooms[i]; var endRoom = rooms[random.Next(0, rooms.Length)]; var startPoint = new Point( random.Next(startRoom.Left, startRoom.Right), random.Next(startRoom.Top, startRoom.Bottom) ); var endPoint = new Point( random.Next(endRoom.Left, endRoom.Right), random.Next(endRoom.Top, endRoom.Bottom) ); for (int x = startPoint.X; x < endPoint.X; x++) { cells[x, startPoint.Y] = ILocationGenerator.CellType.Floor; } for (int y = startPoint.Y; y < endPoint.Y; y++) { cells[endPoint.X, y] = ILocationGenerator.CellType.Floor; } } for (int i = 0; i < 10; i++) { var startRoom = rooms[random.Next(0, rooms.Length)]; var endRoom = rooms[random.Next(0, rooms.Length)]; var startPoint = new Point( random.Next(startRoom.Left, startRoom.Right), random.Next(startRoom.Top, startRoom.Bottom) ); var endPoint = new Point( random.Next(endRoom.Left, endRoom.Right), random.Next(endRoom.Top, endRoom.Bottom) ); for (int x = startPoint.X; x < endPoint.X; x++) { cells[x, startPoint.Y] = ILocationGenerator.CellType.Floor; } for (int y = startPoint.Y; y < endPoint.Y; y++) { cells[endPoint.X, y] = ILocationGenerator.CellType.Floor; } } places = rooms.Select(x => x.Center).ToArray(); return(cells); }