/// <summary> /// Der abstrakte Insekt-Basiskonstruktor. /// </summary> /// <param name="colony">Das Volk zu dem das neue Insekt gehört.</param> /// <param name="vorhandeneInsekten">Hier unbenutzt!</param> internal virtual void Init(CoreColony colony, Random random, Dictionary <string, int> vorhandeneInsekten) { id = neueId; neueId++; this.colony = colony; this.RandomBase = random; koordinate.Richtung = RandomBase.Next(0, 359); // Zufällig auf dem Spielfeldrand platzieren. if (colony.AntHills.Count == 0) // Am oberen oder unteren Rand platzieren. { if (RandomBase.Next(2) == 0) { koordinate.X = RandomBase.Next(0, colony.Playground.Width); koordinate.X *= SimulationEnvironment.PLAYGROUND_UNIT; if (RandomBase.Next(2) == 0) { koordinate.Y = 0; } else { koordinate.Y = colony.Playground.Height * SimulationEnvironment.PLAYGROUND_UNIT; } } // Am linken oder rechten Rand platzieren. else { if (RandomBase.Next(2) == 0) { koordinate.X = 0; } else { koordinate.X = colony.Playground.Width * SimulationEnvironment.PLAYGROUND_UNIT; } koordinate.Y = RandomBase.Next(0, colony.Playground.Height); koordinate.Y *= SimulationEnvironment.PLAYGROUND_UNIT; } } // In einem zufälligen Bau platzieren. else { int i = RandomBase.Next(colony.AntHills.Count); koordinate.X = colony.AntHills[i].CoordinateBase.X + SimulationEnvironment.Cosinus( colony.AntHills[i].CoordinateBase.Radius, koordinate.Richtung); koordinate.Y = colony.AntHills[i].CoordinateBase.Y + SimulationEnvironment.Sinus( colony.AntHills[i].CoordinateBase.Radius, koordinate.Richtung); } }
/// <summary> /// Initialize the simulation-environment. /// </summary> /// <param name="config">configuration</param> public bool Init(SimulatorConfiguration config) { // Prepare values configuration = config; SimulationSettings.SetCustomSettings(config.Settings); environment = null; // Prepare time-counting playerTimes = new Dictionary <PlayerInfo, long>(); currentPlayer = null; currentArea = Area.Unknown; // Load Playerfiles foreach (TeamInfo team in configuration.Teams) { foreach (PlayerInfo spieler in team.Player) { if (spieler is PlayerInfoFiledump) { // Try, to load filedump try { spieler.assembly = Assembly.Load(((PlayerInfoFiledump)spieler).File); } catch (Exception ex) { exception = ex; return(false); } } else if (spieler is PlayerInfoFilename) { // Try, to load filename try { spieler.assembly = Assembly.LoadFile(((PlayerInfoFilename)spieler).File); } catch (Exception ex) { exception = ex; return(false); } } else { exception = new InvalidOperationException( Resource.SimulationCoreHostWrongPlayerInfo); return(false); } // Add player to counter-list // TODO: Need another key for times // playerTimes.Add(spieler, 0); } } // Init environment try { environment = new SimulationEnvironment(); environment.AreaChange += umgebung_Verantwortungswechsel; environment.Init(configuration); } catch (Exception ex) { exception = ex; return(false); } // Everything nice... return(true); }