diff options
| author | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-30 08:28:14 +0200 | 
|---|---|---|
| committer | Aineopintojen-harjoitustyo-Algoritmit-j <github-hy-tiralabra@v.hix.fi> | 2024-01-30 08:28:14 +0200 | 
| commit | db3fd859e42fb3d6b3c1f98473b54e91d78b74e7 (patch) | |
| tree | 5d08001a2dcd6e3ddaf1f9118c9ae345d4ab7132 | |
| parent | fa6a80ea7107c3a1e7c1fa600817b0c5f7be5d36 (diff) | |
Making it actually possible to select board dimensions.
| -rw-r--r-- | app.py | 19 | ||||
| -rw-r--r-- | tui/tui.py | 45 | 
2 files changed, 38 insertions, 26 deletions
| @@ -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) @@ -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}" +            ) |