Exemplo n.º 1
0
        TimerNum toggle; //flips between the 2 timers

        #endregion Fields

        #region Constructors

        public Timer2(int timeSpan1, int timeSpan2)
        {
            span1 = timeSpan1;
            span2 = timeSpan2;
            counter = 0;
            toggle = TimerNum.First;
        }
Exemplo n.º 2
0
        public TimerNum Update(GameTime gameTime)
        {
            //accumulate elapsed time
            counter += gameTime.ElapsedGameTime.Milliseconds;

            switch (toggle)
            {
            case TimerNum.First:

                if (counter >= span1)               //span1 finished
                {
                    counter %= span1;               //remove accumulated span1 time
                    toggle   = TimerNum.Second;     //flip toggle
                }
                break;


            case TimerNum.Second:

                if (counter >= span2)               //span2 finished
                {
                    counter %= span2;               //remove accumulated span2 time
                    toggle   = TimerNum.First;      //flip toggle
                }
                break;
            }

            return(toggle);
        }
Exemplo n.º 3
0
        int counter;        //the time accumulator

        public Timer2(int timeSpan1, int timeSpan2)
        {
            span1   = timeSpan1;
            span2   = timeSpan2;
            counter = 0;
            toggle  = TimerNum.First;
        }
Exemplo n.º 4
0
 private void StartCountDown()
 {
     InCountdownState  = true;
     CountDownNum      = 3;
     TimerNum.Elapsed += CountdownEvent;
     TimerNum.Interval = 1000;
     TimerNum.Start();
     String s = TimerNum.ToString();
 }
Exemplo n.º 5
0
 public void CountdownEvent(Object Sender, ElapsedEventArgs args)
 {
     CountDownNum -= 1;
     if (CountDownNum == 0)
     {
         TimerNum.Stop();
         InCountdownState = false;
         this._status     = GameStatus.InProgress;
         game.Update(game);
         CountDownNum      = 3;
         TimerNum.Elapsed -= CountdownEvent;
     }
 }
Exemplo n.º 6
0
        public TimerNum Update(GameTime gameTime)
        {
            //accumulate elapsed time
            counter += gameTime.ElapsedGameTime.Milliseconds;

            switch (toggle)
            {
                case TimerNum.First:

                    if (counter >= span1)           //span1 finished
                    {
                        counter %= span1;           //remove accumulated span1 time
                        toggle = TimerNum.Second;   //flip toggle
                    }
                    break;

                case TimerNum.Second:

                    if (counter >= span2)           //span2 finished
                    {
                        counter %= span2;           //remove accumulated span2 time
                        toggle = TimerNum.First;    //flip toggle
                    }
                    break;
            }

            return toggle;
        }
Exemplo n.º 7
0
 //Reset the timer back to beginning
 public void Reset()
 {
     toggle = TimerNum.First;
     counter = 0;
 }
Exemplo n.º 8
0
 //Reset the timer back to beginning
 public void Reset()
 {
     toggle  = TimerNum.First;
     counter = 0;
 }