From 2b98f7c66facfe71bf91aebc0d8cf3978e88303f Mon Sep 17 00:00:00 2001 From: Aineopintojen-harjoitustyo-Algoritmit-j Date: Sun, 14 Jan 2024 14:13:59 +0200 Subject: Making it possible to flag bombs and safe areas directly. --- board/board.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'board/board.py') diff --git a/board/board.py b/board/board.py index 04d81d1..0b4c3a2 100644 --- a/board/board.py +++ b/board/board.py @@ -121,25 +121,26 @@ class Board(): return self.masked[x][y] - def flag(self, x, y): + def flag(self, x, y, flag=-1): """ aseta lippu peitetylle ruudulle""" if self.invalid_coordinates(x, y): print("Koordinaatit on pelilaudan ulkopuolella", file=stderr) return False - match self.masked[x][y]: - case 0: - print("Ei voi liputtaa avattua ruutua", file=stderr) - return False - case 10 | 11 | 12: - self.masked[x][y]+=1 - return True - case 13: - self.masked[x][y]=10 - return True - - print("Ruudulla odottamaton lippu", file=stderr) - return False + if self.masked[x][y] not in range(10,14): + print("Ruudulla odottamaton lippu tai se on avattu", file=stderr) + return False + + if flag == -1: + self.masked[x][y] += 1 if self.masked[x][y] < 13 else -3 + return True + + if flag not in range(10,14): + print("Lippua jota asetat ei ole olemassa", file=stderr) + return False + + self.masked[x][y]=flag + return True def guess(self, x, y): -- cgit v1.2.3