summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/game.py4
-rw-r--r--tui/static.py27
-rw-r--r--tui/tui.py13
3 files changed, 37 insertions, 7 deletions
diff --git a/game/game.py b/game/game.py
index d46d97b..0a36b0a 100644
--- a/game/game.py
+++ b/game/game.py
@@ -34,4 +34,8 @@ class Game:
return False
case Action.FLAG:
self.board.flag(self.x, self.y)
+ case Action.BOMB:
+ self.board.flag(self.x, self.y, 11)
+ case Action.SAFE:
+ self.board.flag(self.x, self.y, 12)
return True
diff --git a/tui/static.py b/tui/static.py
index 7bdfa12..b594c44 100644
--- a/tui/static.py
+++ b/tui/static.py
@@ -9,7 +9,7 @@ class Action(Enum):
FLAG = 2 # Ruudun liputus
HINT = 3 # Anna vihjeet
AUTO = 4 # Pelaa automaattisesti
- LEFT = 5
+ LEFT = 5 # Liikkumiset...
RIGHT = 6
UP = 7
DOWN = 8
@@ -17,19 +17,36 @@ class Action(Enum):
BOTTOM = 10
BEGIN = 11
END = 12
- NOOP = 13
+ NOOP = 13 # ei mitään - tarvitaan, ettei mätsää ansikoodeja esciin
+ BOMB = 14 # merkkaa pommi
+ SAFE = 15 # merkkaa turvallinen
# ActionKeys - Ohjelma vertaa syötteen alkua näihin ja palauttaa ekan
ActionKeys = {
"\033[A": Action.UP, "\033[D": Action.LEFT,
"\033[C": Action.RIGHT, '\033[B': Action.DOWN, "\033[5~": Action.TOP,
"\033[6~": Action.BOTTOM, "\033[7~": Action.BEGIN,"\033[8~": Action.END,
- "\033[": Action.NOOP, "\033": Action.QUIT,
+ "\033[": Action.NOOP, "\033": Action.QUIT, "t": Action.SAFE,
"w": Action.UP, "a": Action.LEFT, "s": Action.DOWN,
"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,
}
+KEY_DESCRIPTIONS = """
+Liikkuminen:
+ YLÖS,ALAS,VASEN,OIKEA,PGDN,PGUP,HOME,END,w,a,s,d
+Merkitseminen:
+ m - merkitse
+ p,x - pommi
+ t,o - turvallinen
+Avaaminen:
+ ENTER, SPACE
+Lopetus:
+ l,q,ESC
+"""
+
@dataclass
class TileType:
""" ruututyyppien tallennusmuotojen kuvaus"""
@@ -49,7 +66,7 @@ TileTypes = {
8: TileType( "[8]", [(0x9,0), (0x9,0), (0x9,0)] ),
9: TileType( "[@]", [(0xF,1), (0xF,1), (0xF,1)] ),
10: TileType( "[#]", [(0x8,7), (0x8,7), (0x8,7)] ),
- 11: TileType( "[B]", [(0x8,7), (0x1,7), (0x8,7)] ),
- 12: TileType( "[ ]", [(0x8,7), (0x3,7), (0x8,7)] ),
+ 11: TileType( "[×]", [(0x8,7), (0x1,7), (0x8,7)] ),
+ 12: TileType( "[•]", [(0x8,7), (0x2,7), (0x8,7)] ),
13: TileType( "[?]", [(0x8,7), (0x0,7), (0x8,7)] )
}
diff --git a/tui/tui.py b/tui/tui.py
index 5b15d5f..1f8f410 100644
--- a/tui/tui.py
+++ b/tui/tui.py
@@ -47,7 +47,8 @@ class Tui():
# pylint: disable=consider-using-enumerate
for y in range(len(matrix[0])):
for x in range(len(matrix)):
- self.draw_tile(matrix[x][y], x == hx and y == hy)
+ hilight = matrix[x][y] != 9 and x == hx and y == hy
+ self.draw_tile(matrix[x][y], hilight)
print()
@@ -74,7 +75,7 @@ class Tui():
match action:
case Action.QUIT:
return (action, x, y)
- case Action.OPEN | Action.FLAG:
+ case Action.OPEN | Action.FLAG | Action.BOMB | Action.SAFE:
if matrix[x][y] >= 10:
return (action, x, y)
case Action.UP:
@@ -85,6 +86,14 @@ class Tui():
y = y+1 if y < len(matrix[0])-1 else y
case Action.RIGHT:
x = x+1 if x < len(matrix)-1 else x
+ case Action.TOP:
+ y = 0
+ case Action.BOTTOM:
+ y = len(matrix[0])-1
+ case Action.BEGIN:
+ x = 0
+ case Action.END:
+ x = len(matrix)-1
self.draw_matrix(matrix, x, y)