private bool CreateRoom(int x, int y, int h, int w) { if (Map.GetLength(0) < x+w || Map.GetLength(1) < y+h) { return false; } for (int ulx = x; ulx < x+w; ulx++) { for (int uly = y; uly < y+h; uly++) { if (!Map[ulx, uly].Furniture.Blocking) { return false; } } } for (int ulx = x; ulx < x+w; ulx++) { for (int uly = y; uly < y+h; uly++) { Map[ulx, uly] = new Tile() { Name = "Room", X=x, Y=y, Furniture = new Furniture() { Name = "Floor", Blocking = false, X = ulx, Y = uly } }; } } return true; }
private void InitializeMap() { Map = new Tile[mapWidth, mapHeight]; for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { Map[x, y] = new Tile() { Name = "MapTile", X=x, Y=y, Furniture = new Furniture() { Name = "Wall", Blocking = true, X = x, Y = y } }; } } }
public Tile[,] GetTiles() { var tiles = new Tile[40, 40]; var rnd = new Random(); for (int x = 0; x < 40; x++) { for (int y = 0; y < 40; y++) { int r = rnd.Next(0, 10); var blocking = r < 9 ? false : true; tiles[x, y] = new Tile() { Name = $"Tile[{x},{y}]", Furniture = new Furniture() { Name = "Test furniture", Blocking = blocking, X = x, Y = y} }; } } return tiles; }
private void InitializeMap() { Map = new Tile[mapWidth, mapHeight]; for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { var rnd = Random.Next(0, 10); if (rnd >= 6) { Map[x, y] = new Tile() { Name = "MapTile", X = x, Y = y, Furniture = new Furniture() { Name = "Wall", Blocking = true, X = x, Y = y } }; } else { Map[x, y] = new Tile() { Name = "Room", X = x, Y = y, Furniture = new Furniture() { Name = "Floor", Blocking = false, X = x, Y = y } }; } } } }
public Tile[,] GetTiles() { InitializeMap(); CreateRoom(1, 1, 6, 6); var wall = new Tile(); for (int i = 0; i < 200; i++) { wall = PickAWall(); if (wall == null) { break; } CreateRoom(wall.X, wall.Y, Random.Next(3, 15), Random.Next(3, 15)); } return Map; }