PY-1.4-BP1-MQ40

Our Goal: Add a Score Limit

In this lesson, you will change the Pong game code. Your goal is to make the game end when a player gets 5 points. The game should then say who won. This is how you add a new feature to your game while working on your special branch.

Check Where You Are

Before you start changing the code, let's make sure you are on the right branch. You should be on the 'feature/add-score-limit' branch.

Run this command in your terminal to see your current branch:

git branch

What you should see:

āœ… The 'feature/add-score-limit' branch should have a star (*) next to it. This means you are in the right place to start adding the score limit!

Add the Score Limit Code

Now it's time to add the code for the score limit! You will be working in the main.py file. Look for the part of the code that updates the score.

Your job is to make the game know when a player has won. This means you need to check if a player's score has reached 5. If it has, the game should end, and you should know who the winner is.

Here are some examples of how you can use if statements to check conditions in Python:

score = 0
if score >= 5:
    print("Player wins!")

You can also set variables based on a condition:

game_over = False
player_score = 6
winning_score = 5

if player_score >= winning_score:
    game_over = True
    print("Game is over!")

Remember to use these ideas to make your Pong game end when a player reaches 5 points!

Check Your Work Again

You've added the score limit code! Now, let's run the tests to see if it works.

Run this command in your terminal:

pytest module-1.4/blueprint-BP1/quest-40

What you should see:

āœ… All tests should pass! This means your score limit code is working correctly.

Documentation

Documentation not available for PY-1.4-BP1.