public JapaneseTimeControl(int mainTimeSeconds, int byoyomiLengthInSeconds, int byoyomiPeriodCount)
 {
     this._byoyomiLengthInSeconds = byoyomiLengthInSeconds;
     this._byoyomiPeriodCount     = byoyomiPeriodCount;
     this._snapshot = new Japanese.JapaneseTimeInformation(TimeSpan.FromSeconds(mainTimeSeconds),
                                                           byoyomiPeriodCount, false);
 }
 protected override void UpdateSnapshot(TimeSpan timeSpent)
 {
     // A move was just made.
     _snapshot = ReduceBy(_snapshot, timeSpent);
     if (_snapshot.InByoYomi)
     {
         _snapshot = new Japanese.JapaneseTimeInformation(TimeSpan.FromSeconds(_byoyomiLengthInSeconds),
                                                          _snapshot.PeriodsLeft, true);
     }
 }
 public override void UpdateFromClock(Clock clock)
 {
     LastTimeClockStarted = DateTime.Now;
     if (clock.PeriodsLeft == 0)
     {
         _snapshot = new JapaneseTimeInformation(TimeSpan.FromSeconds(clock.Time), _byoyomiPeriodCount, false);
     }
     else
     {
         _snapshot = new Japanese.JapaneseTimeInformation(TimeSpan.FromSeconds(clock.Time), clock.PeriodsLeft - 1,
                                                          true);
     }
     // TODO (future work)  Petr: Think about whether this is correct.
 }
        /// <summary>
        /// Reduces the time remaining on the clock in the <paramref name="minued"/> by <paramref name="subtrahend"/>
        /// and returns the result. This cannot be static because it uses the <see cref="_byoyomiLengthInSeconds"/> field.
        /// </summary>
        /// <param name="minued">The minued.</param>
        /// <param name="subtrahend">The subtrahend.</param>
        private JapaneseTimeInformation ReduceBy(JapaneseTimeInformation minued, TimeSpan subtrahend)
        {
            TimeSpan subtractStill         = subtrahend;
            JapaneseTimeInformation result = new Japanese.JapaneseTimeInformation(minued.TimeLeft,
                                                                                  minued.PeriodsLeft, minued.InByoYomi);

            while (subtractStill > TimeSpan.Zero)
            {
                if (result.TimeLeft > subtractStill)
                {
                    result = new Japanese.JapaneseTimeInformation(result.TimeLeft - subtractStill, result.PeriodsLeft,
                                                                  result.InByoYomi);
                    break;
                }
                else
                {
                    subtractStill -= result.TimeLeft;
                    result         = new Japanese.JapaneseTimeInformation(TimeSpan.FromSeconds(_byoyomiLengthInSeconds),
                                                                          result.PeriodsLeft - 1, true);
                }
            }
            return(result);
        }