예제 #1
0
        private void Menu_NewGame_Click(object sender, RoutedEventArgs e)
        {
            canvas.Children.Clear();
            _currentShape = ShapesFactory.CreateShape(canvas);

            previewCanvas.Children.Clear();
            _currentPreviewShape = ShapesFactory.CreateShape(previewCanvas);

            _currentInterval    = 300;
            _gameTimer.Interval = _currentInterval;
            _score = 0;
            _gameTimer.Start();

            _gameStarted = true;
            _pause       = false;

            gameOverTxtBlk.Text  = string.Empty;
            gameScoreTxtBlk.Text = "Score: ";
        }
예제 #2
0
        private void _gameTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _gameTimer.Stop();

            Dispatcher.Invoke(() =>
            {
                lock (this)
                {
                    if (_currentShape.IsStacked(canvas))
                    {
                        RemoveFullLinesIfEnabled();

                        if (IsCanvasOverflow())
                        {
                            gameOverTxtBlk.Text = "GAME OVER";
                            _gameStarted        = false;
                            _gameTimer.Stop();
                            return;
                        }
                        else
                        {
                            _currentShape = ShapesFactory.CreateShape(canvas, _currentPreviewShape.GetType());
                            previewCanvas.Children.Clear();
                            _currentPreviewShape = ShapesFactory.CreateShape(previewCanvas);
                        }
                    }
                    else
                    {
                        try     // when Application shutdown, can be exception here
                        {
                            _currentShape.MoveDown();
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            });

            _gameTimer.Start();
        }