Add game restart functionality and update roadmap

This commit is contained in:
Rbanh 2025-02-23 12:13:24 -05:00
parent dda11c6dc5
commit 18ff38fe47
2 changed files with 29 additions and 19 deletions

View File

@ -3,11 +3,15 @@
This is a living document that tracks the development progress of the AI Snake Game project. This is a living document that tracks the development progress of the AI Snake Game project.
## Current Status ## Current Status
Last Updated: [Food System Implementation] Last Updated: [Restart Functionality Implementation]
- Added Food class with spawning mechanics - Added game restart functionality
- Integrated food system with main game loop - Added "Press any key to restart" message
- Implemented basic scoring system - Implemented game state reset
- Added game over screen with score display - Previous updates:
- Added Food class with spawning mechanics
- Integrated food system with main game loop
- Implemented basic scoring system
- Added game over screen with score display
## Phase 1: Project Setup and Basic Structure ✅ ## Phase 1: Project Setup and Basic Structure ✅
- [x] Create project structure and virtual environment - [x] Create project structure and virtual environment
@ -16,7 +20,7 @@ Last Updated: [Food System Implementation]
- [x] Create basic project documentation (README.md) - [x] Create basic project documentation (README.md)
- [x] Create living roadmap document - [x] Create living roadmap document
## Phase 2: Core Game Development 🔄 ## Phase 2: Core Game Development
- [x] Implement basic game window using Pygame - [x] Implement basic game window using Pygame
- [x] Create Snake class with movement mechanics - [x] Create Snake class with movement mechanics
- [x] Implement food spawning system - [x] Implement food spawning system
@ -29,9 +33,9 @@ Last Updated: [Food System Implementation]
- [ ] Add high score tracking - [ ] Add high score tracking
- [x] Add game over conditions - [x] Add game over conditions
- [x] Implement game over state transition - [x] Implement game over state transition
- [ ] Add restart functionality - [x] Add restart functionality
## Phase 3: Game Polish and UI ## Phase 3: Game Polish and UI 🔄
- [ ] Add main menu interface - [ ] Add main menu interface
- [ ] Create menu layout - [ ] Create menu layout
- [ ] Add game mode selection - [ ] Add game mode selection
@ -77,16 +81,13 @@ Last Updated: [Food System Implementation]
- [ ] Final testing and refinements - [ ] Final testing and refinements
## Next Steps ## Next Steps
1. Add restart functionality 1. Create main menu interface
- Implement game restart on key press
- Reset score and snake position
2. Create main menu interface
- Design menu layout - Design menu layout
- Implement menu navigation - Implement menu navigation
3. Add high score system 2. Add high score system
- Implement score persistence - Implement score persistence
- Add high score display - Add high score display
4. Add visual and sound effects 3. Add visual and sound effects
- Implement basic animations - Implement basic animations
- Add game sounds - Add game sounds

View File

@ -24,15 +24,17 @@ class Game:
# Game objects # Game objects
self.block_size = 20 self.block_size = 20
self.snake = Snake((self.width // 2, self.height // 2), self.block_size) self.reset_game()
self.food = Food(self.block_size)
# Spawn initial food
self.food.spawn(self.width, self.height, self.snake.body)
# Game state # Game state
self.state = GameState.PLAYING # Changed to start in playing state for now self.state = GameState.PLAYING # Changed to start in playing state for now
self.running = True self.running = True
def reset_game(self):
"""Reset the game state for a new game"""
self.snake = Snake((self.width // 2, self.height // 2), self.block_size)
self.food = Food(self.block_size)
self.food.spawn(self.width, self.height, self.snake.body)
self.score = 0 self.score = 0
def handle_events(self): def handle_events(self):
@ -55,6 +57,10 @@ class Game:
self.snake.change_direction(Direction.LEFT) self.snake.change_direction(Direction.LEFT)
elif event.key == pygame.K_RIGHT: elif event.key == pygame.K_RIGHT:
self.snake.change_direction(Direction.RIGHT) self.snake.change_direction(Direction.RIGHT)
elif self.state == GameState.GAME_OVER:
# Any key to restart in game over state
self.reset_game()
self.state = GameState.PLAYING
def update(self): def update(self):
if self.state == GameState.PLAYING: if self.state == GameState.PLAYING:
@ -95,12 +101,15 @@ class Game:
font = pygame.font.Font(None, 74) font = pygame.font.Font(None, 74)
text = font.render('Game Over!', True, (255, 0, 0)) text = font.render('Game Over!', True, (255, 0, 0))
score_text = font.render(f'Score: {self.score}', True, (255, 255, 255)) score_text = font.render(f'Score: {self.score}', True, (255, 255, 255))
restart_text = font.render('Press any key to restart', True, (255, 255, 255))
text_rect = text.get_rect(center=(self.width//2, self.height//2 - 50)) text_rect = text.get_rect(center=(self.width//2, self.height//2 - 50))
score_rect = score_text.get_rect(center=(self.width//2, self.height//2 + 50)) score_rect = score_text.get_rect(center=(self.width//2, self.height//2 + 50))
restart_rect = restart_text.get_rect(center=(self.width//2, self.height//2 + 150))
self.screen.blit(text, text_rect) self.screen.blit(text, text_rect)
self.screen.blit(score_text, score_rect) self.screen.blit(score_text, score_rect)
self.screen.blit(restart_text, restart_rect)
# Update display # Update display
pygame.display.flip() pygame.display.flip()