original_docstring: The game function takes the ball speed as the ball speed was determined by the game men. Contains the game.
docstring: The game function takes the ball speed as the ball speed was determined by the game men. Contains the game.
docstring_tokens: The game function takes the ball speed as the ball speed was determined by the game men . Contains the game .
code: def run_game(self, ball_x_speed):
          """The game function takes the ball speed as the ball speed was determined by the game men. Contains the game."""
          running = True
          self.default_ball_speed = ball_x_speed
          self.ball.reset_ball()
  
          while running:
              pygame.time.Clock().tick(120)
              self.click = False
              self.score.left_color = self.left_paddle.color
              self.score.right_color = self.right_paddle.color
              # Checks to see if the user quits or presses the mouse. If they press the mouse down then it will return click as True
              for event in pygame.event.get():
                  if event.type == pygame.QUIT:
                      self.reset_game()
                      return False
                  if event.type == pygame.MOUSEBUTTONDOWN:
                      if event.button == 1:
                          self.click = True
  
              # Checking for the keys pressed and creating the pause button. Also creates score board
              keys = pygame.key.get_pressed()
              self.screen.fill((0, 0, 0))
              self.score.show_score(self.screen, (255, 255, 255))
              pause_button = pygame.rect.Rect((380, 0, 50, 50))
              pygame.draw.rect(self.screen, (0, 0, 0), pause_button)
              self.display.create_text((391, 0), (255, 255, 255), 50, "ll", self.screen)
  
              # Draw the paddles
              right_pad = pygame.draw.rect(self.screen, self.right_paddle.color,
                                           (
                                               self.right_paddle.x_cord, self.right_paddle.y_cord,
                                               self.right_paddle.width, self.right_paddle.height))
              left_pad = pygame.draw.rect(self.screen, self.left_paddle.color,
                                          (self.left_paddle.x_cord, self.left_paddle.y_cord, self.left_paddle.width,
                                           self.left_paddle.height))
  
              # Checks to see if a key is pressed if one is then move a paddle
              if keys[pygame.K_UP] and self.right_paddle.y_cord > 0:
                  self.right_paddle.y_cord -= self.y_speed
              if keys[pygame.K_DOWN] and self.right_paddle.y_cord < 600 - self.right_paddle.height:
                  self.right_paddle.y_cord += self.y_speed
              if keys[pygame.K_w] and self.left_paddle.y_cord > 0:
                  self.left_paddle.y_cord -= self.y_speed
              if keys[pygame.K_s] and self.left_paddle.y_cord < 600 - self.left_paddle.height:
                  self.left_paddle.y_cord += self.y_speed
  
              # Drawing the ball and ball movement
              game_ball = pygame.draw.rect(self.screen, self.ball.color,
                                           (self.ball.x_cord, self.ball.y_cord, self.ball.width, self.ball.height))
  
              if self.ball.ball_moving_state:
                  # Ball movement and collision with wall if the ball is in moving state then move the ball else display message to press space. Once the space bar is hit the ball state is moving
                  if 575 > self.ball.y_cord > 0:
                      self.ball.y_cord += self.ball.ball_y_speed
                      self.ball.x_cord += self.ball.ball_x_speed
                  else:
                      self.ball.ball_y_speed *= -1
                      self.ball.y_cord += self.ball.ball_y_speed
              else:
                  if keys[pygame.K_SPACE]:
                      self.ball.ball_moving_state = True
                  self.display.display_continue_message(self.screen, (49, 51, 53))
  
              # checks to see if the ball collides with the if it does the ball changes x direction and slightly increases speed.
              if right_pad.colliderect(game_ball) or left_pad.colliderect(game_ball):
                  self.ball.ball_x_speed *= -1
                  for _ in range(2):
                      self.ball.x_cord += self.ball.ball_x_speed
                  self.ball.ball_x_speed *= 1.1
  
              # reset ball if goes past the paddle. Checks to see if which side the ball went past and adds a point to the opposing side. Additional sets the ball moving state to False
              if self.ball.x_cord < 0 or self.ball.x_cord > 770:
                  self.ball.ball_moving_state = False
                  if self.ball.x_cord < 30:
                      self.score.right_score += 1
                      self.ball.ball_x_speed = self.default_ball_speed
                  elif self.ball.x_cord > 770:
                      self.score.left_score += 1
                      self.ball.ball_x_speed = self.default_ball_speed
                      self.ball.ball_x_speed *= -1
                  self.ball.reset_ball()
  
              # Check to see if the pause button is click on. If it is calls the pause menu function. In the pause menu if the home option is hit the game function is quit
              if pause_button.collidepoint(get_mouse_pos()):
                  if self.click:
                      print("clicked pause")
                      if self.pause_screen(self.ball.ball_x_speed, self.ball.ball_y_speed, "pause"):
                          self.reset_game()
                          print("going home")
                          return True
  
              pygame.display.update()
  
              # checks to see if teh game is over when a side hits the required score if so then displays the game over screen if the user hits home game function is quit to the starting menu if the redo is hit the score is reset.
              if self.score.game_over():
                  self.score.reset_score()
                  if self.pause_screen(self.ball.ball_x_speed, self.ball.ball_y_speed, "game_over"):
                      self.reset_game()
                      return True
code_tokens: def run_game ( self , ball_x_speed ) : running = True self . default_ball_speed = ball_x_speed self . ball . reset_ball ( ) while running : pygame . time . Clock ( ) . tick ( 120 ) self . click = False self . score . left_color = self . left_paddle . color self . score . right_color = self . right_paddle . color for event in pygame . event . get ( ) : if event . type == pygame . QUIT : self . reset_game ( ) return False if event . type == pygame . MOUSEBUTTONDOWN : if event . button == 1 : self . click = True keys = pygame . key . get_pressed ( ) self . screen . fill ( ( 0 , 0 , 0 ) ) self . score . show_score ( self . screen , ( 255 , 255 , 255 ) ) pause_button = pygame . rect . Rect ( ( 380 , 0 , 50 , 50 ) ) pygame . draw . rect ( self . screen , ( 0 , 0 , 0 ) , pause_button ) self . display . create_text ( ( 391 , 0 ) , ( 255 , 255 , 255 ) , 50 , "ll" , self . screen ) right_pad = pygame . draw . rect ( self . screen , self . right_paddle . color , ( self . right_paddle . x_cord , self . right_paddle . y_cord , self . right_paddle . width , self . right_paddle . height ) ) left_pad = pygame . draw . rect ( self . screen , self . left_paddle . color , ( self . left_paddle . x_cord , self . left_paddle . y_cord , self . left_paddle . width , self . left_paddle . height ) ) if keys [ pygame . K_UP ] and self . right_paddle . y_cord > 0 : self . right_paddle . y_cord -= self . y_speed if keys [ pygame . K_DOWN ] and self . right_paddle . y_cord < 600 - self . right_paddle . height : self . right_paddle . y_cord += self . y_speed if keys [ pygame . K_w ] and self . left_paddle . y_cord > 0 : self . left_paddle . y_cord -= self . y_speed if keys [ pygame . K_s ] and self . left_paddle . y_cord < 600 - self . left_paddle . height : self . left_paddle . y_cord += self . y_speed game_ball = pygame . draw . rect ( self . screen , self . ball . color , ( self . ball . x_cord , self . ball . y_cord , self . ball . width , self . ball . height ) ) if self . ball . ball_moving_state : if 575 > self . ball . y_cord > 0 : self . ball . y_cord += self . ball . ball_y_speed self . ball . x_cord += self . ball . ball_x_speed else : self . ball . ball_y_speed *= - 1 self . ball . y_cord += self . ball . ball_y_speed else : if keys [ pygame . K_SPACE ] : self . ball . ball_moving_state = True self . display . display_continue_message ( self . screen , ( 49 , 51 , 53 ) ) if right_pad . colliderect ( game_ball ) or left_pad . colliderect ( game_ball ) : self . ball . ball_x_speed *= - 1 for _ in range ( 2 ) : self . ball . x_cord += self . ball . ball_x_speed self . ball . ball_x_speed *= 1.1 if self . ball . x_cord < 0 or self . ball . x_cord > 770 : self . ball . ball_moving_state = False if self . ball . x_cord < 30 : self . score . right_score += 1 self . ball . ball_x_speed = self . default_ball_speed elif self . ball . x_cord > 770 : self . score . left_score += 1 self . ball . ball_x_speed = self . default_ball_speed self . ball . ball_x_speed *= - 1 self . ball . reset_ball ( ) if pause_button . collidepoint ( get_mouse_pos ( ) ) : if self . click : print ( "clicked pause" ) if self . pause_screen ( self . ball . ball_x_speed , self . ball . ball_y_speed , "pause" ) : self . reset_game ( ) print ( "going home" ) return True pygame . display . update ( ) if self . score . game_over ( ) : self . score . reset_score ( ) if self . pause_screen ( self . ball . ball_x_speed , self . ball . ball_y_speed , "game_over" ) : self . reset_game ( ) return True
short_docstring: The game function takes the ball speed as the ball speed was determined by the game men.
short_docstring_tokens: The game function takes the ball speed as the ball speed was determined by the game men .
comment: """The game function takes the ball speed as the ball speed was determined by the game men. Contains the game."""$SEP$# Checks to see if the user quits or presses the mouse. If they press the mouse down then it will return click as True
  $SEP$# Checking for the keys pressed and creating the pause button. Also creates score board
  $SEP$# Draw the paddles
  $SEP$# Checks to see if a key is pressed if one is then move a paddle
  $SEP$# Drawing the ball and ball movement
  $SEP$# Ball movement and collision with wall if the ball is in moving state then move the ball else display message to press space. Once the space bar is hit the ball state is moving
  $SEP$# checks to see if the ball collides with the if it does the ball changes x direction and slightly increases speed.
  $SEP$# reset ball if goes past the paddle. Checks to see if which side the ball went past and adds a point to the opposing side. Additional sets the ball moving state to False
  $SEP$# Check to see if the pause button is click on. If it is calls the pause menu function. In the pause menu if the home option is hit the game function is quit
  $SEP$# checks to see if teh game is over when a side hits the required score if so then displays the game over screen if the user hits home game function is quit to the starting menu if the redo is hit the score is reset.
  