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#