From 5f9562a9d68c2b18d159eba9aff0eda2a7469168 Mon Sep 17 00:00:00 2001 From: shiventi <105996940+shiventi@users.noreply.github.com> Date: Tue, 24 May 2022 21:07:34 -0700 Subject: [PATCH 1/4] Create space_counter_solution.py --- .../solutions/space_counter_solution.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 games/chapter3/solutions/space_counter_solution.py diff --git a/games/chapter3/solutions/space_counter_solution.py b/games/chapter3/solutions/space_counter_solution.py new file mode 100644 index 00000000..ae1a425e --- /dev/null +++ b/games/chapter3/solutions/space_counter_solution.py @@ -0,0 +1,39 @@ +import pygame + +pygame.init() +screen = pygame.display.set_mode((400, 400)) + +font = pygame.font.SysFont('arial', 70) + +display_counter = 0 + +while True: + + # Render the "display_counter" to the screen + + show_counter = font.render(str(display_counter), True, (255,192,203)) + + # Makes Screen Black + + screen.fill((0, 0, 0)) + + # Prints Data on Screen + + screen.blit(show_counter, (30,30)) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + break + + # Checks to see if key is pressed + if event.type == pygame.KEYDOWN: + + # Checks to see if the space is pressed + if event.key == pygame.K_SPACE: + + # Adds one to the counter + display_counter += 1 + + # Updates the data + pygame.display.update() From 069ef2171e6b88f74945a7a84f4ba0e33001ab1a Mon Sep 17 00:00:00 2001 From: shiventi <105996940+shiventi@users.noreply.github.com> Date: Wed, 25 May 2022 20:42:07 -0700 Subject: [PATCH 2/4] Update and rename space_counter_solution.py to SpaceCounter.py --- .../{space_counter_solution.py => SpaceCounter.py} | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) rename games/chapter3/solutions/{space_counter_solution.py => SpaceCounter.py} (79%) diff --git a/games/chapter3/solutions/space_counter_solution.py b/games/chapter3/solutions/SpaceCounter.py similarity index 79% rename from games/chapter3/solutions/space_counter_solution.py rename to games/chapter3/solutions/SpaceCounter.py index ae1a425e..d719691f 100644 --- a/games/chapter3/solutions/space_counter_solution.py +++ b/games/chapter3/solutions/SpaceCounter.py @@ -1,3 +1,6 @@ +#Create a program that increments a counter every time the space bar is pressed. +#This counter should be displayed as text on the pygame window. + import pygame pygame.init() @@ -6,8 +9,10 @@ font = pygame.font.SysFont('arial', 70) display_counter = 0 + +run = True -while True: +while run: # Render the "display_counter" to the screen @@ -23,8 +28,7 @@ for event in pygame.event.get(): if event.type == pygame.QUIT: - pygame.quit() - break + run = False # Checks to see if key is pressed if event.type == pygame.KEYDOWN: From ce2201c547566acf007f9219963ccb7b4b908739 Mon Sep 17 00:00:00 2001 From: shiventi <105996940+shiventi@users.noreply.github.com> Date: Wed, 25 May 2022 20:54:38 -0700 Subject: [PATCH 3/4] Update SpaceCounter.py --- games/chapter3/solutions/SpaceCounter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/games/chapter3/solutions/SpaceCounter.py b/games/chapter3/solutions/SpaceCounter.py index d719691f..72736bd4 100644 --- a/games/chapter3/solutions/SpaceCounter.py +++ b/games/chapter3/solutions/SpaceCounter.py @@ -41,3 +41,5 @@ # Updates the data pygame.display.update() + +pygame.quit() From 0d8cba1bca7f8d401f63ab63f0fa94815ad3ae2f Mon Sep 17 00:00:00 2001 From: shiventi <105996940+shiventi@users.noreply.github.com> Date: Wed, 25 May 2022 21:09:29 -0700 Subject: [PATCH 4/4] Update SpaceCounter.py --- games/chapter3/solutions/SpaceCounter.py | 49 +++++++++++------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/games/chapter3/solutions/SpaceCounter.py b/games/chapter3/solutions/SpaceCounter.py index 72736bd4..069dae81 100644 --- a/games/chapter3/solutions/SpaceCounter.py +++ b/games/chapter3/solutions/SpaceCounter.py @@ -1,45 +1,42 @@ -#Create a program that increments a counter every time the space bar is pressed. -#This counter should be displayed as text on the pygame window. - import pygame - + pygame.init() screen = pygame.display.set_mode((400, 400)) - -font = pygame.font.SysFont('arial', 70) + +font = pygame.font.SysFont("arial", 70) display_counter = 0 run = True - + while run: - # Render the "display_counter" to the screen + # Render the "display_counter" to the screen + + show_counter = font.render(str(display_counter), True, (255, 192, 203)) + + # Makes Screen Black - show_counter = font.render(str(display_counter), True, (255,192,203)) - - # Makes Screen Black + screen.fill((0, 0, 0)) - screen.fill((0, 0, 0)) + # Prints Data on Screen - # Prints Data on Screen + screen.blit(show_counter, (30, 30)) - screen.blit(show_counter, (30,30)) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False - for event in pygame.event.get(): - if event.type == pygame.QUIT: - run = False + # Checks to see if key is pressed + if event.type == pygame.KEYDOWN: - # Checks to see if key is pressed - if event.type == pygame.KEYDOWN: + # Checks to see if the space is pressed + if event.key == pygame.K_SPACE: - # Checks to see if the space is pressed - if event.key == pygame.K_SPACE: + # Adds one to the counter + display_counter += 1 - # Adds one to the counter - display_counter += 1 + # Updates the data + pygame.display.update() - # Updates the data - pygame.display.update() - pygame.quit()