public override bool Apply(ROI roi) { var list = new List <Point>(); foreach (var point in roi.Where(t => Map.Cells[t.X, t.Y].Type == CellType.Flat)) { if (!point.IsBorder()) { list.Add(point); } } for (int i = 0; i < Count; i++) { var p = list[Rnd.Next(list.Count)]; if (SpriteName.Contains("_part_1")) { // 2 x 2 tile if (Map.Cells[p.X + 1, p.Y].Type == CellType.Flat && Map.Cells[p.X + 1, p.Y + 1].Type == CellType.Flat && Map.Cells[p.X, p.Y + 1].Type == CellType.Flat) { Map.Cells[p.X, p.Y] = new Cell { SpriteName = SpriteName, Type = CellType.InsideElement }; Map.Cells[p.X + 1, p.Y] = new Cell { SpriteName = SpriteName.Replace("_part_1", "_part_2"), Type = CellType.InsideElement }; Map.Cells[p.X, p.Y + 1] = new Cell { SpriteName = SpriteName.Replace("_part_1", "_part_3"), Type = CellType.InsideElement }; Map.Cells[p.X + 1, p.Y + 1] = new Cell { SpriteName = SpriteName.Replace("_part_1", "_part_4"), Type = CellType.InsideElement }; } continue; } var cx = Rnd.Next(3); var cy = Rnd.Next(3); for (int x = 0; x < cx; x++) { for (int y = 0; y < cy; y++) { if (Map.Cells[p.X + x, p.Y + y].Type == CellType.Flat) { Map.Cells[p.X + x, p.Y + y] = new Cell { SpriteName = SpriteName, Type = CellType.InsideElement } } } } ; } return(true); }