diff --git a/docs/artifact-registry.md b/docs/artifact-registry.md index 9ad9b27..734f527 100644 --- a/docs/artifact-registry.md +++ b/docs/artifact-registry.md @@ -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 | 015 | +| RC | SQA Review Record | docs/sqa/reviews/rc-*.md | 016 | | TM | Traceability Matrix | docs/sqa/traceability-matrix.md | 002 | ## Languages diff --git a/docs/sqa/reviews/rc-015-mil-006-code.md b/docs/sqa/reviews/rc-015-mil-006-code.md new file mode 100644 index 0000000..6bcbec0 --- /dev/null +++ b/docs/sqa/reviews/rc-015-mil-006-code.md @@ -0,0 +1,59 @@ +# Code review for MIL-006 + +## Metadata +| Key | Value | +| --- | --- | +| ID | RC-015 | +| CrossReference | [MIL-006], [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-006] +- Checklist used: [QC-PY-001] +- Scope: full review of the source and tests changed by MIL-006: scoreboard.py, game over and level hooks in main.py, scoreboard tests, annotation fixes in 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-006]: ../../milestones/mil-006-scoreboard.md +[QC-PY-001]: ../../../framework/qc/code/qc-programming-python.md diff --git a/src/constants.py b/src/constants.py index a15bd06..80a778d 100644 --- a/src/constants.py +++ b/src/constants.py @@ -43,3 +43,6 @@ CAR_LIGHT_COLOR = "gold" FONT = ("Courier", 24, "normal") SCOREBOARD_POSITION = (-280, 250) GAME_OVER_TEXT = "GAME OVER" +GAME_OVER_POSITION = (0, 0) +STARTING_LEVEL = 1 +LEVEL_TEXT_PREFIX = "Level: " diff --git a/src/main.py b/src/main.py index 5e6260e..00883be 100644 --- a/src/main.py +++ b/src/main.py @@ -21,6 +21,7 @@ def main() -> None: player = Player() car_manager = CarManager() + scoreboard = Scoreboard() screen.listen() screen.onkey(player.go_up, "Up") @@ -33,11 +34,14 @@ def main() -> None: if car_manager.is_hit(player): game_is_on = False + scoreboard.game_over() if player.is_at_finish_line(): player.go_to_start() car_manager.level_up() + scoreboard.increase_level() + screen.update() screen.exitonclick() diff --git a/src/scoreboard.py b/src/scoreboard.py index dfaba0d..c034cfc 100644 --- a/src/scoreboard.py +++ b/src/scoreboard.py @@ -2,6 +2,47 @@ @brief Shows the level and the game over message. """ +from turtle import Turtle -class Scoreboard: - """@brief Placeholder, implemented in milestone MIL-006.""" +from constants import ( + FONT, + GAME_OVER_POSITION, + GAME_OVER_TEXT, + LEVEL_TEXT_PREFIX, + SCOREBOARD_POSITION, + STARTING_LEVEL, +) + + +class Scoreboard(Turtle): + """@brief Writes the current level and the game over message.""" + + def __init__(self) -> None: + """@brief Create the scoreboard and write level 1.""" + super().__init__() + self.hideturtle() + self.penup() + self.color("black") + self.level = STARTING_LEVEL + self.update_scoreboard() + + @property + def level_text(self) -> str: + """@brief The text shown for the current level.""" + return f"{LEVEL_TEXT_PREFIX}{self.level}" + + def update_scoreboard(self) -> None: + """@brief Clear the board and write the current level.""" + self.clear() + self.goto(SCOREBOARD_POSITION) + self.write(self.level_text, align="left", font=FONT) + + def increase_level(self) -> None: + """@brief Go up one level and redraw the board.""" + self.level += 1 + self.update_scoreboard() + + def game_over(self) -> None: + """@brief Write the game over message in the middle of the screen.""" + self.goto(GAME_OVER_POSITION) + self.write(GAME_OVER_TEXT, align="center", font=FONT) diff --git a/tests/test_car_shape.py b/tests/test_car_shape.py index 1c03816..c065542 100644 --- a/tests/test_car_shape.py +++ b/tests/test_car_shape.py @@ -1,5 +1,7 @@ """Tests for the car drawing.""" +from turtle import TurtleScreen + from car_shape import car_components, register_car_shapes, shape_name from constants import CAR_HEIGHT, CAR_LENGTH, COLORS @@ -23,6 +25,6 @@ def test_body_and_cabin_use_the_car_colour() -> None: assert fills.count("green") == 2 -def test_register_car_shapes_adds_one_shape_per_colour(screen) -> None: +def test_register_car_shapes_adds_one_shape_per_colour(screen: TurtleScreen) -> None: register_car_shapes(screen) assert all(shape_name(color) in screen.getshapes() for color in COLORS) diff --git a/tests/test_player.py b/tests/test_player.py index fde758e..8b3d33d 100644 --- a/tests/test_player.py +++ b/tests/test_player.py @@ -1,48 +1,50 @@ -"""Tests for the Player class (need a display; skipped without one).""" - -import pytest - -from constants import FINISH_LINE_Y, 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_player_is_not_at_finish_line_at_start(player: Player) -> None: - assert not player.is_at_finish_line() - - -def test_player_is_at_finish_line_above_finish_y(player: Player) -> None: - player.goto(0, FINISH_LINE_Y + 1) - assert player.is_at_finish_line() - - -def test_go_to_start_returns_to_starting_position(player: Player) -> None: - player.goto(0, FINISH_LINE_Y + 1) - player.go_to_start() - assert player.position() == STARTING_POSITION - - -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]) +"""Tests for the Player class (need a display; skipped without one).""" + +from turtle import TurtleScreen + +import pytest + +from constants import FINISH_LINE_Y, MOVE_DISTANCE, STARTING_POSITION +from player import Player + + +@pytest.fixture +def player(screen: TurtleScreen) -> 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_player_is_not_at_finish_line_at_start(player: Player) -> None: + assert not player.is_at_finish_line() + + +def test_player_is_at_finish_line_above_finish_y(player: Player) -> None: + player.goto(0, FINISH_LINE_Y + 1) + assert player.is_at_finish_line() + + +def test_go_to_start_returns_to_starting_position(player: Player) -> None: + player.goto(0, FINISH_LINE_Y + 1) + player.go_to_start() + assert player.position() == STARTING_POSITION + + +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]) diff --git a/tests/test_scoreboard.py b/tests/test_scoreboard.py new file mode 100644 index 0000000..0ee93e3 --- /dev/null +++ b/tests/test_scoreboard.py @@ -0,0 +1,36 @@ +"""@file test_scoreboard.py +@brief Tests for the Scoreboard. +""" + +from turtle import TurtleScreen + +from scoreboard import Scoreboard + + +def test_level_starts_at_one(screen: TurtleScreen) -> None: + assert Scoreboard().level == 1 + + +def test_level_text_shows_level_one_at_start(screen: TurtleScreen) -> None: + assert Scoreboard().level_text == "Level: 1" + + +def test_level_text_follows_level() -> None: + board = Scoreboard.__new__(Scoreboard) + board.level = 7 + assert board.level_text == "Level: 7" + + +def test_increase_level_adds_one(screen: TurtleScreen) -> None: + board = Scoreboard() + board.increase_level() + assert board.level == 2 + assert board.level_text == "Level: 2" + + +def test_game_over_keeps_level(screen: TurtleScreen) -> None: + board = Scoreboard() + board.increase_level() + board.game_over() + assert board.level == 2 + assert board.position() == (0, 0)