From 16fe3639ed8190361d4505f075ff5689ef569f5e Mon Sep 17 00:00:00 2001 From: Chrissi Date: Thu, 11 Jun 2026 14:02:49 +0200 Subject: [PATCH] A9 Fertig --- .vscode/settings.json | 3 +++ A9/arbeitsblatt9.pdf | Bin A9/highscores.txt | 7 +++---- A9/ohm.png | Bin A9/pong-oo-highscore-aufgabe.py | 27 +++++++++++++++++++++++++-- README.md | 0 highscores.txt | 3 +++ 7 files changed, 34 insertions(+), 6 deletions(-) create mode 100755 .vscode/settings.json mode change 100644 => 100755 A9/arbeitsblatt9.pdf mode change 100644 => 100755 A9/highscores.txt mode change 100644 => 100755 A9/ohm.png mode change 100644 => 100755 A9/pong-oo-highscore-aufgabe.py mode change 100644 => 100755 README.md create mode 100755 highscores.txt diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100755 index 0000000..d84f211 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python-envs.defaultEnvManager": "ms-python.python:system" +} \ No newline at end of file diff --git a/A9/arbeitsblatt9.pdf b/A9/arbeitsblatt9.pdf old mode 100644 new mode 100755 diff --git a/A9/highscores.txt b/A9/highscores.txt old mode 100644 new mode 100755 index b853003..4fe7e44 --- a/A9/highscores.txt +++ b/A9/highscores.txt @@ -1,6 +1,5 @@ -30#2020-06-11 18:34:26# -20#2020-06-11 19:08:10# -10#2020-06-11 19:08:21# -0#2020-06-11 19:11:14# +1230#2026-06-09 22:33:50# 70#2020-06-11 19:08:56# 50#2020-06-11 19:09:25# +30#2020-06-11 18:34:26# +20#2026-06-11 09:54:46# diff --git a/A9/ohm.png b/A9/ohm.png old mode 100644 new mode 100755 diff --git a/A9/pong-oo-highscore-aufgabe.py b/A9/pong-oo-highscore-aufgabe.py old mode 100644 new mode 100755 index dfc72b0..3380906 --- a/A9/pong-oo-highscore-aufgabe.py +++ b/A9/pong-oo-highscore-aufgabe.py @@ -105,14 +105,37 @@ class Highscore(GameObject): self.scores = {} self.last_score = None - ### TODO: Hier müssen die Highscores eingelesen werden + ##Falls es noch keine Highscore.txt gibt## + # try: + # with open("A9/highscores.txt", "r") as file: + # for line in file: + # parts = line.split("#") + # score = int(parts[0]) + # time = parts[1] + # self.scores[score] = time + # except: + # pass + + with open("A9/highscores.txt", "r") as file: + for line in file: + parts = line.split("#") + score = int(parts[0]) + time = parts[1] + self.scores[score] = time + def signal_is_over(self, game_objects): self.last_score = game_objects[OBJ_COUNTER].counter self.scores[self.last_score] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - ### TODO: Hier müssen die Highscores gesichert werden + with open("A9/highscores.txt", "w") as file: + sorted_scores = sorted(self.scores.keys()) + sorted_scores.reverse() + + for score in sorted_scores[:5]: + time = self.scores[score] + file.write(f"{score}#{time}#\n") self.visible = True diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/highscores.txt b/highscores.txt new file mode 100755 index 0000000..8d07b6f --- /dev/null +++ b/highscores.txt @@ -0,0 +1,3 @@ +30#2026-06-09 22:30:54# +10#2026-06-09 22:31:03# +0#2026-06-09 22:31:09#