diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/Snake.iml b/.idea/Snake.iml
new file mode 100644
index 0000000..d0876a7
--- /dev/null
+++ b/.idea/Snake.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..814013f
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/main.py b/main.py
index 142c89e..0b4b61c 100644
--- a/main.py
+++ b/main.py
@@ -2,9 +2,6 @@
import pygame
import random
-
-
-
async def game_loop():
global direction, change_to, score, snake_speed, fruit_spawn, fruit_position
@@ -61,23 +58,35 @@ def show_score(choice, color, font, size):
score_rect = score_surface.get_rect()
game_window.blit(score_surface, score_rect)
- # Game over function
- def game_over():
+ # game over function
+ async def game_over():
+ # creating font object my_font
my_font = pygame.font.SysFont('times new roman', 50)
- game_over_surface = my_font.render('Your Score is : ' + str(score), True, red)
+
+ # creating a text surface on which text
+ # will be drawn
+ game_over_surface = my_font.render('Your Score is : ' + str(score) + " | Press SPACE to play again", True, red)
+
+ # create a rectangular object for the text surface object
game_over_rect = game_over_surface.get_rect()
+
+ # setting position of the text
game_over_rect.midtop = (window_x / 2, window_y / 4)
+
+ # blit will draw the text on screen
game_window.blit(game_over_surface, game_over_rect)
pygame.display.flip()
- # This should be awaited when called from an async function
- async def wait_then_quit():
- await asyncio.sleep(2) # Asynchronous sleep
- pygame.quit()
- quit()
+ while True:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ pygame.quit()
+ quit()
+ if event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_SPACE:
+ return # Exit the loop to restart the game
- # Schedule the wait_then_quit task
- asyncio.create_task(wait_then_quit())
+ await asyncio.sleep(0)
while True:
for event in pygame.event.get():