Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2a622c7ed2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
pacman_game.py
Outdated
| def on_key(self, event: tk.Event): | ||
| if self.game_over: | ||
| if event.keysym.lower() == "r": | ||
| self.__init__(self.root) |
There was a problem hiding this comment.
Cancel existing tick timer before restarting game
Pressing R in the game-over state calls __init__ on the same instance, but the previous after chain created in loop() is never canceled and loop() always re-schedules itself even when game_over is true. After each restart, another timer chain keeps running, so updates execute multiple times per tick and the game speed/collision behavior becomes increasingly incorrect.
Useful? React with 👍 / 👎.
| self.player.direction = (0, 0) | ||
| self.pending_direction = (0, 0) | ||
|
|
||
| self.canvas = tk.Canvas( |
There was a problem hiding this comment.
Destroy or reuse the canvas when handling restart
Because restart re-enters __init__ on the existing window, this line creates a fresh Canvas each time and pack() adds it to the UI without removing the previous one. Repeating win/loss + restart cycles will stack canvases and grow resource usage/window layout unexpectedly instead of resetting the same board.
Useful? React with 👍 / 👎.
Motivation
tkinterfor easy running and learning.Description
pacman_game.pyimplementing the game loop, a fixedMAP_LAYOUT, anEntitydataclass, player input handling, pellet and power-pellet scoring, ghost AI that chases or flees, collision handling, lives, win/lose states, and restart support.README.mdwith quick-start instructions and controls showing how to run the game withpython3 pacman_game.py.CELL_SIZEon atk.Canvasand expose atick_rate_msfor game pacing.Testing
python3 -m py_compile pacman_game.pywhich succeeded.python3 -m py_compile pacman_game.py README.mdwhich failed becauseREADME.mdis not a Python file, as expected.Codex Task