summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
Diffstat (limited to 'board')
-rw-r--r--board/board.py29
1 files changed, 15 insertions, 14 deletions
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):