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 int DetermineScore(int SquareCount)
    {
    return (int)((Math.Pow((SquareCount/5), 2) + SquareCount)*10);
    }
    
  2. Add a method to evaluate a chain to determine if it scores and process it:
    private void CheckScoringChain(List<Vector2> WaterChain)
    {
    if (WaterChain.Count > 0)
    {
    Vector2 LastPipe = WaterChain[WaterChain.Count - 1];
    if (LastPipe.X == GameBoard.GameBoardWidth - 1)
    Flood Control game, buildingscoring chains{
    if (gameBoard.HasConnector(
    (int)LastPipe.X, (int)LastPipe.Y, "Right"))
    {
    playerScore += DetermineScore(WaterChain.Count);
    foreach (Vector2 ScoringSquare in WaterChain)
    {
    gameBoard.SetSquare((int)ScoringSquare.X,
    (int)ScoringSquare.Y, "Empty");
    }
    }
    }
    }
    }
    

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 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 makes longer scoring chains (especially increments of five squares) award much higher scores than a series of shorter chains.

The CheckScoringRow() 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, CheckScoringRow() sets all of the pieces in the scoring row 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.68.14