官术网_书友最值得收藏!

Time for action – letting the player play

  1. Modify the Update() method of Game1.vb, by adding the following before the call to MyBase.Update(gameTime):
    Select Case gameState
      Case GameStates.TitleScreen
        If Keyboard.GetState().IsKeyDown(Keys.Space) Then
          _gameBoard.ClearBoard()
          _gameBoard.GenerateNewPieces(False)
          playerScore = 0
          gameState = GameStates.Playing
        End If
    
        Case GameStates.Playing
          timeSinceLastInput +=
          (CSng(gameTime.ElapsedGameTime.TotalSeconds))
    
          If timeSinceLastInput >= MinTimeSinceLastInput Then
            HandleMouseInput(Mouse.GetState())
          End If
    
          _gameBoard.ResetWater()
    
          Dim y As Integer
    
          For y = 0 To GameBoard.GameBoardHeight
            CheckScoringChain(_gameBoard.GetWaterChain(y))
          Next
    
          _gameBoard.GenerateNewPieces(True)
    End Select

What just happened?

The Update() method performs two different functions, depending on the current gameState value. If the game is in TitleScreen state, Update() examines the keyboard, waiting for the Space bar to be pressed. When it is, Update() clears the _gameBoard, generates a new set of pieces, resets the player's score, and changes gameState to Playing.

While in the Playing state, Update() accumulates time in timeSinceLastInput in order to pace the game play properly. If enough time has passed, the HandleMouseInput() method is called to allow the player to rotate game pieces.

Update() then calls ResetWater() to clear the water flags for all pieces on the game board. This is followed by a loop that processes each row, starting at the top and working downward, using CheckScoringChain() and GetWaterChain(), to fill any pieces that should have water in them and check the results of each row for completed chains.

Finally, GenerateNewPieces() is called with the true parameter for dropSquares, which will cause GenerateNewPieces() to fill the empty holes from the squares above, and then generate new pipes to replace the empty squares.

主站蜘蛛池模板: 东乡族自治县| 临西县| 梨树县| 长宁县| 营口市| 自贡市| 广州市| 阿拉善右旗| 嘉峪关市| 磐安县| 怀集县| 北海市| 达州市| 栖霞市| 襄城县| 乳山市| 万年县| 大同县| 广汉市| 大安市| 夹江县| 葫芦岛市| 桐乡市| 阆中市| 赤峰市| 新乡县| 瓮安县| 浦东新区| 囊谦县| 苏尼特左旗| 中超| SHOW| 湄潭县| 长沙县| 莒南县| 盖州市| 万山特区| 怀远县| 东台市| 类乌齐县| 兴山县|