From c20ea6c6161717711a836e71d6c63d216a06f61d Mon Sep 17 00:00:00 2001 From: Jens Tirsvad Nielsen Date: Tue, 13 Oct 2026 14:38:50 +0800 Subject: [PATCH] Add the high score file constants Refs #23 Task: MIL-004#1 --- src/snake_game/constants.py | 12 ++++++++++++ tests/test_constants.py | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/src/snake_game/constants.py b/src/snake_game/constants.py index 270d76a..615409e 100644 --- a/src/snake_game/constants.py +++ b/src/snake_game/constants.py @@ -128,3 +128,15 @@ HIGH_SCORE_LABEL: Final[str] = "High Score: " # 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) + +## @brief Name of the text file that keeps the high score between games. +# +# A relative path: the file lies in the working directory the game is started +# from. The file is not tracked by git. +HIGH_SCORE_FILE: Final[str] = "data.txt" + +## @brief Text encoding used to read and write the high score file. +HIGH_SCORE_FILE_ENCODING: Final[str] = "utf-8" + +## @brief The high score of a new game, and of a file that cannot be read. +DEFAULT_HIGH_SCORE: Final[int] = 0 diff --git a/tests/test_constants.py b/tests/test_constants.py index d785adc..49c2b5f 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -164,6 +164,15 @@ def test_high_score_label_follows_the_score_label_as_in_the_lecture() -> None: assert constants.HIGH_SCORE_LABEL != constants.SCORE_LABEL +def test_high_score_is_kept_in_the_text_file_data_txt_as_utf_8() -> None: + assert constants.HIGH_SCORE_FILE == "data.txt" + assert constants.HIGH_SCORE_FILE_ENCODING == "utf-8" + + +def test_the_default_high_score_is_0() -> None: + assert constants.DEFAULT_HIGH_SCORE == 0 + + def test_old_segments_are_parked_outside_the_screen() -> None: x, y = constants.SEGMENT_PARKING_POSITION