summaryrefslogtreecommitdiff
path: root/game/game.py
diff options
context:
space:
mode:
authorAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-01-14 13:07:08 +0200
committerAineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi>2024-01-14 13:07:08 +0200
commit822d89c50a70277186f5c845e4341236548c16b7 (patch)
treef1306919615dc786cf7bc5f913d61ea835b99596 /game/game.py
parent1f9bba90256f0baf605636a93037f1debdcb4623 (diff)
Moving game logic to game/game.py.
Diffstat (limited to 'game/game.py')
-rw-r--r--game/game.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/game/game.py b/game/game.py
new file mode 100644
index 0000000..91c240f
--- /dev/null
+++ b/game/game.py
@@ -0,0 +1,37 @@
+""" game/game.py - pelin etenemiseen liittyvä ohjaus """
+from tui.tui import Action
+
+class Game:
+ """ Game - peli """
+ def __init__(self, board, ui):
+ self.board = board
+ self.ui = ui
+ self.x, self.y = self.ui.game_begin(self.board.size)
+
+
+ def __del__(self):
+ self.board.reveal()
+ self.ui.game_end(self.board.get_view())
+
+
+ def next(self):
+ """ seuraava kiitos vai jotain muuta? """
+ action, self.x, self.y = self.ui.matrix_selector(
+ self.board.get_view(), self.x, self.y
+ )
+ match action:
+ case Action.QUIT:
+ return False
+ case Action.OPEN:
+ if self.board.get_mask(self.x, self.y):
+ if not self.board.make_guess(self.x, self.y):
+ self.ui.game_over(
+ self.board.get_view(), self.x, self.y
+ )
+ return False
+ if self.board.is_winning():
+ self.ui.game_win(self.board.get_view(), self.x, self.y)
+ return False
+ case Action.FLAG:
+ self.board.flag_tile(self.x, self.y)
+ return True