Пример #1
0
 public TetrisGame()
 {
     Score             = 0;
     TetrominosDropped = 0;
     NextTetromino     = Tetromino.RandomTetromino();
     GameOver          = Paused = TetrominoChanged = false;
     GameStarted       = DateTime.Now;
 }
Пример #2
0
        private void TmrGame_Tick(object sender, EventArgs e)
        {
            //游戏暂停则跳过
            if (tetrisGame.Paused)
            {
                return;
            }

            gameField.DoStep();

            if (!gameField.IsTetrominoFalling)
            {
                //清除满行
                int removeRows = gameField.RemoveFullRows();
                SetScore(tetrisGame.Score + removeRows * 10);
                if (removeRows != 0 && sound)
                {
                    secBuffer = new SecondaryBuffer(Properties.Resources.clear, secDev); //创建辅助缓冲区
                    secBuffer.Play(0, BufferPlayFlags.Default);                          //设置缓冲区为默认播放
                }

                if (!gameField.PlaceTetromino(tetrisGame.NextTetromino))
                {
                    OnGameOver();
                }
                else
                {
                    tetrisGame.NextTetromino = Tetromino.RandomTetromino();
                    tetrisGame.TetrominosDropped++;
                    lblDropped.Text = tetrisGame.TetrominosDropped.ToString();
                    nextTetromino.Clear();
                    nextTetromino.DrawTetromino(tetrisGame.NextTetromino.MoveTo(1, 1), false);

                    //交换tetromino的冷却
                    if (tetrisGame.TetrominoChanged && tetrisGame.TetrominosDropped % 5 == 0)
                    {
                        tetrisGame.TetrominoChanged = false;
                    }

                    //游戏加速
                    if (tetrisGame.TetrominosDropped % 15 == 0 && tetrisGame.Score != 0 && tmrGame.Interval > 300)
                    {
                        tmrGame.Interval -= 100;
                    }

                    ShowTips();
                }
            }
            lblTime.Text = (DateTime.Now - tetrisGame.GameStarted).ToString(@"mm\:ss");

            Refresh();
        }
Пример #3
0
        private void NewGame()
        {
            tetrisGame = new TetrisGame();
            tetrisGame.StateChanged += new EventHandler(Game_StateChanged);
            SetScore(0);

            tmrGame.Interval = 1000;
            tmrGame.Enabled  = true;

            tetrisGame.NextTetromino = Tetromino.RandomTetromino();

            gameField.Clear();

            Refresh();
        }