Add testing framework and debug mode
This commit is contained in:
1 parent
33cca6cd3c
commit
cb626dfe7d
6 files changed
+237
No files matched your search
+36
@@ -32,6 +32,9 @@ class Game:
|
||||
self.state = GameState.MENU # Start in menu state
|
||||
self.running = True
|
||||
self.game_mode = None
|
||||
|
||||
# Debug mode
|
||||
self.debug = False
|
||||
|
||||
def reset_game(self):
|
||||
"""Reset the game state for a new game"""
|
||||
@@ -40,6 +43,29 @@ class Game:
|
||||
self.food.spawn(self.width, self.height, self.snake.body)
|
||||
self.score = 0
|
||||
|
||||
def draw_grid(self):
|
||||
"""Draw the game grid (debug mode)"""
|
||||
for x in range(0, self.width, self.block_size):
|
||||
pygame.draw.line(self.screen, (50, 50, 50), (x, 0), (x, self.height))
|
||||
for y in range(0, self.height, self.block_size):
|
||||
pygame.draw.line(self.screen, (50, 50, 50), (0, y), (self.width, y))
|
||||
|
||||
def draw_debug_info(self):
|
||||
"""Draw debug information"""
|
||||
font = pygame.font.Font(None, 24)
|
||||
debug_info = [
|
||||
f"FPS: {int(self.clock.get_fps())}",
|
||||
f"Snake Length: {len(self.snake.body)}",
|
||||
f"Snake Head: {self.snake.body[0]}",
|
||||
f"Food Pos: {self.food.position}",
|
||||
f"Game State: {self.state.name}",
|
||||
f"Game Mode: {self.game_mode.name if self.game_mode else 'None'}"
|
||||
]
|
||||
|
||||
for i, text in enumerate(debug_info):
|
||||
surface = font.render(text, True, (0, 255, 0))
|
||||
self.screen.blit(surface, (10, self.height - 150 + i * 25))
|
||||
|
||||
def handle_events(self):
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
@@ -52,6 +78,8 @@ class Game:
|
||||
self.state = GameState.PLAYING
|
||||
elif self.state == GameState.MENU:
|
||||
self.running = False
|
||||
elif event.key == pygame.K_F3: # Toggle debug mode
|
||||
self.debug = not self.debug
|
||||
|
||||
if self.state == GameState.MENU:
|
||||
# Handle menu input
|
||||
@@ -101,6 +129,10 @@ class Game:
|
||||
# Clear screen
|
||||
self.screen.fill((0, 0, 0)) # Black background
|
||||
|
||||
# Draw grid in debug mode
|
||||
if self.debug and self.state != GameState.MENU:
|
||||
self.draw_grid()
|
||||
|
||||
if self.state == GameState.MENU:
|
||||
self.menu.draw(self.screen)
|
||||
|
||||
@@ -138,6 +170,10 @@ class Game:
|
||||
self.screen.blit(score_text, score_rect)
|
||||
self.screen.blit(restart_text, restart_rect)
|
||||
|
||||
# Draw debug info
|
||||
if self.debug:
|
||||
self.draw_debug_info()
|
||||
|
||||
# Update display
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
Reference in new issue
Block a user