public void TestInit() { DndTimeClock dndTimeClock = new DndTimeClock(); DateTime now = DateTime.Now; dndTimeClock.SetTime(now); dndTimeClock.Advance(DndTimeSpan.FromRounds(1)); TimeSpan difference = dndTimeClock.Time - now; Assert.AreEqual(6, difference.TotalSeconds); dndTimeClock.SetTime(now); dndTimeClock.Advance(new DndTimeSpan(TimeMeasure.instant, 5)); difference = dndTimeClock.Time - now; Assert.AreEqual(0, difference.TotalSeconds); dndTimeClock.SetTime(now); dndTimeClock.Advance(DndTimeSpan.FromMinutes(5)); difference = dndTimeClock.Time - now; Assert.AreEqual(5, difference.TotalMinutes); dndTimeClock.SetTime(now); dndTimeClock.Advance(DndTimeSpan.FromHours(3)); difference = dndTimeClock.Time - now; Assert.AreEqual(3, difference.TotalHours); dndTimeClock.SetTime(now); dndTimeClock.Advance(DndTimeSpan.FromDays(2)); difference = dndTimeClock.Time - now; Assert.AreEqual(2, difference.TotalDays); }
public MainWindow() { realTimeAdvanceTimer = new DispatcherTimer(DispatcherPriority.Send); realTimeAdvanceTimer.Tick += new EventHandler(RealTimeClockHandler); realTimeAdvanceTimer.Interval = TimeSpan.FromMilliseconds(200); showClearButtonTimer = new DispatcherTimer(); showClearButtonTimer.Tick += new EventHandler(ShowClearButton); showClearButtonTimer.Interval = TimeSpan.FromSeconds(8); updateClearButtonTimer = new DispatcherTimer(DispatcherPriority.Send); updateClearButtonTimer.Tick += new EventHandler(UpdateClearButton); updateClearButtonTimer.Interval = TimeSpan.FromMilliseconds(80); dndTimeClock = new DndTimeClock(); History.TimeClock = dndTimeClock; dndTimeClock.TimeChanged += DndTimeClock_TimeChanged; // TODO: Save and retrieve game time. dndTimeClock.SetTime(DateTime.Now); InitializeComponent(); FocusHelper.FocusedControlsChanged += FocusHelper_FocusedControlsChanged; groupEffectBuilder.Entries = new ObservableCollection <TimeLineEffect>(); spTimeSegments.DataContext = dndTimeClock; logListBox.ItemsSource = History.Entries; History.LogUpdated += History_LogUpdated; InitializeAttackShortcuts(); }
public void Test() { bool firstAlarmFired = false; bool secondAlarmFired = false; DateTime firstAlarmTime = DateTime.MinValue; DateTime secondAlarmTime = DateTime.MinValue; void First_AlarmFired(object sender, DndTimeEventArgs ea) { firstAlarmTime = ea.TimeClock.Time; firstAlarmFired = true; } void Second_AlarmFired(object sender, DndTimeEventArgs ea) { secondAlarmTime = ea.TimeClock.Time; secondAlarmFired = true; } DndTimeClock dndTimeClock = new DndTimeClock(); DateTime startTime = new DateTime(2000, 1, 1); dndTimeClock.SetTime(startTime); DndAlarm first = dndTimeClock.CreateAlarm(TimeSpan.FromSeconds(5), "First"); first.AlarmFired += First_AlarmFired; DndAlarm second = dndTimeClock.CreateAlarm(TimeSpan.FromSeconds(15), "Second"); second.AlarmFired += Second_AlarmFired; Assert.IsFalse(firstAlarmFired); Assert.IsFalse(secondAlarmFired); Assert.AreEqual(firstAlarmTime, DateTime.MinValue); Assert.AreEqual(secondAlarmTime, DateTime.MinValue); dndTimeClock.Advance(DndTimeSpan.FromSeconds(10)); Assert.IsTrue(firstAlarmFired); Assert.AreEqual(firstAlarmTime, startTime + TimeSpan.FromSeconds(5)); Assert.IsFalse(secondAlarmFired); dndTimeClock.Advance(DndTimeSpan.FromSeconds(10)); Assert.IsTrue(secondAlarmFired); Assert.AreEqual(secondAlarmTime, startTime + TimeSpan.FromSeconds(15)); }
public void TestDateStringConversionDayOfYearPlusLeapYears() { DndTimeClock dndTimeClock = new DndTimeClock(); int aLeapYear = 1376; int aNonLeapYear = 1374; dndTimeClock.SetTime(aLeapYear, 214); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet")); dndTimeClock.SetTime(aLeapYear + 1, 214); Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet")); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis")); dndTimeClock.SetTime(aLeapYear + 2, 214); Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet")); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis")); dndTimeClock.SetTime(aLeapYear + 3, 214); Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet")); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis")); dndTimeClock.SetTime(aLeapYear + 4, 214); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Shieldmeet")); Assert.IsFalse(dndTimeClock.AsDndDateString().StartsWith("1st of Eleasis")); dndTimeClock.SetTime(aNonLeapYear, 1); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("1st of Hammer")); dndTimeClock.SetTime(aNonLeapYear, 122); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Greengrass")); dndTimeClock.SetTime(aLeapYear, 122); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Greengrass")); dndTimeClock.SetTime(aNonLeapYear, 213); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Midsummer")); dndTimeClock.SetTime(aLeapYear, 213); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Midsummer")); dndTimeClock.SetTime(aNonLeapYear, 274); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Highharvestide")); dndTimeClock.SetTime(aLeapYear, 275); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("Highharvestide")); dndTimeClock.SetTime(aNonLeapYear, 335); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("The Feast of the Moon")); dndTimeClock.SetTime(aLeapYear, 336); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("The Feast of the Moon")); dndTimeClock.SetTime(aNonLeapYear, 295); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("21st of Marpenoth")); dndTimeClock.SetTime(aLeapYear, 296); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("21st of Marpenoth")); dndTimeClock.SetTime(aLeapYear, 366); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("30th of Nightal")); dndTimeClock.SetTime(aNonLeapYear, 365); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("30th of Nightal")); dndTimeClock.SetTime(aLeapYear, 365); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("29th of Nightal")); dndTimeClock.SetTime(aNonLeapYear, 364); Assert.IsTrue(dndTimeClock.AsDndDateString().StartsWith("29th of Nightal")); }