MIL-003: Continuous play and high score #37
@@ -117,8 +117,14 @@ SCOREBOARD_FONT: Final[tuple[str, int, str]] = ("Arial", 24, "normal")
|
|||||||
## @brief The head touches the tail when it is closer to a segment than this, in pixels.
|
## @brief The head touches the tail when it is closer to a segment than this, in pixels.
|
||||||
TAIL_COLLISION_DISTANCE: Final[int] = 10
|
TAIL_COLLISION_DISTANCE: Final[int] = 10
|
||||||
|
|
||||||
## @brief Text shown when the game is over.
|
## @brief Text in front of the high score on the scoreboard.
|
||||||
GAME_OVER_TEXT: Final[str] = "GAME OVER"
|
#
|
||||||
|
# The scoreboard writes `Score: <score> High Score: <high_score>`: the score
|
||||||
|
# label, the score, a space, this label and the high score.
|
||||||
|
HIGH_SCORE_LABEL: Final[str] = "High Score: "
|
||||||
|
|
||||||
## @brief Where the game-over text is written: the centre of the screen.
|
## @brief Where a segment of the old snake is sent when the snake is reset.
|
||||||
GAME_OVER_POSITION: Final[tuple[int, int]] = (0, 0)
|
#
|
||||||
|
# The place is far outside the 600 by 600 screen, so the old segments are out
|
||||||
|
# of sight, as the day-24 lecture does it.
|
||||||
|
SEGMENT_PARKING_POSITION: Final[tuple[int, int]] = (1000, 1000)
|
||||||
|
|||||||
+14
-6
@@ -154,10 +154,18 @@ def test_tail_is_touched_closer_than_10_pixels_which_is_less_than_a_move() -> No
|
|||||||
assert 0 < constants.TAIL_COLLISION_DISTANCE < constants.MOVE_DISTANCE
|
assert 0 < constants.TAIL_COLLISION_DISTANCE < constants.MOVE_DISTANCE
|
||||||
|
|
||||||
|
|
||||||
def test_game_over_text_is_written_at_the_centre_inside_the_wall() -> None:
|
def test_game_over_constants_no_longer_exist() -> None:
|
||||||
x, y = constants.GAME_OVER_POSITION
|
assert not hasattr(constants, "GAME_OVER_TEXT")
|
||||||
|
assert not hasattr(constants, "GAME_OVER_POSITION")
|
||||||
|
|
||||||
assert constants.GAME_OVER_TEXT == "GAME OVER"
|
|
||||||
assert (x, y) == (0, 0)
|
def test_high_score_label_follows_the_score_label_as_in_the_lecture() -> None:
|
||||||
assert abs(x) < constants.WALL_LIMIT
|
assert constants.HIGH_SCORE_LABEL == "High Score: "
|
||||||
assert abs(y) < constants.WALL_LIMIT
|
assert constants.HIGH_SCORE_LABEL != constants.SCORE_LABEL
|
||||||
|
|
||||||
|
|
||||||
|
def test_old_segments_are_parked_outside_the_screen() -> None:
|
||||||
|
x, y = constants.SEGMENT_PARKING_POSITION
|
||||||
|
|
||||||
|
assert abs(x) > HALF_WIDTH
|
||||||
|
assert abs(y) > HALF_HEIGHT
|
||||||
|
|||||||
Reference in New Issue
Block a user