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

Time for action – scores and scoring chains

  1. Add a method to the Game1 class to calculate a score based on the number of pipes used:
    Private Function DetermineScore(squareCount As Integer) As Integer
      Return CInt(
        ((Math.Pow((squareCount / 5), 2) + squareCount) * 10))
    End Function
  2. Add a method to evaluate a chain to determine if it scores and process it:
    Private Sub CheckScoringChain(WaterChain As List(Of Vector2))
      If (WaterChain.Count > 0) Then
        Dim LastPipe As Vector2 = WaterChain(WaterChain.Count - 1)
    
        If LastPipe.X = gameBoard.GameBoardWidth Then
          If _gameBoard.HasConnector(
            CInt(LastPipe.X),
            CInt(LastPipe.Y), 
          "Right") Then
            playerScore += DetermineScore(WaterChain.Count)
            For Each thisPipe As Vector2 In WaterChain
              _gameBoard.SetSquare(
                CInt(thisPipe.X),
                CInt(thisPipe.Y),
              "Empty")
            Next
          End If
        End If
      End If
    End Sub

What just happened?

DetermineScore() accepts the number of squares in a scoring chain and returns a score value for that chain. The number of squares in the chain is divided by 5, and that number is squared. The initial number of squares is added to the result, and the final amount is multiplied by 10.

Score = (((Squares / 5) ^ 2) + Squares) * 10

For example, a minimum scoring chain would be 8 squares (forming a straight line across the board). This chain would result in 1 squared plus 8 times 10, or 90 points. If a chain had 18 squares, the result would be 3 squared plus 18 times 10, or 270 points. This scoring equation makes longer scoring chains (especially increments of five squares) award much higher scores than a series of shorter chains.

The CheckScoringChain() method makes sure that there are entries in the WaterChain list, and then examines the last piece in the chain and checks to see if it has an X value of 7 (the right-most column on the board). If it does, the HasConnector() method is checked to see if the last pipe has a connector to the right, indicating that it completes a chain across the board.

After updating playerScore for the scoring row, CheckScoringChain() sets all of the pieces in the scoring chain to Empty. They will be refilled by a subsequent call to the GenerateNewPieces() method.

Input handling

The player interacts with Flood Control using the mouse. For readability reasons, we will create a helper method that deals with mouse input and call it when appropriate from the Update() method.

主站蜘蛛池模板: 许昌市| 德令哈市| 剑川县| 富阳市| 临安市| 库伦旗| 深水埗区| 霍林郭勒市| 德庆县| 金寨县| 中超| 诏安县| 关岭| 云南省| 大名县| 嘉善县| 新民市| 原阳县| 咸宁市| 增城市| 醴陵市| 友谊县| 阆中市| 郁南县| 溧水县| 平武县| 凤凰县| 盘山县| 丰都县| 静宁县| 昌黎县| 北海市| 崇阳县| 桃园市| 亳州市| 濮阳县| 保靖县| 镇江市| 庆元县| 娄底市| 普陀区|