예제 #1
0
        /// <summary>
        /// Method for handeling the score.
        /// </summary>
        /// <param name="ct">Token to cancel the process.</param>
        /// <remarks>Perfomance test can be enabled for this method.</remarks>
        private void ScoreHandler(CancellationToken ct)
        {
            PerformanceTest performance = new PerformanceTest("Score Handler");
            performance.IsEnable = false;
            performance.Start();

            while (!ct.IsCancellationRequested && !Dispatcher.HasShutdownStarted)
            {
                Dispatcher.Invoke((Action)(() => { scoreLabel.Content = engine.Score; }));

                if (++timerCounts % timerFrame == 0)
                {
                    timerInterval -= timerInterval > 10 ? 5 : 0;
                    timer.Interval = timerInterval;
                }

                performance.iterate();
                Thread.Sleep(250); // Disable this for the performance test.
            }

            performance.Stop();
        }
예제 #2
0
        /// <summary>
        /// Method to handle if the game is over.
        /// </summary>
        /// <param name="ct">Token to cancel the process.</param>
        /// <remarks>Perfomance test can be enabled for this method.</remarks>
        private void GameOverHandler(CancellationToken ct)
        {
            PerformanceTest performance = new PerformanceTest("Game Over Handler");
            performance.IsEnable = false;
            performance.Start();

            while (!ct.IsCancellationRequested && !Dispatcher.HasShutdownStarted)
            {
                if (engine.GameOver)
                {
                    timer.Stop();
                    tokenSource.Cancel();
                    Dispatcher.Invoke((Action)(() => { gameOverCanvas.Visibility = Visibility.Visible; }));
                }

                performance.iterate();
                Thread.Sleep(10); // Disable this for the performance test.
            }

            performance.Stop();
        }