private void GenerateMap(Map map) { var mapSize = map.GetSize(); int width = (int)mapSize.Width - 1; int height = (int)mapSize.Height - 1; int count = (int)(width * height * 0.35); var mapWithRiver = GenerateRiver(map); for (int i = 0; i < mapWithRiver.GetLength(0); i++) { for (int j = 0; j < mapWithRiver.GetLength(1); j++) { if (mapWithRiver[i, j] > 0) { map.SetObjectFromCell(new Point(i, j), new FixedObject(new Size(1, 1), (uint)(mapWithRiver[i, j] > 1 ? 0x00002000 : 0x00002100)) { IsPassable = false }); } } } int tmpX, tmpY; Random rand = new Random(); while (count > 0) { tmpX = rand.Next(width); tmpY = rand.Next(height); if (map.GetObjectFromCell(new Point(tmpX, tmpY)) != null) { continue; } var typesCount = Game.Factory.ObjectsToGenMap.Count; /* * var typesOnMap = Assembly.GetExecutingAssembly().GetTypes().Where( * type => type.GetCustomAttribute<GenerateMapAttribute>() != null).ToList(); */ var randIndex = count % typesCount;//typesOnMap.Count; //map.SetObjectFromCell(new Point(tmpX, tmpY), Activator.CreateInstance(typesOnMap[randIndex]) as FixedObject); // map.SetObjectFromCell(new Point(tmpX, tmpY), Game.Factory.Produce(Game.Factory.ObjectsToGenMap[randIndex]) as FixedObject); count--; } for (int i = 0; i < 20; i++) { while (true) { tmpX = rand.Next(width); tmpY = rand.Next(height); if (map.GetObjectFromCell(new Point(tmpX, tmpY)) != null) { continue; } // map.AddMobileObject(new Dikabryozik(new Point(tmpX, tmpY))); map.AddMobileObject(new Hare(Map.CellToPoint(new Point(tmpX, tmpY)))); map.AddMobileObject(new Fox(Map.CellToPoint(new Point(tmpX, tmpY)))); break; } } }