public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
    {
        bool ticked = false;

        // Figure out how many Ticks we need.
        if (IsEnabled && this.Interval > TimeSpan.Zero)
        {
            var args = new GameTimeEventArgs(gameTime);
            ElapsedTime = ElapsedTime.Add(gameTime.ElapsedGameTime);
            while (IsEnabled && ElapsedTime >= Interval)
            {
                if (!ticked)
                {
                    ticked = true;
                    OnTickFirst(args);
                }
                ElapsedTime = ElapsedTime.Subtract(Interval);
                OnTick(args);
            }
            // If we know we ticked at least once during this Update, raise event that we're on the last Tick.
            if (ticked)
            {
                OnTickLast(args);
            }
        }
        base.Update(gameTime);
    }
Exemple #2
0
        /// <summary>
        /// Method executed every second.
        /// </summary>
        void SecondTimer()
        {
            Fps         = TickCount;
            ElapsedTime = ElapsedTime.Add(TimeSpan.FromSeconds(1));
            Program.Debug(LogLevel.Info, "Ticks per second: {0}", TickCount);
            Program.Debug(LogLevel.Info, "Average ticktime: {0} ms", ticktimes.Average());
            Program.Debug(LogLevel.Info, "Elapsed time: {0} seconds", ElapsedTime.Seconds);
            ticktimes.Clear();
            TickCount = 0;

            if (type == GameType.TimeTrial && ElapsedTime >= TimeToEnd && TimeToEnd.Ticks != 0)
            {
                EndGame();
            }
        }
Exemple #3
0
 /// <summary>
 /// Minden egyes másodpercben meghívódik, ahogy telik az idõ.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void time_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (gameMode == GameMode.TIME)
     {
         ElapsedTime = ElapsedTime.Subtract(TimeSpan.FromSeconds(1));
     }
     else
     {
         ElapsedTime = ElapsedTime.Add(TimeSpan.FromSeconds(1));
     }
     if (ElapsedTime == TimeSpan.Zero)
     {
         time.Stop();
         time.Dispose();
     }
     if (TimeElapsedHandler != null)
     {
         TimeElapsedHandler(ElapsedTime);
     }
 }
Exemple #4
0
        //Run every 0.1s
        /// <summary>
        /// Runs every 0.1 seconds - Update cycle. TODO: Cleanup and split into functions
        /// </summary>
        private void t_Tick(object sender, EventArgs e)
        {
            //DO THE OTHER TIMER
            if (doStopwatchTick)
            {
                this.BackColor  = Color.White;
                SWRemainingTime = SWRemainingTime.Subtract(TimeSpan.Parse("00:00:01"));
                if (SWRemainingTime < TimeSpan.Parse("00:00"))
                {
                    label12.Text      = TimeSpan.Parse("00:00").ToString();
                    label12.ForeColor = Color.White;
                    label11.ForeColor = Color.White;
                    label8.ForeColor  = Color.White;
                    this.BackColor    = Color.Tomato;
                }
                else
                {
                    label12.Text      = SWRemainingTime.ToString(@"hh\:mm\:ss");
                    label12.ForeColor = Color.Black;
                    label11.ForeColor = Color.Black;
                    label8.ForeColor  = Color.Black;
                    this.BackColor    = Color.White;
                }

                ElapsedTime  = ElapsedTime.Add(TimeSpan.Parse("00:00:01"));
                label11.Text = ElapsedTime.ToString(@"hh\:mm\:ss");
            }
            else
            {
                if (examStarted)
                {
                    PausedFor      = PausedFor.Add(TimeSpan.Parse("00:00:01"));
                    label14.Text   = PausedFor.ToString(@"hh\:mm\:ss");
                    FinishTime     = DateTime.Now.TimeOfDay.Add(SWRemainingTime);
                    label8.Text    = FinishTime.ToString(@"hh\:mm\:ss");
                    this.BackColor = Color.LightGray;
                }
                else
                {
                    label14.Text = TimeSpan.Parse("00:00").ToString();
                }
            }

            //get time
            TimeSpan TimeNow = DateTime.Now.TimeOfDay;
            int      ss      = TimeNow.Seconds;
            int      mm      = TimeNow.Minutes;
            int      hh      = TimeNow.Hours;
            int      ms      = TimeNow.Milliseconds;

            //put time into text format
            string sstring  = ss.ToString();
            string mstring  = mm.ToString();
            string hstring  = hh.ToString();
            string textTime = TimeNow.ToString(@"hh\:mm\:ss");

            label1.Text = textTime;

            //Set up labels
            //label6.Text = Properties.Settings.Default.StartTime.ToString();
            //TimeSpan FinishTime = Properties.Settings.Default.StartTime.Add(Properties.Settings.Default.Duration);
            //label8.Text = FinishTime.ToString();

            //Do stopwatch labels
            //TimeSpan TimeNow = DateTime.Now.TimeOfDay;
            //TimeSpan StartTime = Properties.Settings.Default.StartTime;
            //TimeSpan Duration = Properties.Settings.Default.Duration;
            //if (TimeNow.Subtract(StartTime) < TimeSpan.Parse("00:00"))
            //{
            //    label11.Text = "00:00:00.0";
            //}
            //else if (TimeNow.Subtract(StartTime) > Duration)
            //{
            //    label11.Text = Duration.ToString(@"hh\:mm\:ss\.f");
            //}
            //else
            //{
            //    label11.Text = TimeNow.Subtract(StartTime).ToString(@"hh\:mm\:ss\.f");
            //}

            //if (FinishTime.Subtract(TimeNow) > Duration)
            //{
            //    label12.Text = Duration.ToString(@"hh\:mm\:ss\.f");
            //}
            //else if (FinishTime.Subtract(TimeNow) <= TimeSpan.Parse("00:00"))
            //{
            //    label12.Text = "00:00:00.0";
            //}
            //else
            //{
            //    label12.Text = FinishTime.Subtract(TimeNow).ToString(@"hh\:mm\:ss\.f");
            //}

            //Debug Text Box
            DebugFinish = DateTime.Now.TimeOfDay.Add(SWRemainingTime);
            //textBox1.Text = "DEBUG\r\nElapsedTime " + ElapsedTime.ToString() + "\r\nSWRemainingTime " + SWRemainingTime.ToString() + "\r\nTime Now" + DateTime.Now.TimeOfDay + "\r\nFinishTime " + DebugFinish.ToString() + "\r\n Difference " + DateTime.Now.TimeOfDay.Subtract(DebugFinish).ToString();


            //create graphics
            g = Graphics.FromImage(bmp);
            int[] handCoord = new int[2];

            //clear
            if (!doStopwatchTick && examStarted)
            {
                g.Clear(Color.LightGray);
            }
            else if (SWRemainingTime < TimeSpan.Parse("00:00"))
            {
                g.Clear(Color.Tomato);
            }
            else
            {
                g.Clear(Color.White);
            }


            //draw circle
            g.DrawEllipse(new Pen(Color.Black, 1f), 0, 0, WIDTH, HEIGHT);

            //draw figure
            g.DrawString("12", new Font("Arial", 12), Brushes.Black, new PointF(285, 9));
            g.DrawString("3", new Font("Arial", 12), Brushes.Black, new PointF(577, 285));
            g.DrawString("6", new Font("Arial", 12), Brushes.Black, new PointF(289, 569));
            g.DrawString("9", new Font("Arial", 12), Brushes.Black, new PointF(5, 285));
            //second hand
            handCoord = msCoord(ss, secHAND);
            g.DrawLine(new Pen(Color.Red, 1f), new Point(cx, cy), new Point(handCoord[0], handCoord[1]));

            //minute hand
            handCoord = msCoord(mm, minHAND);
            g.DrawLine(new Pen(Color.Black, 2f), new Point(cx, cy), new Point(handCoord[0], handCoord[1]));

            //hour hand
            handCoord = hrCoord(hh % 12, mm, hrHAND);
            g.DrawLine(new Pen(Color.Gray, 3f), new Point(cx, cy), new Point(handCoord[0], handCoord[1]));

            //load bmp in picturebox1
            pictureBox1.Image = bmp;

            //disp time
            this.Text = "Exam Clock -  Exam:" + Properties.Settings.Default.ExamName + " " + SWRemainingTime.ToString(@"hh\:mm\:ss") + " Remaining";

            //dispose
            g.Dispose();
        }
Exemple #5
0
        private void SetTimer()
        {
            if (HabitTimeList.Count <= CurrentIndex)
            {
                HabitTimeList.Add(CurrentHabitTime);
                ElapsedTimeList.Add(ElapsedTime);
            }

            void action()
            {
                if (previousTime == DateTime.MinValue)
                {
                    previousTime = DateTime.Now;
                }

                var currentTime = DateTime.Now;

                var diffTimeSpan = currentTime.Subtract(previousTime);

                var oldHabitTime = CurrentHabitTime;

                ElapsedTime      = ElapsedTime.Add(diffTimeSpan);
                CurrentHabitTime = CurrentHabitTime.Add(-diffTimeSpan);

                if (oldHabitTime.Seconds != CurrentHabitTime.Seconds)
                {
                    Console.WriteLine($"{ElapsedTime.ToString(@"mm\:ss")}");

                    RefreshHabitAndElapsedTimeList();

                    if (!IsSoonFinishTime)
                    {
                        DependencyService.Get <IAlarmSetter>().SetCountAlarm(CurrentHabitTime.Add(TimeSpan.FromSeconds(-10)));
                    }

                    DependencyService.Get <INotifySetter>().NotifyHabitCount(CurrentHabit, CurrentHabitTime, false, !IsNotLastHabit);

                    if (CurrentHabit.TotalTime.TotalSeconds > 20 && CurrentHabitTime.TotalSeconds < 11 && !IsSoonFinishTime)
                    {
                        DependencyService.Get <INotifySetter>().NotifySoonFinishHabit(CurrentHabit, NextHabitName);
                        IsSoonFinishTime = true;
                    }

                    if (CurrentHabitTime.TotalSeconds < 1 && !IsMinusHabitTime)
                    {
                        DependencyService.Get <INotifySetter>().NotifyFinishHabit(CurrentHabit, NextHabitName);
                        IsMinusHabitTime = true;

                        if (Preferences.Get("IsAutoFlipHabit", false))
                        {
                            ShowNextHabitCommand.Execute(null);
                        }
                    }
                    ;
                }

                previousTime = currentTime;
            }

            void stoppingaAction()
            {
                IsCounting = false;
                DependencyService.Get <INotifySetter>().CancelHabitCountNotify();
                DependencyService.Get <INotifySetter>().CancelFinishHabitNotify();
            }

            deviceTimer = new DeviceTimer(action, TimeSpan.FromSeconds(0.1), true, true, stoppingaAction);
        }
Exemple #6
0
 private void _gameTimer_Tick(object sender, object e)
 {
     ElapsedTime = ElapsedTime.Add(TimeSpan.FromSeconds(1.0));
 }
Exemple #7
0
 /// <summary>
 /// Adds a new time span to the existing elapsed time object.
 /// </summary>
 /// <param name="ts">the new time span to add</param>
 public void AddTime(TimeSpan ts)
 {
     ElapsedTime = ElapsedTime.Add(ts);
 }
Exemple #8
0
 public void Work(TimeSpan duration)
 {
     ElapsedTime = ElapsedTime.Add(duration);
 }