diff options
author | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-30 09:08:20 +0200 |
---|---|---|
committer | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-30 09:08:20 +0200 |
commit | 70df24894d1cb0f2897442c64a3b7e460ed6ff78 (patch) | |
tree | a73bd3554e6ad42b8c91c6e5aed7a224ad4118d8 | |
parent | db3fd859e42fb3d6b3c1f98473b54e91d78b74e7 (diff) |
Adding level-info on statusline.
-rw-r--r-- | app.py | 1 | ||||
-rw-r--r-- | board/board.py | 44 | ||||
-rw-r--r-- | board/static.py | 6 | ||||
-rw-r--r-- | tests/test_board.py | 6 | ||||
-rw-r--r-- | tui/ansi_draw.py | 4 | ||||
-rw-r--r-- | tui/tui.py | 6 |
6 files changed, 39 insertions, 28 deletions
@@ -29,6 +29,7 @@ class App: tui_opts['height'] = LevelSpecs[board_opts['level']][1] self.board = Board(**board_opts) + tui_opts['level_name']=self.board.get_level_name() self.ui = Tui(**tui_opts) self.game = Game(self.board,self.ui) diff --git a/board/board.py b/board/board.py index 625e670..8fc1f3a 100644 --- a/board/board.py +++ b/board/board.py @@ -10,23 +10,34 @@ class Board(): """ Board - Luokka joka pitää huolen pelilaudasta ja siihen kohdistuvista siirroista. """ - def __init__(self, **opts): - - self.__level = opts["level"] if "level" in opts else Level.BEGINNER - self.__width, self.__height, self.__bombs = LevelSpecs[self.__level] - - self.__width = opts["width"] if "width" in opts else self.__width - self.__height = opts["height"] if "height" in opts else self.__height - self.__bombs = opts["bombs"] if "bombs" in opts else self.__bombs - - if self.__width not in range(2,51): - self.__width = LevelSpecs[self.__level][0] - if self.__height not in range(2,51): - self.__height = LevelSpecs[self.__level][0] + def __init__(self, + level = Level.BEGINNER, + width = None, + height = None, + bombs = None): + + self.__level = level + self.__width, self.__height, self.__bombs =LevelSpecs[self.__level][:3] + + if width and width in range(2,51): + self.__width = width + if height and height in range(2,51): + self.__height = width + if bombs: + self.__bombs = bombs if self.__bombs not in range(1,self.__width*self.__height): self.__bombs = self.__width + if ( (self.__width, self.__height, self.__bombs) + == LevelSpecs[self.__level][:3] ): + self.__level_name = LevelSpecs[self.__level][3] + else: + self.__level_name = "Mukautettu" + + self.__level_name += ( f" ({self.__width}x{self.__height}" + f", {self.__bombs} miinaa)" ) + self.__tiles = None self.__masked = None self.__initialize_tiles() @@ -191,7 +202,6 @@ class Board(): """ palauttaa pommien määrän """ return self.__bombs - def get_level(self): - """ palauttaa vaikesutason """ - return self.__level if (self.__width, self.__height, self.__bombs) \ - == LevelSpecs[self.__level] else None + def get_level_name(self): + """ palauttaa vaikesutason nimen""" + return self.__level_name diff --git a/board/static.py b/board/static.py index d6b48dd..5d4b4ba 100644 --- a/board/static.py +++ b/board/static.py @@ -28,7 +28,7 @@ class Tile(IntEnum): LevelSpecs = { - Level.BEGINNER: ( 9, 9, 10 ), - Level.INTERMEDIATE: ( 16, 16, 40 ), - Level.EXPERT: ( 30, 16, 99 ) + Level.BEGINNER: ( 9, 9, 10, "Aloittelija"), + Level.INTERMEDIATE: ( 16, 16, 40, "Keskivaikea"), + Level.EXPERT: ( 30, 16, 99, "Edistynyt") } diff --git a/tests/test_board.py b/tests/test_board.py index 904f73a..7b0d1fd 100644 --- a/tests/test_board.py +++ b/tests/test_board.py @@ -108,6 +108,6 @@ class TestBoardClass(unittest.TestCase): def test_get_level(self): """ Testataan että nykyinen vaikeustaso palautuu oikein """ b = Board(level=Level.INTERMEDIATE) - self.assertEqual(b.get_level(), Level.INTERMEDIATE) - b = Board(level=Level.INTERMEDIATE, width=25) - self.assertEqual(b.get_level(), None) + self.assertIn(LevelSpecs[Level.INTERMEDIATE][3], b.get_level_name()) + b = Board(level=Level.INTERMEDIATE, width=25, bombs=2) + self.assertIn("Mukautettu", b.get_level_name()) diff --git a/tui/ansi_draw.py b/tui/ansi_draw.py index dd304d0..143874d 100644 --- a/tui/ansi_draw.py +++ b/tui/ansi_draw.py @@ -5,8 +5,8 @@ from .static import TileTypes class AnsiDraw(): """ AnsiDraw - "piirtelee" näytölle kirjailmilla """ - def __init__(self, height = 15): - print(end="\n"*height) + def __init__(self, height = 9, name = ""): + print(end='\n'*height+name+": Peli alkaa.") def __del__(self): print() @@ -42,7 +42,7 @@ class Tui(): if self.suppress: self.draw = SuppressDraw() else: - self.draw = AnsiDraw(height=self.height) + self.draw = AnsiDraw(height=self.height, name=self.level_name) def matrix_selector(self, matrix, x, y): """ valinta matriisita """ @@ -78,7 +78,7 @@ class Tui(): self.draw.matrix(matrix, x, y) self.draw.status_line( f"{self.level_name}: " + - f"{'K' if self.suppress else 'Peli ohitse! Kuolit!':<30}" + "K " if self.suppress else f"{'Kuolit!':<30}" ) self.kbd.read_action() @@ -87,7 +87,7 @@ class Tui(): self.draw.matrix(matrix, x, y) self.draw.status_line( f"{self.level_name}: " + - f"{'V' if self.suppress else 'Peli ohitse! Voitit!':<30}" + "V " if self.suppress else "{'Voitit!':<30}" ) self.kbd.read_action() |