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 /board | |
parent | db3fd859e42fb3d6b3c1f98473b54e91d78b74e7 (diff) |
Adding level-info on statusline.
Diffstat (limited to 'board')
-rw-r--r-- | board/board.py | 44 | ||||
-rw-r--r-- | board/static.py | 6 |
2 files changed, 30 insertions, 20 deletions
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") } |