Merge pull request 'Fix cars drawn vertically' (#36) from fix-car-orientation into main
This commit was merged in pull request #36.
This commit is contained in:
@@ -5,6 +5,8 @@ Complete Python Pro Bootcamp*. Steer the turtle north across a busy road of
|
||||
randomly generated cars. Each crossing raises the level and the car speed; one
|
||||
collision ends the game. Written with the Python standard library only.
|
||||
|
||||

|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.13 or newer, with `tkinter` (the `turtle` module needs it).
|
||||
@@ -71,6 +73,8 @@ Press the **Up** arrow key to move the turtle forward. Reaching the top edge
|
||||
returns the turtle to the start and speeds up the cars. A collision shows
|
||||
`GAME OVER`; click the window to close it.
|
||||
|
||||

|
||||
|
||||
## Run the tests
|
||||
|
||||
With the `.venv` active:
|
||||
@@ -112,6 +116,7 @@ Open `docs/api/html/index.html` in a browser.
|
||||
│ └── scoreboard.py Scoreboard
|
||||
├── tests/ pytest tests
|
||||
├── docs/ planning and review documents (business case, plan, milestones, reviews)
|
||||
│ └── images/ screenshots used by the README and the wiki
|
||||
├── wiki/ wiki pages in English, Danish (-da) and Bahasa Malaysia (-ms)
|
||||
├── Doxyfile Doxygen configuration
|
||||
├── pyproject.toml project configuration and development dependencies
|
||||
|
||||
@@ -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 | 016 |
|
||||
| RC | SQA Review Record | docs/sqa/reviews/rc-*.md | 017 |
|
||||
| TM | Traceability Matrix | docs/sqa/traceability-matrix.md | 002 |
|
||||
|
||||
## Languages
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,60 @@
|
||||
# Code review for MIL-004
|
||||
|
||||
## Metadata
|
||||
| Key | Value |
|
||||
| --- | --- |
|
||||
| ID | RC-016 |
|
||||
| CrossReference | [MIL-004], [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 | [3d51354] |
|
||||
|
||||
---
|
||||
|
||||
## Artifact Under Review
|
||||
|
||||
- Instance reviewed: [MIL-004]
|
||||
- Checklist used: [QC-PY-001]
|
||||
- Scope: full review of the source and tests changed by MIL-004: car_shape.py orientation fix (to_shape_frame) and its 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 | The orientation bug was reproduced by a display test that fails without the fix and passes with it. |
|
||||
| 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-004]: ../../milestones/mil-004-cars.md
|
||||
[QC-PY-001]: ../../../framework/qc/code/qc-programming-python.md
|
||||
[3d51354]: https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/023-turtle-crossing/commit/3d51354d46663954dc481989c1ab31b348cca6dc
|
||||
+22
-1
@@ -4,6 +4,12 @@
|
||||
A car is a compound turtle shape inside a 40 x 20 pixel footprint, front to the
|
||||
left: lower body, cabin, two windows, a headlight and two wheels. The geometry
|
||||
is plain data (see car_components) so it can be tested without a display.
|
||||
|
||||
Shape frame: car_components works in screen coordinates (x along the car, front
|
||||
at -x). A turtle shape, however, is defined pointing up (forward is +y) and is
|
||||
rotated by the turtle's heading, so at heading 0 (east) it is turned clockwise
|
||||
by 90 degrees. to_shape_frame converts the points when the shapes are
|
||||
registered, so a car at heading 0 lies along x and drives to the left.
|
||||
"""
|
||||
|
||||
from turtle import Shape, TurtleScreen
|
||||
@@ -74,6 +80,19 @@ def car_components(color: str) -> list[Component]:
|
||||
]
|
||||
|
||||
|
||||
def to_shape_frame(point: tuple[float, float]) -> tuple[float, float]:
|
||||
"""@brief Convert a screen-coordinate point to the turtle shape's own frame.
|
||||
|
||||
A shape's forward direction is +y and heading 0 turns it clockwise by 90
|
||||
degrees, so the screen point (x, y) must be registered as (-y, x).
|
||||
|
||||
@param point A point (x, y) in screen coordinates at heading 0.
|
||||
@return The same point in the shape's frame.
|
||||
"""
|
||||
x, y = point
|
||||
return (-y, x)
|
||||
|
||||
|
||||
def register_car_shapes(screen: TurtleScreen) -> None:
|
||||
"""@brief Register one car shape per colour with the screen.
|
||||
|
||||
@@ -82,5 +101,7 @@ def register_car_shapes(screen: TurtleScreen) -> None:
|
||||
for color in COLORS:
|
||||
shape = Shape("compound")
|
||||
for polygon, fill, outline in car_components(color):
|
||||
shape.addcomponent(polygon, fill, outline)
|
||||
shape.addcomponent(
|
||||
tuple(to_shape_frame(point) for point in polygon), fill, outline
|
||||
)
|
||||
screen.register_shape(shape_name(color), shape)
|
||||
|
||||
+34
-2
@@ -1,8 +1,13 @@
|
||||
"""Tests for the car drawing."""
|
||||
|
||||
from turtle import TurtleScreen
|
||||
from turtle import Turtle, TurtleScreen
|
||||
|
||||
from car_shape import car_components, register_car_shapes, shape_name
|
||||
from car_shape import (
|
||||
car_components,
|
||||
register_car_shapes,
|
||||
shape_name,
|
||||
to_shape_frame,
|
||||
)
|
||||
from constants import CAR_HEIGHT, CAR_LENGTH, COLORS
|
||||
|
||||
|
||||
@@ -28,3 +33,30 @@ def test_body_and_cabin_use_the_car_colour() -> 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)
|
||||
|
||||
|
||||
def test_to_shape_frame_maps_screen_points_to_the_upright_shape_frame() -> None:
|
||||
assert to_shape_frame((-20, 0)) == (0, -20) # front (screen left) -> shape -y
|
||||
assert to_shape_frame((20, 0)) == (0, 20)
|
||||
assert to_shape_frame((0, 10)) == (-10, 0)
|
||||
assert to_shape_frame((0, 0)) == (0, 0)
|
||||
|
||||
|
||||
def test_drawn_car_is_horizontal(screen: TurtleScreen) -> None:
|
||||
register_car_shapes(screen)
|
||||
car = Turtle(visible=False)
|
||||
car.penup()
|
||||
car.shape(shape_name("red"))
|
||||
car.showturtle()
|
||||
try:
|
||||
screen.update()
|
||||
canvas = screen.getcanvas()
|
||||
# the first compound component is the lower body
|
||||
coords = canvas.coords(car.turtle._item[0]) # type: ignore[attr-defined]
|
||||
xs, ys = coords[0::2], coords[1::2]
|
||||
width, height = max(xs) - min(xs), max(ys) - min(ys)
|
||||
assert width > height
|
||||
assert width <= CAR_LENGTH
|
||||
assert height <= CAR_HEIGHT
|
||||
finally:
|
||||
car.hideturtle()
|
||||
|
||||
@@ -6,6 +6,8 @@ Dag 23 i Udemys *100 Days of Code: The Complete Python Pro Bootcamp*: et spil i
|
||||
Crossy Road-stil. Styr en skildpadde mod nord over en travl vej. Hver
|
||||
krydsning gør bilerne hurtigere; ét sammenstød afslutter spillet.
|
||||
|
||||

|
||||
|
||||
| Side | Læs den, når du vil |
|
||||
| --- | --- |
|
||||
| [Installation](Install-da) | Klone repositoryet, oprette `.venv` og køre spillet og testene |
|
||||
|
||||
@@ -7,6 +7,8 @@ permainan gaya Crossy Road. Pandu seekor penyu ke utara merentasi jalan yang
|
||||
sibuk. Setiap kali berjaya melintas, kereta menjadi lebih laju; satu perlanggaran
|
||||
menamatkan permainan.
|
||||
|
||||

|
||||
|
||||
| Halaman | Baca apabila anda mahu |
|
||||
| --- | --- |
|
||||
| [Pemasangan](Install-ms) | Klon repositori, cipta `.venv` dan jalankan permainan serta ujian |
|
||||
|
||||
@@ -6,6 +6,8 @@ Day 23 of Udemy's *100 Days of Code: The Complete Python Pro Bootcamp*: a
|
||||
Crossy Road style game. Steer a turtle north across a busy road. Every
|
||||
crossing makes the cars faster; one collision ends the game.
|
||||
|
||||

|
||||
|
||||
| Page | Read it when you want to |
|
||||
| --- | --- |
|
||||
| [Install](Install) | Clone the repository, create the `.venv` and run the game and the tests |
|
||||
|
||||
@@ -23,4 +23,8 @@
|
||||
- Hvert niveau lægger det samme hastighedstrin til, så senere niveauer kræver
|
||||
hurtige, korte træk.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Tilbage til [Forside](Home-da).
|
||||
|
||||
@@ -23,4 +23,8 @@
|
||||
- Setiap tahap menambah langkah kelajuan yang sama, jadi tahap lebih tinggi
|
||||
memerlukan gerakan pantas dan pendek.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Kembali ke [Laman utama](Home-ms).
|
||||
|
||||
@@ -22,4 +22,8 @@
|
||||
- Wait for a gap: a new car is created on about one frame in six.
|
||||
- Every level adds the same speed step, so later levels need quick, short moves.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Back to [Home](Home).
|
||||
|
||||
Reference in New Issue
Block a user