From c57e78e5444d0b89f8db432125b45ea44a63b6fd Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sat, 5 Jun 2021 22:10:14 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- src/data.py | 33 +++++++++++++++++++++++---------- src/game.py | 43 ++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/data.py b/src/data.py index b892af7..31dfd1e 100644 --- a/src/data.py +++ b/src/data.py @@ -11,10 +11,20 @@ def square_start(self, hieght: int, width: int) -> [[int, int]]: fourth_x = second_x * 3 first_y = hieght / 3 second_y = first_y * 2 - squares = [[first_x, 0], [second_x, 0], [third_x, 0], [fourth_x, 0], - [first_x, first_y], [second_x, first_y], [third_x, first_y], [fourth_x, first_y], - [first_x, second_y], [second_x, second_y], [third_x, second_y], [fourth_x, second_y]] - return squares + return [ + [first_x, 0], + [second_x, 0], + [third_x, 0], + [fourth_x, 0], + [first_x, first_y], + [second_x, first_y], + [third_x, first_y], + [fourth_x, first_y], + [first_x, second_y], + [second_x, second_y], + [third_x, second_y], + [fourth_x, second_y], + ] def fullsquares(self, hieght: int, width: int) -> {int: pygame.Rect}: numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] @@ -28,13 +38,16 @@ def fullsquares(self, hieght: int, width: int) -> {int: pygame.Rect}: return fullsquares def prompts(self) -> {str: str}: - prompts = { - "Pencil": "Click On the square where you saw the yellow Pencil.", - "Mountain": "Click On the square where you saw the Tall White Mountain.", - "Numbers": "Click On the square where you saw the Numbers surronded by the red circles.", - "Letters": "Click On the square where you saw the the letters in the yellow box." + return { + "Pencil": + "Click On the square where you saw the yellow Pencil.", + "Mountain": + "Click On the square where you saw the Tall White Mountain.", + "Numbers": + "Click On the square where you saw the Numbers surronded by the red circles.", + "Letters": + "Click On the square where you saw the the letters in the yellow box.", } - return prompts def images(self) -> {str: pygame.surface}: images = {"Pencil": pygame.image.load("../assets/pencil.jpg"), diff --git a/src/game.py b/src/game.py index 1bbed6a..cd83223 100644 --- a/src/game.py +++ b/src/game.py @@ -64,17 +64,13 @@ def draw_random_image(self, random_image_choice: str = "Mountain", sleeptime: in del self.Images[invimage] self.correct_square = self.squares.index(random_square) self.correct_square += 1 - - prompt = self.prompts[random_image_choice] - - return prompt + + return self.prompts[random_image_choice] def drawscreen(self, difficulty: int = 5, sleeptimer: int = 1) -> pygame.display: prompt = "" current_difficulty = 0 - amount_of_guesses = 1 - while current_difficulty != difficulty: event = pygame.event.poll() if event.type == pygame.QUIT: @@ -87,8 +83,8 @@ def drawscreen(self, difficulty: int = 5, sleeptimer: int = 1) -> pygame.display self.drawlines() prompt = self.draw_random_image(sleeptime=sleeptimer) current_difficulty += 1 - - if self.correct_square == None: + + if self.correct_square is None: print("Game Bug Image did not show up.") print("Restarting...") self.screen.fill((0, 0, 0)) @@ -98,7 +94,9 @@ def drawscreen(self, difficulty: int = 5, sleeptimer: int = 1) -> pygame.display self.drawscreen(difficulty, sleeptimer) else: print(prompt) - + + amount_of_guesses = 1 + while True: event = pygame.event.poll() self.screen.fill((0, 0, 0)) @@ -109,18 +107,17 @@ def drawscreen(self, difficulty: int = 5, sleeptimer: int = 1) -> pygame.display if event.type == pygame.K_ESCAPE: pygame.quit() sys.exit() - - if event.type == pygame.MOUSEBUTTONUP: - + + if (event.type == pygame.MOUSEBUTTONUP + and event.button == 1): correct_rect = self.fullsquares[self.correct_square] - if event.button == 1: - if correct_rect.collidepoint(event.pos): - print("guess : " + str(amount_of_guesses)) - print("Correct!") - print("You got it right in " + str(amount_of_guesses) + " guess/ess") - sys.exit() - - else: - print("guess : " + str(amount_of_guesses)) - amount_of_guesses += 1 - print("That is not the correct square") + if correct_rect.collidepoint(event.pos): + print("guess : " + str(amount_of_guesses)) + print("Correct!") + print("You got it right in " + str(amount_of_guesses) + " guess/ess") + sys.exit() + + else: + print("guess : " + str(amount_of_guesses)) + amount_of_guesses += 1 + print("That is not the correct square")