Add game restart functionality and update roadmap
This commit is contained in:
parent
dda11c6dc5
commit
18ff38fe47
29
ROADMAP.md
29
ROADMAP.md
@ -3,11 +3,15 @@
|
||||
This is a living document that tracks the development progress of the AI Snake Game project.
|
||||
|
||||
## Current Status
|
||||
Last Updated: [Food System Implementation]
|
||||
- Added Food class with spawning mechanics
|
||||
- Integrated food system with main game loop
|
||||
- Implemented basic scoring system
|
||||
- Added game over screen with score display
|
||||
Last Updated: [Restart Functionality Implementation]
|
||||
- Added game restart functionality
|
||||
- Added "Press any key to restart" message
|
||||
- Implemented game state reset
|
||||
- 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 ✅
|
||||
- [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 living roadmap document
|
||||
|
||||
## Phase 2: Core Game Development 🔄
|
||||
## Phase 2: Core Game Development ✅
|
||||
- [x] Implement basic game window using Pygame
|
||||
- [x] Create Snake class with movement mechanics
|
||||
- [x] Implement food spawning system
|
||||
@ -29,9 +33,9 @@ Last Updated: [Food System Implementation]
|
||||
- [ ] Add high score tracking
|
||||
- [x] Add game over conditions
|
||||
- [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
|
||||
- [ ] Create menu layout
|
||||
- [ ] Add game mode selection
|
||||
@ -77,16 +81,13 @@ Last Updated: [Food System Implementation]
|
||||
- [ ] Final testing and refinements
|
||||
|
||||
## Next Steps
|
||||
1. Add restart functionality
|
||||
- Implement game restart on key press
|
||||
- Reset score and snake position
|
||||
2. Create main menu interface
|
||||
1. Create main menu interface
|
||||
- Design menu layout
|
||||
- Implement menu navigation
|
||||
3. Add high score system
|
||||
2. Add high score system
|
||||
- Implement score persistence
|
||||
- Add high score display
|
||||
4. Add visual and sound effects
|
||||
3. Add visual and sound effects
|
||||
- Implement basic animations
|
||||
- Add game sounds
|
||||
|
||||
|
19
src/game.py
19
src/game.py
@ -24,15 +24,17 @@ class Game:
|
||||
|
||||
# Game objects
|
||||
self.block_size = 20
|
||||
self.snake = Snake((self.width // 2, self.height // 2), self.block_size)
|
||||
self.food = Food(self.block_size)
|
||||
|
||||
# Spawn initial food
|
||||
self.food.spawn(self.width, self.height, self.snake.body)
|
||||
self.reset_game()
|
||||
|
||||
# Game state
|
||||
self.state = GameState.PLAYING # Changed to start in playing state for now
|
||||
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
|
||||
|
||||
def handle_events(self):
|
||||
@ -55,6 +57,10 @@ class Game:
|
||||
self.snake.change_direction(Direction.LEFT)
|
||||
elif event.key == pygame.K_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):
|
||||
if self.state == GameState.PLAYING:
|
||||
@ -95,12 +101,15 @@ class Game:
|
||||
font = pygame.font.Font(None, 74)
|
||||
text = font.render('Game Over!', True, (255, 0, 0))
|
||||
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))
|
||||
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(score_text, score_rect)
|
||||
self.screen.blit(restart_text, restart_rect)
|
||||
|
||||
# Update display
|
||||
pygame.display.flip()
|
||||
|
Loading…
Reference in New Issue
Block a user