Initializing the score

In order to have a score, we are going to create a variable for each player that begins at the default score, zero. As this is a global variable, like the other integers, it will change as the game loop runs. For now, we just need to have placeholders for each player. So, starting on line 46, add these lines of code to your game:

  # initialize score
  player1_score = 0
  player2_score = 0

We have now created all of the global variables that we need to write code that is easier to understand. Remember, these are called global variables because they can be used throughout the entire code file. Save your file. Then, compare your code with the completed code in this screenshot:

Initializing the score
..................Content has been hidden....................

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