summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-31 13:56:46 +0300
committerViljami Ilola <+@hix.fi>2024-03-31 13:56:46 +0300
commit551289aa0d40b80e8c2f8e6e732dbfc8b03e5e96 (patch)
treee5ed0fc3e0119304df5dce4dbbcbf7dab1cc3f46
parent20b23c0cd4cf613a2634cc57bf6f2430cc9fc364 (diff)
mainloop
-rw-r--r--src/sliceitoff/game/game.py23
-rw-r--r--src/sliceitoff/mainmenu/__init__.py2
-rw-r--r--src/sliceitoff/mainmenu/mainmenu.py4
3 files changed, 18 insertions, 11 deletions
diff --git a/src/sliceitoff/game/game.py b/src/sliceitoff/game/game.py
index 18c47b2..fea5151 100644
--- a/src/sliceitoff/game/game.py
+++ b/src/sliceitoff/game/game.py
@@ -11,7 +11,7 @@ from text import Fonts
from stats import Stats
from screens import welcome_screen, hiscores_screen
from hiscores import HiScores
-from mainmenu import Mainmenu
+from mainmenu import Mainmenu, MenuItems
from .level import Level
from .show import Show
@@ -73,10 +73,17 @@ class Game:
return menu.selection
def run(self):
- """ This is the main loop of the game (not loop at the moment) """
- self.mainmenu()
- self.welcome()
- self.newgame()
- if self.hiscores.high_enough(self.stats.score):
- self.hiscores.add( self.stats.score, self.initials())
- self.show_highscores()
+ """ This is the main loop of the game """
+ while True:
+ match self.mainmenu():
+ case MenuItems.QUIT:
+ break
+ case MenuItems.HISCORES:
+ self.show_highscores()
+ case MenuItems.INSTRUCT:
+ self.welcome()
+ case MenuItems.NEWGAME:
+ self.newgame()
+ if self.hiscores.high_enough(self.stats.score):
+ self.hiscores.add( self.stats.score, self.initials())
+ self.show_highscores()
diff --git a/src/sliceitoff/mainmenu/__init__.py b/src/sliceitoff/mainmenu/__init__.py
index 3dd1fe3..9259d1f 100644
--- a/src/sliceitoff/mainmenu/__init__.py
+++ b/src/sliceitoff/mainmenu/__init__.py
@@ -1,2 +1,2 @@
""" mainmenu - Menu where user can new game, quit etc """
-from .mainmenu import Mainmenu
+from .mainmenu import Mainmenu, MenuItems
diff --git a/src/sliceitoff/mainmenu/mainmenu.py b/src/sliceitoff/mainmenu/mainmenu.py
index c907443..e0466a5 100644
--- a/src/sliceitoff/mainmenu/mainmenu.py
+++ b/src/sliceitoff/mainmenu/mainmenu.py
@@ -1,12 +1,12 @@
""" mainmenu.mainmenu - Let's user choose """
-from enum import Enum
+from enum import IntEnum
import pygame
from screens import mainmenu_screen
from game.anykey import anykey
-class MenuItems(Enum):
+class MenuItems(IntEnum):
""" Items in the menu. Should match mainmenu_screen """
NEWGAME = 0
HISCORES = 1