示例#1
0
 public void RemoveAllListener()
 {
     if (OnTimerFinished != null)
     {
         foreach (Delegate d in OnTimerFinished.GetInvocationList())
         {
             OnTimerFinished -= (OnTimerFinishedEvent)d;
         }
     }
 }
 private void TimerTick(object sender, ElapsedEventArgs args)
 {
     currTick--;
     Dispatcher.Invoke(() => { tbTimer.Text = string.Format("{0}:{1}", (currTick / 60).ToString(), (currTick % 60).ToString("D2")); });
     if (currTick == 0)
     {
         countDownTimer.Stop();
         OnTimerFinished?.Invoke(this, new EventArgs());
     }
 }
示例#3
0
    private IEnumerator RunTimer()
    {
        OnTimerStarted?.Invoke(this);
        while (timeLeft > 0)
        {
            yield return(null);

            SetTimeLeft(timeLeft - Time.deltaTime);
        }
        OnTimerStopped?.Invoke(this);
        OnTimerFinished?.Invoke(this);
    }
示例#4
0
        /// <summary>
        /// Coroutine for the counter. Calls the OnCount event each tick and the the ontimerfinished
        /// when the countdown reaches zero.
        /// </summary>
        /// <returns></returns>
        private IEnumerator TimerCountDown()
        {
            counter -= Time.deltaTime;
            OnCount?.Invoke(Mathf.RoundToInt(counter));

            if (counter <= 0)
            {
                OnTimerFinished?.Invoke();
                yield break;
            }

            yield return(null);
        }
示例#5
0
 public void Update(GameTime gameTime)
 {
     if (Active)
     {
         elapsed += gameTime.ElapsedGameTime.TotalSeconds;
         if (elapsed >= Duration)
         {
             OnTimerFinished?.Invoke();
             Active  = false;
             elapsed = 0;
         }
     }
 }
示例#6
0
    IEnumerator StartTimerCoroutine()
    {
        Debug.Log("Coroutine Start");
        coroutineRunning = true;
        while (timePassed <= timeLimit)
        {
            //Debug.Log("timer = "+timePassed);
            timePassed += Time.deltaTime;
            yield return(null);
        }

        OnTimerFinished?.Invoke();
        coroutineRunning = false;
    }
示例#7
0
                /// <summary>
                /// Creates and initializes a new instance of a Timer.
                /// </summary>
                internal Timer(float waitTime, Timer.OnTimerFinished onTimerFinished = null, Timer.OnTimerTicked onTimerTicked = null, bool startNow = true)
                {
                    SetWaitTime(waitTime);
                    this.onTimerFinished = onTimerFinished;
                    this.onTimerTicked   = onTimerTicked;

                    if (startNow)
                    {
                        Start();
                    }
                    else
                    {
                        Pause();
                    }
                }
示例#8
0
    public override IEnumerator Play()
    {
        CurrentValue = MaxValue;
        while (CurrentValue > 0)
        {
            CurrentValue -= Time.deltaTime;
            yield return(new WaitForSeconds(0.01f));
        }

        if (OnTimerFinished != null)
        {
            OnTimerFinished.Invoke();
        }

        yield break;
    }
示例#9
0
    public void StartGame(OnTimerFinished callback, GameManager.Games game)
    {
        timerFinishedCallback = callback;

        timeLeft = initialTime;

        countdownActive  = false;
        timerActive      = false;
        showInstructions = false;

        Time.timeScale = 0.0f;

        //show game instructions
        ShowInstructions(game);

        //
    }
示例#10
0
 public void StopGame()
 {
     timerFinishedCallback = null;
     timerActive           = false;
     timer.SetActive(false);
 }
示例#11
0
 /// <summary>
 /// Removes the specified delegate from the delegate invokation list.
 /// This should be called in cases where you want to unsubscribe a function.
 /// </summary>
 public void RemoveListener(OnTimerFinished delgt)
 {
     onTimerFinished -= delgt;
 }
示例#12
0
 /// <summary>
 /// Sets the delegate to invoke when the timer finishes.
 /// When the timer is finished and/or you don't need it anymore, don't forget to call RemoveListener.
 /// </summary>
 public void AddListener(OnTimerFinished delgt)
 {
     onTimerFinished += delgt;
 }
示例#13
0
        public GameWindow(Game game)
        {
            InitializeComponent();

            if (game == null || game.NumRounds < 2)
            {
                throw new ArgumentException("Game cannot be null and must have at least two rounds");
            }

            mGame = game;

            mSoundPlayerIntro.Load();

            mAttachedKeys = new List <Key>()
            {
                Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8, Key.D9, Key.D0
            };

            switch (mGame.BonusRoundLocation)
            {
            case BonusRoundLocation.Middle:
                mBonusRoundIndex  = (int)(game.NumRounds / 2);
                ExistingQuestions = new IRoundControl[mGame.NumRounds + 1];
                break;

            case BonusRoundLocation.End:
                mBonusRoundIndex  = (int)game.NumRounds;
                ExistingQuestions = new IRoundControl[mGame.NumRounds + 1];
                break;

            case BonusRoundLocation.None:
            default:
                mBonusRoundIndex  = int.MaxValue;
                ExistingQuestions = new IRoundControl[mGame.NumRounds];
                break;
            }

            for (int i = 0; i < ExistingQuestions.Length; i++)
            {
                if (i == mBonusRoundIndex)
                {
                    var bonusRound = new BonusRoundControl(game.BonusRound);
                    bonusRound.OnTimerFinished += (sender, args) =>
                    {
                        OnTimerFinished?.Invoke(sender, args);
                    };
                    ExistingQuestions[i] = bonusRound;
                }
                else
                {
                    int normalQuestionIndex = i <= mBonusRoundIndex ? i : i - 1;
                    ExistingQuestions[i] = new SingleQuestionControl(mGame.Rounds.ElementAt(normalQuestionIndex));
                }

                (ExistingQuestions[i] as UIElement).CacheMode = new BitmapCache()
                {
                    EnableClearType = false, RenderAtScale = 1, SnapsToDevicePixels = false
                };
            }

            IntroPlaceholderBorder = new Border()
            {
                Background = new SolidColorBrush(Color.FromRgb(0, 0, 0))
            };

            gParentGrid.Children.Add(IntroPlaceholderBorder);

            mNextQuestion = ExistingQuestions[0];
            SetNextTransform(mNextQuestion);
            gParentGrid.Children.Add(mNextQuestion as Control);

            mMediaPlayerQuestion = new MediaPlayer();

            mMediaPlayerQuestion.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + @"/Sounds/Next_Question.wav", UriKind.RelativeOrAbsolute));
            mMediaPlayerQuestion.IsMuted = true;

            this.Closed += GameWindow_Closed;
        }
 internal Timer(float waitTime, Timer.OnTimerFinished onTimerFinished = null, Timer.OnTimerTicked onTimerTicked = null)
 {
     SetWaitTime(waitTime);
     this.onTimerFinished = onTimerFinished;
     this.onTimerTicked   = onTimerTicked;
 }