feat: +unit test

fixbug: PYTHONPATH

fixbug: unit test
This commit is contained in:
莘权 马 2023-12-27 11:24:22 +08:00
parent 641c71bf18
commit 0adabfe53f
33 changed files with 1561 additions and 297 deletions

View file

@ -0,0 +1,57 @@
## Implementation approach
We will use the Pygame library to create the game interface and handle user input. The game logic will be implemented using Python classes and data structures.
## File list
- main.py
- game.py
## Data structures and interfaces
classDiagram
class Game {
-grid: List[List[int]]
-score: int
-game_over: bool
+__init__()
+reset_game()
+move(direction: str)
+is_game_over() bool
+get_empty_cells() List[Tuple[int, int]]
+add_new_tile()
+get_score() int
}
class UI {
-game: Game
+__init__(game: Game)
+draw_grid()
+draw_score()
+draw_game_over()
+handle_input()
}
Game --> UI
## Program call flow
sequenceDiagram
participant M as Main
participant G as Game
participant U as UI
M->>G: reset_game()
M->>U: draw_grid()
M->>U: draw_score()
M->>U: handle_input()
U->>G: move(direction)
G->>G: add_new_tile()
G->>U: draw_grid()
G->>U: draw_score()
G->>U: draw_game_over()
G->>G: is_game_over()
G->>G: get_empty_cells()
G->>G: get_score()
## Anything UNCLEAR
...

View file

@ -0,0 +1,63 @@
## Language
en_us
## Programming Language
Python
## Original Requirements
write a 2048 game
## Project Name
game_2048
## Product Goals
- Create an addictive and engaging gaming experience
- Ensure smooth performance and responsiveness
- Offer customizable game settings and features
## User Stories
- As a player, I want to be able to play the game on different devices and screen sizes
- As a gamer, I want to be challenged with increasing difficulty levels as I progress
- As a user, I want to be able to undo my last move in the game
## Competitive Analysis
- 2048 Game by Gabriele Cirulli: Popular and addictive, lacks advanced customization options
## Competitive Quadrant Chart
quadrantChart
title "Engagement and Customization of 2048 Games"
x-axis "Low Customization" --> "High Customization"
y-axis "Low Engagement" --> "High Engagement"
quadrant-1 "Enhance Customization"
quadrant-2 "Improve Engagement"
quadrant-3 "Maintain Customization, Enhance Engagement"
quadrant-4 "Highly Engaging and Customizable"
"2048 Game by Gabriele Cirulli": [0.4, 0.7]
"Our Target Product": [0.6, 0.8]
## Requirement Analysis
The product should provide an intuitive and seamless gaming experience with customizable features to enhance user engagement.
## Requirement Pool
- ['P0', 'Implement game logic and user interface']
- ['P1', 'Incorporate multiple difficulty levels and scoring system']
- ['P2', 'Integrate customizable game settings and undo feature']
## UI Design draft
The UI should have a clean and modern design with intuitive game controls and customizable settings for difficulty levels and game themes.
## Anything UNCLEAR
...

View file

@ -0,0 +1,39 @@
### Code Review All
#### game.py
- The `add_new_tile` function should handle the case when there are no empty cells left.
- The `move` function should update the score when tiles are merged.
#### main.py
- The game loop does not handle the game over condition properly. It should break the loop when the game is over.
### Call flow
```mermaid
sequenceDiagram
participant M as Main
participant G as Game
participant U as UI
M->>G: reset_game()
M->>U: draw_grid()
M->>U: draw_score()
M->>U: handle_input()
U->>G: move(direction)
G->>G: add_new_tile()
G->>U: draw_grid()
G->>U: draw_score()
G->>U: draw_game_over()
G->>G: is_game_over()
G->>G: get_empty_cells()
G->>G: get_score()
```
### Summary
The code implements the 2048 game using Python classes and data structures. The Pygame library is used for the game interface and user input handling. The `game.py` file contains the `Game` class and related functions for game logic, while the `main.py` file initializes the game and UI.
### TODOs
```python
{
"game.py": "Add handling for no empty cells in add_new_tile function, Update score in move function",
"main.py": "Handle game over condition in the game loop"
}
```

File diff suppressed because it is too large Load diff