From 53eea87fe65c5c4f063664c424d4b49176a27984 Mon Sep 17 00:00:00 2001 From: Aineopintojen-harjoitustyo-Algoritmit-j Date: Sun, 14 Jan 2024 15:08:54 +0200 Subject: Making it possible to ask hints. --- app.py | 2 +- tui/static.py | 4 +++- tui/tui.py | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index be711b0..977e6c3 100644 --- a/app.py +++ b/app.py @@ -8,7 +8,7 @@ class App: """ App - Luokka pääohjelmalle""" def __init__(self): self.board = Board() - self.ui = Tui() + self.ui = Tui("just testing bot here") self.game = Game(self.board,self.ui) def run(self): diff --git a/tui/static.py b/tui/static.py index b594c44..98b6985 100644 --- a/tui/static.py +++ b/tui/static.py @@ -31,7 +31,7 @@ ActionKeys = { "d": Action.RIGHT, " ": Action.OPEN, "\n": Action.OPEN, "f": Action.FLAG, "m": Action.FLAG, "q": Action.QUIT, "p": Action.BOMB, "x": Action.BOMB, "o": Action.SAFE, - "l": Action.QUIT, + "l": Action.QUIT, "?": Action.HINT, "b": Action.HINT } KEY_DESCRIPTIONS = """ @@ -43,6 +43,8 @@ Merkitseminen: t,o - turvallinen Avaaminen: ENTER, SPACE +Vinkki: + ?, b - pyydä botilta vihje Lopetus: l,q,ESC """ diff --git a/tui/tui.py b/tui/tui.py index 1f8f410..d884766 100644 --- a/tui/tui.py +++ b/tui/tui.py @@ -8,7 +8,7 @@ from tui.ansi import Ansi class Tui(): """ Tui - Luokka käyttäjän interaktiota varten """ - def __init__(self): + def __init__(self, bot = None): # Vaatii hieman terminaaliasetusten muokkaamista jotta yksittäiset # napin painallukset voidaan lukea # https://stackoverflow.com/questions/983354/how-do-i-wait-for-a-pressed-key @@ -22,6 +22,8 @@ class Tui(): self.oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, self.oldflags | os.O_NONBLOCK) + self.bot = bot + def __del__(self): # palautetaan terminaali takaisin alkupetäiseen uskoon @@ -94,6 +96,9 @@ class Tui(): x = 0 case Action.END: x = len(matrix)-1 + case Action.HINT: + if self.bot is not None: + return (Action.BOMB, 0, 0) self.draw_matrix(matrix, x, y) -- cgit v1.2.3