Ejemplo n.º 1
0
        // Handles the periodic updates of the game
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            game.Tick();
            gridBoard.Invalidate();
            gridBoard.Update();
            nextPieceForm.ForceUpdate();

            if (game.IsGameOver)
            {
                gameTimer.Stop();
                gridBoard.CoveredRanges.Add(GridRangeInfo.Cells(6, 2, 7, 7));
                SetPauseBarItemStatus();
            }
            else
            {
                // Tracks the games speed
                label1.Text = "Score: " + game.GetScore().ToString();

                // Level    Score
                // --------------
                //     1        0
                //     2      100
                //     3      400
                //     4      900
                //     5     1600
                //     6     2500
                //     7     3600
                //     8     4900
                //     9     6400
                //    10     8100
                //    11    10000
                //    12    12100
                //    13    14400
                level = Convert.ToInt32(Math.Sqrt(game.GetScore() / 100)) + 1;

                // Max level is 13
                if (level > 13)
                {
                    level = 13;
                }

                progressBarAdv1.Value = level;

                // Game speed ranges from 2 updates a second to about 6 updates a second
                gameTimer.Interval = 3000 / (5 + level);
            }
        }