Building the Score Limit

Objective: Building the Score Limit

Welcome to Building the Score Limit!

Our objective is to modify the provided Pygame Pong code to add a winning score limit. The game should end and declare a winner when one player reaches a score of 5.

This micro-quest focuses on Isolated Feature Implementation using Git branches.

Check Spec: Verify Your Branch

Before we begin implementing the feature, let's ensure we are working in the correct isolated environment.

Use Git commands to verify that you are currently on the feature/add-score-limit branch.

Review the documentation on Git branching if you need a reminder on how to check your current branch.

Once you've confirmed you are on the correct branch, proceed to the next step.

Implement: Add Score Limit Logic

Now, let's implement the score limit logic within the update_and_check_score function in main.py.

Your task is to add the necessary checks to determine if a player's score has reached or exceeded the WINNING_SCORE and update the game_over and winner variables accordingly.

Step by step checklist:

  1. Locate the update_and_check_score function in main.py.
  2. After the scores have been incremented, add logic to check if new_player1_score is greater than or equal to the winning_score.
  3. If player 1's score meets or exceeds the limit, set the game_over flag to True and the winner to 1.
  4. Add logic to check if new_player2_score is greater than or equal to the winning_score.
  5. If player 2's score meets or exceeds the limit, set the game_over flag to True and the winner to 2.
  6. Ensure the function returns the updated scores, the game_over status, and the winner.

The following documentation sections are going to be helpful:

  • Isolated Feature Implementation

Validate: Run the Tests

With the score limit logic implemented, let's validate your work by running the provided test suite (test_main.py).

Execute the tests to ensure the update_and_check_score function correctly handles score increments, checks the winning condition, and identifies the winner.

If all tests pass, your implementation meets the specification.

Verification Results:

  • ✅ test_score_increment_player1
  • ✅ test_score_increment_player2
  • ✅ test_scores_below_limit_not_game_over
  • ✅ test_player1_reaches_limit_exactly
  • ✅ test_player2_reaches_limit_exactly
  • ✅ test_player1_exceeds_limit
  • ✅ test_player2_exceeds_limit
  • ✅ test_invalid_scoring_player_raises_error
  • ✅ test_custom_winning_score_parameter All verification steps passed!

Documentation

Documentation not available for PY-1.4-BP1.