public static SceneSettings GetRandomMap(int seed = -1) { if (seed == -1) return GetDefaulSettings(); Random rand = new Random(seed); SceneSettings setts; do { setts = new SceneSettings(); var toAdd = Enumerable.Range(0, 6 * 4).Select(a => WallSettings.NoWall).ToList(); toAdd[0] = WallSettings.BlueSocket; toAdd[1] = WallSettings.RedSocket; toAdd[2] = WallSettings.GreenSocket; toAdd[3] = WallSettings.Wall; toAdd[4] = WallSettings.Wall; toAdd[5] = WallSettings.Wall; toAdd[6] = WallSettings.Wall; while (toAdd.Any()) { var ind = rand.Next(toAdd.Count); var wall = toAdd[ind]; toAdd.RemoveAt(ind); bool isHorizontal = rand.NextDouble() > 0.5; if (isHorizontal) { while (true) { var x = rand.Next(3); var y = rand.Next(setts.HorizontalWalls.GetLength(1)); if (setts.HorizontalWalls[x, y] == WallSettings.NoWall) { setts.HorizontalWalls[x, y] = wall; setts.HorizontalWalls[setts.HorizontalWalls.GetLength(0) - x - 1, y] = GetWallSettings(wall); break; } } } else { while (true) { var x = rand.Next(3); var y = rand.Next(setts.VerticalWalls.GetLength(1)); if (wall != WallSettings.Wall && x == 2) continue; if (setts.VerticalWalls[x, y] == WallSettings.NoWall) { setts.VerticalWalls[x, y] = wall; setts.VerticalWalls[setts.VerticalWalls.GetLength(0) - x - 1, y] = GetWallSettings(wall); break; } } } } setts.Map.Init(setts); } while (!setts.Map.IsValid()); CreateDetails(setts); return setts; }
private static void CreateDetails(SceneSettings settings) { settings.Details[0].Color = DetailColor.Red; settings.Details[0].Location = new Point(0, 1); settings.Details[1].Color = DetailColor.Red; settings.Details[1].Location = new Point(0, 3); settings.Details[2].Color = DetailColor.Blue; settings.Details[2].Location = new Point(5, 1); settings.Details[3].Color = DetailColor.Blue; settings.Details[3].Location = new Point(5, 3); settings.Details[4].Color = DetailColor.Green; settings.Details[4].Location = new Point(2, 0); settings.Details[5].Color = DetailColor.Green; settings.Details[5].Location = new Point(3, 0); }
public Body CreateWorld(ICvarcEngine engine, ISceneSettings _settings) { Settings = (SceneSettings)_settings; var root = new Body(); var first = new Cylinder { Height = 20, RTop = 10, RBottom = 10, Location = new Frame3D(-150 + 25 - 10, 100 - 25 + 10, 3), DefaultColor = Color.DarkViolet, IsMaterial = true, Density = Density.Iron, FrictionCoefficient = 0, Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("red.png")) }, Type = "Robot" }; var second = new Cylinder { Height = 20, RTop = 10, RBottom = 10, Location = new Frame3D(150 - 25 + 10, 100 - 25 + 10, 3, Angle.Zero, Angle.Pi, Angle.Zero), DefaultColor = Color.DarkViolet, IsMaterial = true, Density = Density.Iron, FrictionCoefficient = 0, Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("blue.png")) }, Type = "Robot" }; root.Add(first); root.Add(second); first.Collision += body => engine.RaiseOnCollision(first.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision); second.Collision += body => engine.RaiseOnCollision(second.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision); root.Add(new Box { XSize = 300, YSize = 200, ZSize = 3, DefaultColor = Color.White, Top = new SolidColorBrush { Color = Color.Yellow }, IsStatic = true, Type = "floor", }); foreach (var detail in Settings.Details) { Color color = Color.White; string name = "D"; switch (detail.Color) { case DetailColor.Red: color = Color.Red; name += "R"; break; case DetailColor.Blue: color = Color.Blue; name += "B"; break; case DetailColor.Green: color = Color.Green; name += "G"; break; } var box = new Box { XSize = 15, YSize = 15, ZSize = 15, Location = new Frame3D(-150 + 25 + detail.Location.X * 50, 100 - 25 - 50 * detail.Location.Y, 0), DefaultColor = color, Type = name, IsMaterial = true, IsStatic = false, FrictionCoefficient = 8 }; root.Add(box); box.Collision += body => { if (box.Parent.Id == first.Id && body.Id == second.Id) { engine.RaiseOnCollision(second.Id.ToString(), first.Id.ToString(), CollisionType.RobotCollision); } if (box.Parent.Id == second.Id && body.Id == first.Id) { engine.RaiseOnCollision(first.Id.ToString(), second.Id.ToString(), CollisionType.RobotCollision); } }; } CreateWalls(root, Settings.HorizontalWalls, 50, 10, 15, "HW", (x, y) => new Point(-150 + 25 + x * 50, 100 - (y + 1) * 50)); CreateWalls(root, Settings.VerticalWalls, 10, 50, 14, "VW", (x, y) => new Point(-150 + (x + 1) * 50, 100 - 25 - y * 50)); CreateBorders(root); return(root); }
private static SceneSettings GetDefaulSettings() { var settings = new SceneSettings(); settings.VerticalWalls[0, 0] = WallSettings.RedSocket; settings.VerticalWalls[4, 0] = WallSettings.BlueSocket; settings.VerticalWalls[2, 1] = WallSettings.Wall; settings.HorizontalWalls[1, 0] = settings.HorizontalWalls[4, 0] = WallSettings.Wall; settings.HorizontalWalls[0, 1] = settings.HorizontalWalls[5, 1] = WallSettings.Wall; settings.HorizontalWalls[2, 2] = settings.HorizontalWalls[3, 2] = WallSettings.Wall; settings.HorizontalWalls[1, 2] = settings.HorizontalWalls[4, 2] = WallSettings.GreenSocket; settings.HorizontalWalls[1, 1] = WallSettings.BlueSocket; settings.HorizontalWalls[4, 1] = WallSettings.RedSocket; CreateDetails(settings); settings.Map.Init(settings); return settings; }
public Body CreateWorld(ICvarcEngine engine, ISceneSettings _settings) { Settings = (SceneSettings)_settings; var root = new Body(); var first = new Cylinder { Height = 20, RTop = 10, RBottom = 10, Location = new Frame3D(-150 + 25 - 10, 100 - 25 + 10, 3), DefaultColor = Color.DarkViolet, IsMaterial = true, Density = Density.Iron, FrictionCoefficient = 0, Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("red.png")) }, Type = "Robot" }; var second = new Cylinder { Height = 20, RTop = 10, RBottom = 10, Location = new Frame3D(150 - 25 + 10, 100 - 25 + 10, 3, Angle.Zero, Angle.Pi, Angle.Zero), DefaultColor = Color.DarkViolet, IsMaterial = true, Density = Density.Iron, FrictionCoefficient = 0, Top = new PlaneImageBrush { Image = new Bitmap(GetResourceStream("blue.png")) }, Type = "Robot" }; root.Add(first); root.Add(second); first.Collision += body => engine.RaiseOnCollision(first.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision); second.Collision += body => engine.RaiseOnCollision(second.Id.ToString(), body.Id.ToString(), CollisionType.RobotCollision); root.Add(new Box { XSize = 300, YSize = 200, ZSize = 3, DefaultColor = Color.White, Top = new SolidColorBrush { Color = Color.Yellow }, IsStatic = true, Type = "floor", }); foreach (var detail in Settings.Details) { Color color = Color.White; string name = "D"; switch (detail.Color) { case DetailColor.Red: color = Color.Red; name += "R"; break; case DetailColor.Blue: color = Color.Blue; name += "B"; break; case DetailColor.Green: color = Color.Green; name += "G"; break; } var box = new Box { XSize = 15, YSize = 15, ZSize = 15, Location = new Frame3D(-150 + 25 + detail.Location.X * 50, 100 - 25 - 50 * detail.Location.Y, 0), DefaultColor = color, Type = name, IsMaterial = true, IsStatic = false, FrictionCoefficient = 8 }; root.Add(box); box.Collision += body => { if (box.Parent.Id == first.Id && body.Id == second.Id) engine.RaiseOnCollision(second.Id.ToString(), first.Id.ToString(), CollisionType.RobotCollision); if (box.Parent.Id == second.Id && body.Id == first.Id) engine.RaiseOnCollision(first.Id.ToString(), second.Id.ToString(), CollisionType.RobotCollision); }; } CreateWalls(root, Settings.HorizontalWalls, 50, 10, 15, "HW", (x, y) => new Point(-150 + 25 + x * 50, 100 - (y + 1) * 50)); CreateWalls(root, Settings.VerticalWalls, 10, 50, 14, "VW", (x, y) => new Point(-150 + (x + 1) * 50, 100 - 25 - y * 50)); CreateBorders(root); return root; }
public static SceneSettings GetRandomMap(int seed = -1) { if (seed == -1) { return(GetDefaulSettings()); } Random rand = new Random(seed); SceneSettings setts; do { setts = new SceneSettings(); var toAdd = Enumerable.Range(0, 6 * 4).Select(a => WallSettings.NoWall).ToList(); toAdd[0] = WallSettings.BlueSocket; toAdd[1] = WallSettings.RedSocket; toAdd[2] = WallSettings.GreenSocket; toAdd[3] = WallSettings.Wall; toAdd[4] = WallSettings.Wall; toAdd[5] = WallSettings.Wall; toAdd[6] = WallSettings.Wall; while (toAdd.Any()) { var ind = rand.Next(toAdd.Count); var wall = toAdd[ind]; toAdd.RemoveAt(ind); bool isHorizontal = rand.NextDouble() > 0.5; if (isHorizontal) { while (true) { var x = rand.Next(3); var y = rand.Next(setts.HorizontalWalls.GetLength(1)); if (setts.HorizontalWalls[x, y] == WallSettings.NoWall) { setts.HorizontalWalls[x, y] = wall; setts.HorizontalWalls[setts.HorizontalWalls.GetLength(0) - x - 1, y] = GetWallSettings(wall); break; } } } else { while (true) { var x = rand.Next(3); var y = rand.Next(setts.VerticalWalls.GetLength(1)); if (wall != WallSettings.Wall && x == 2) { continue; } if (setts.VerticalWalls[x, y] == WallSettings.NoWall) { setts.VerticalWalls[x, y] = wall; setts.VerticalWalls[setts.VerticalWalls.GetLength(0) - x - 1, y] = GetWallSettings(wall); break; } } } } setts.Map.Init(setts); } while (!setts.Map.IsValid()); CreateDetails(setts); return(setts); }