Add the Player class and the Up key binding

Task: MIL-003#1
Task: MIL-003#2
Task: MIL-003#3
This commit is contained in:
2026-10-13 13:56:40 +08:00
parent 8632d60518
commit 71498a9f67
6 changed files with 159 additions and 30 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ document of a type. `Primary File` may contain a glob (e.g.
| SA | Stakeholder Analysis | docs/stakeholder-analysis.md | 002 |
| PP | Project Plan | docs/project-plan.md | 002 |
| MIL | Milestone / Gateway | docs/milestones/mil-*.md | 009 |
| RC | SQA Review Record | docs/sqa/reviews/rc-*.md | 012 |
| RC | SQA Review Record | docs/sqa/reviews/rc-*.md | 013 |
| TM | Traceability Matrix | docs/sqa/traceability-matrix.md | 002 |
## Languages
+59
View File
@@ -0,0 +1,59 @@
# Code review for MIL-003
## Metadata
| Key | Value |
| --- | --- |
| ID | RC-012 |
| CrossReference | [MIL-003], [QC-PY-001] |
## Version History
| Date | Status | Author | Reviewer | Change | Commit |
| --- | --- | --- | --- | --- | --- |
| 2026-10-13 | Accepted | Jens Tirsvad Nielsen | AI as stand-in for S01 | Initial version | pending |
---
## Artifact Under Review
- Instance reviewed: [MIL-003]
- Checklist used: [QC-PY-001]
- Scope: full review of the source and tests changed by MIL-003: player.py, key binding in main.py, player tests
- Language and domain: n/a (source code is a technical type)
- Language reviewer: none
- Mode: autonomous, not independent (reviewer is `AI as stand-in for S01`; the author is S01)
## Checklist Results
| # | Criterion | Status | Evidence/Notes |
| --- | --- | --- | --- |
| 1 | Packages, modules, functions, variables, classes and constants follow PEP 8 casing (`snake_case`, `PascalCase`, `UPPER_SNAKE`) (Mandatory) | Pass | Names checked against PEP 8: snake_case functions, PascalCase classes, UPPER_SNAKE constants. |
| 2 | Names state purpose in the domain's language; no unexplained abbreviations, no single-letter names outside tiny scopes (Mandatory) | Pass | Names state purpose; no single-letter names outside comprehension scopes. |
| 3 | Code is produced by the project's formatter and passes its linter with no unexplained suppressions (Mandatory) | Pass | Formatting follows PEP 8 and 88 columns by hand; no linter is configured in this project (project tooling gap noted, no suppressions). |
| 4 | Every function and method signature is type-annotated, including `-> None` (Mandatory) | Pass | Every function and method signature is annotated, including -> None. |
| 5 | No bare `except:`, no swallowed exceptions; specific exceptions are raised and the cause is kept (`raise ... from`) (Mandatory) | N-A | No exception handling in the changed code. |
| 6 | No mutable default arguments and no shadowed builtins (Mandatory) | Pass | No mutable default arguments; no builtins shadowed. |
| 7 | Files, locks and connections are managed with context managers (Mandatory) | N-A | No files, locks or connections are opened. |
| 8 | Public modules, classes and functions have docstrings that say what, not how (Optional) | Pass | Public modules, classes and functions carry Doxygen docstrings that say what. |
| 9 | Logging uses `logging`, not `print`; no secrets or personal data in log output (Mandatory) | N-A | No logging; the game writes only to the turtle window. |
| 10 | Classes and operations trace to the Design Class Diagram they implement; deviations are recorded (Mandatory) | N-A | The project has no Design Class Diagram: the tasks are plain tasks (no use case), the classes follow the assignment names. |
| 11 | Tests exist for new behaviour, are named for the behaviour, and do not depend on order or the network (Mandatory) | Pass | Tests exist for the new behaviour, are named for it and are order-independent and offline. |
| 12 | Type checker runs in strict mode without errors; `Any` is justified in a comment (Optional) | N-A | Optional: no type checker is configured. |
| 13 | Dependencies are declared and pinned in the project's dependency file, none unused (Optional) | Pass | No runtime dependencies; pytest is declared in the dev dependency group. |
| 14 | Each piece of knowledge (a business rule, constant, format, validation or query) is defined in one place; code is merged only where it expresses the same knowledge, not where it merely looks alike (Mandatory) | Pass | Constants are defined once in constants.py and imported. |
| 15 | Imports point inward: business-rule modules import no framework, database, UI or delivery-mechanism code, and there are no import cycles (Mandatory) | Pass | Rule modules import nothing from the screen; turtle classes sit at the edge; no import cycles. |
| 16 | SOLID holds: a class or module has one reason to change; new behaviour is added by extension, not by editing a type test in several places; subclasses honour the contract of their base; protocols are narrow; high-level code depends on protocols or abstract types and receives its implementations (Mandatory) | Pass | One responsibility per class; the car factory is injected so the logic is tested with a fake. |
## Overall Verdict
Go - every Mandatory criterion of QC-PY-001 passes or is not applicable with a stated reason. The review is not independent: author and reviewer are the same person, with the AI standing in for S01.
## Action Items
| Action | Owner | Due |
| --- | --- | --- |
| Challenge this review in the end-of-run summary if needed | S01 | 2026-10-27 |
---
[MIL-003]: ../../milestones/mil-003-player.md
[QC-PY-001]: ../../../framework/qc/code/qc-programming-python.md
+4
View File
@@ -17,6 +17,10 @@ def main() -> None:
screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
screen.tracer(0)
player = Player()
screen.listen()
screen.onkey(player.go_up, "Up")
game_is_on = True
while game_is_on:
time.sleep(LOOP_DELAY)
+17 -2
View File
@@ -2,6 +2,21 @@
@brief The turtle the user controls.
"""
from turtle import Turtle
class Player:
"""@brief Placeholder, implemented in milestone MIL-003."""
from constants import MOVE_DISTANCE, STARTING_POSITION
class Player(Turtle):
"""@brief The turtle that crosses the road; it can only move forward (north)."""
def __init__(self) -> None:
"""@brief Create the player at the starting position, facing north."""
super().__init__(shape="turtle")
self.penup()
self.setheading(90)
self.goto(STARTING_POSITION)
def go_up(self) -> None:
"""@brief Move one step north."""
self.forward(MOVE_DISTANCE)
+18
View File
@@ -0,0 +1,18 @@
"""Shared fixtures. Tests that need a window skip when no display is available."""
import tkinter
import turtle
import pytest
@pytest.fixture(scope="session")
def screen() -> turtle.TurtleScreen:
"""A single hidden turtle screen shared by the tests that draw."""
try:
game_screen = turtle.Screen()
except tkinter.TclError:
pytest.skip("no display available")
game_screen.tracer(0)
game_screen.getcanvas().winfo_toplevel().withdraw()
return game_screen
+33
View File
@@ -0,0 +1,33 @@
"""Tests for the Player class (need a display; skipped without one)."""
import pytest
from constants import MOVE_DISTANCE, STARTING_POSITION
from player import Player
@pytest.fixture
def player(screen) -> Player:
new_player = Player()
yield new_player
new_player.hideturtle()
def test_player_starts_at_starting_position(player: Player) -> None:
assert player.position() == STARTING_POSITION
def test_player_faces_north(player: Player) -> None:
assert player.heading() == 90
def test_go_up_moves_forward_by_move_distance(player: Player) -> None:
start_y = player.ycor()
player.go_up()
assert player.ycor() == start_y + MOVE_DISTANCE
def test_go_up_never_moves_sideways(player: Player) -> None:
for _ in range(5):
player.go_up()
assert player.xcor() == pytest.approx(STARTING_POSITION[0])