public void onGameDate() { // the date of the game. // play the game! _score = stadium.playGame(this); _audience = Const.rnd.Next(10000) + 20000 + stadium.popularity * 50; // TODO: incorporate popularity // erase the record after two weeks. World.world.clock.registerOneShot(new ClockHandler(onTimeout), TimeLength.fromDays(Const.DAYS_RECORD_EFFECTIVE)); }
// // called by the Game object. // internal string playGame(Game game) { Debug.Assert(futureGames[0] == game); futureGames.RemoveAt(0); string score; // decide the score. int s1 = (int)Math.Floor(6.0 * Math.Pow(Const.rnd.NextDouble(), 1.4)); int s2 = (int)Math.Floor(6.0 * Math.Pow(Const.rnd.NextDouble(), 1.4)); // make sure s1 >= s2 if (s2 > s1) { int t = s1; s1 = s2; s2 = t; } if (s1 == s2) { // draw game. no bonus score = s1 + "-" + s2; } else { // decide who won. 25% - 75% if (Const.rnd.Next(100) < (this.strength - game.opponent.strength) / 5 + 50) { score = s1 + "-" + s2; // won _popularity = Math.Min(100, _popularity + 1); } else { score = s2 + "-" + s1; // lost _popularity = Math.Max(0, _popularity - 1); } } // move it to the "past games" list pastGames.Add(game); // schedule another game one week later scheduleNewGame(TimeLength.fromDays(Const.SCHEDULE_DAYS)); return(score); }
/// <summary> /// Creates a new commercial structurewith its left-top corner at /// the specified location. /// </summary> /// <param name="_type"> /// Type of the structure to be built. /// </param> public StadiumStructure(StructureContributionImpl _type, WorldLocator wloc) : base(_type, wloc) { // this.type = _type; // register once a month timer for the strength/popularity decay World.world.clock.registerRepeated(new ClockHandler(onClock), TimeLength.fromDays(30)); // schedule initial games // minutes to the next day midnight TimeLength b = TimeLength.fromMinutes( TimeLength.ONEDAY.totalMinutes - (World.world.clock.totalMinutes % TimeLength.ONEDAY.totalMinutes)); // the first game is set to 14:00 that day. b += TimeLength.fromHours(14); for (int i = 0; i < Const.SCHEDULE_DAYS; i += 7) { scheduleNewGame(b); scheduleNewGame(b + TimeLength.fromHours(24 * 3 + 5)); // schdule a nighter b += TimeLength.fromDays(7); } }
private void registerClock() { World.world.clock.registerOneShot( new ClockHandler(clockHandler), TimeLength.random(TimeLength.fromDays(14), TimeLength.fromDays(28))); }
protected void initialze() { manager.earn(_corpus, genre); clock.registerOneShot(new ClockHandler(warningBeforeDue), due - clock + TimeLength.fromDays(-30)); }