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) { 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"); } ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.