From f502b21183d307fcab9b353aa18609d15c3547f1 Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Thu, 28 Mar 2024 13:54:00 +0200 Subject: hiscores: loading, saving, screen --- src/sliceitoff/hiscores/__init__.py | 1 + src/sliceitoff/hiscores/hiscores.py | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/sliceitoff/hiscores/__init__.py create mode 100644 src/sliceitoff/hiscores/hiscores.py (limited to 'src/sliceitoff/hiscores') diff --git a/src/sliceitoff/hiscores/__init__.py b/src/sliceitoff/hiscores/__init__.py new file mode 100644 index 0000000..f3d7811 --- /dev/null +++ b/src/sliceitoff/hiscores/__init__.py @@ -0,0 +1 @@ +from .hiscores import HiScores diff --git a/src/sliceitoff/hiscores/hiscores.py b/src/sliceitoff/hiscores/hiscores.py new file mode 100644 index 0000000..098f0e3 --- /dev/null +++ b/src/sliceitoff/hiscores/hiscores.py @@ -0,0 +1,55 @@ +import os + +MAX_HIGHSCORES = 20 + +class HiScores: + def __init__(self): + self.table=[] + self.config_filename = os.path.join( + os.getenv('HOME'), + ".config", + "sliceitoffrc") + if not os.path.isfile(self.config_filename): + self.table=[(0,"") for _ in range(MAX_HIGHSCORES)] + return + with open(self.config_filename, "r") as config_file: + for line in config_file: + option, value = line.split('=') + if option == 'hiscore': + score, name = value.split('!') + self.add(int(score.strip()),name.strip()) + if len(self.table)