From db3fd859e42fb3d6b3c1f98473b54e91d78b74e7 Mon Sep 17 00:00:00 2001 From: Aineopintojen-harjoitustyo-Algoritmit-j Date: Tue, 30 Jan 2024 08:28:14 +0200 Subject: Making it actually possible to select board dimensions. --- app.py | 19 +++++++++++++------ tui/tui.py | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app.py b/app.py index 4af66dd..a9cee19 100644 --- a/app.py +++ b/app.py @@ -8,20 +8,27 @@ from bots import SimpleBot, DSSPBot class App: """ App - Luokka pääohjelmalle""" def __init__(self, args=None): - level = Level.BEGINNER + board_opts = {'level': Level.BEGINNER} tui_opts = {'bot': DSSPBot} if args: - # pylint: disable = pointless-statement - (level:=Level.INTERMEDIATE) if args.intermediate else () - (level:=Level.EXPERT) if args.expert else () + if args.intermediate: + board_opts['level'] = Level.INTERMEDIATE + if args.expert: + board_opts['level'] = Level.EXPERT + if args.w: + board_opts['width'] = args.w + if args.H: + board_opts['height'] = args.H + if args.b: + board_opts['bombs'] = args.b tui_opts['bot'] = SimpleBot if args.simple else DSSPBot tui_opts['autoplay'] = args.auto tui_opts['interactive'] = not args.uncertain tui_opts['suppress'] = args.quiet - tui_opts['height'] = LevelSpecs[level][1] + tui_opts['height'] = LevelSpecs[board_opts['level']][1] - self.board = Board(level=level) + self.board = Board(**board_opts) self.ui = Tui(**tui_opts) self.game = Game(self.board,self.ui) diff --git a/tui/tui.py b/tui/tui.py index f91db05..3369a61 100644 --- a/tui/tui.py +++ b/tui/tui.py @@ -7,37 +7,37 @@ from .ansi_draw import AnsiDraw, SuppressDraw class Tui(): """ Tui - Luokka käyttäjän interaktiota varten """ - # pylint: disable = too-many-arguments + # pylint: disable = too-many-arguments, too-many-instance-attributes def __init__(self, bot = None, autoplay = False, interactive = True, suppress = False, - height = 9): + height = 9, + level_name = "outo lauta"): - self.autoplay = autoplay - self.interactive = interactive - self.suppress = suppress - self.height = height - - # jos ei oo bottia pitää olla interaktiivinen + # jos ei ole bottia pitää olla interaktiivinen if bot is None: - self.autoplay = False - self.interactive = True - self.suppress = False + autoplay = False + interactive = True + suppress = False # jos ei mitään näytetä ei voi olla interaktiivinen - self.interactive = False if self.suppress else self.interactive + # pylint: disable = pointless-statement + (interactive := False) if suppress else () # automaattipeli pitää olla päällä jos ei interaktiivinen - self.autoplay = self.autoplay if self.interactive else True + (autoplay := True) if not interactive else () + + self.autoplay = autoplay + self.interactive = interactive + self.suppress = suppress + self.height = height + self.level_name = level_name self.bot = bot(uncertain=not self.interactive) if bot else None - if self.interactive: - self.kbd = Kbd() - else: - self.kbd = NoKbd() + self.kbd = Kbd() if self.interactive else NoKbd() if self.suppress: self.draw = SuppressDraw() @@ -77,7 +77,8 @@ class Tui(): """ tehtävät kun kuolee """ self.draw.matrix(matrix, x, y) self.draw.status_line( - "K " if self.suppress else "Peli ohitse! Kuolit!" + f"{self.level_name}: " + + f"{'K' if self.suppress else 'Peli ohitse! Kuolit!':<30}" ) self.kbd.read_action() @@ -85,7 +86,8 @@ class Tui(): """ tehtävät kun voittaa """ self.draw.matrix(matrix, x, y) self.draw.status_line( - "V " if self.suppress else "Peli ohitse! Voitit!" + f"{self.level_name}: " + + f"{'V' if self.suppress else 'Peli ohitse! Voitit!':<30}" ) self.kbd.read_action() @@ -93,4 +95,7 @@ class Tui(): """ tehtävät ihan pelin lopuksi """ if self.interactive: self.draw.matrix(matrix, -1, -1) - self.draw.status_line("Kiitos! ") + self.draw.status_line( + f"{self.level_name}: " + + f"{'Kiitos!':<30}" + ) -- cgit v1.2.3