-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_input.py
66 lines (48 loc) · 1.94 KB
/
player_input.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from consts import *
class Chosen_Tile:
def __init__(self, row: int, col: int, flag: bool, unflag: bool):
self.row = row
self.col = col
self.flag = flag
self.unflag = unflag
def get_starting_tile() -> tuple:
starting_tile = get_user_input()
while is_valid_tile(starting_tile[0], starting_tile[1], None, None) is False:
print(TILE_NOT_VALID)
starting_tile = get_user_input()
return starting_tile
def get_user_input() -> tuple:
row = input(PICK_ROW)
while row.isnumeric() is False:
row = input(PICK_ROW)
col = input(PICK_COL)
while col.isnumeric() is False:
col = input(PICK_COL)
return (int(row), int(col))
def is_valid_tile(row: int, col: int, play_board: list, is_unflagging: bool) -> bool:
if ((col >= 0 and col < COLUMNS) and
(row >= 0 and row < ROWS)):
if (((play_board and play_board[row][col] == '▯') or
(play_board and play_board[row][col] == '^' and is_unflagging)) or
not play_board and not is_unflagging): # This last check is only when the starting tile is selected
return True
return False
def get_chosen_tile_and_decision(play_board: list) -> Chosen_Tile:
is_flagging = is_user_flagging()
is_unflagging = is_user_unflagging(is_flagging)
chosen_tile = get_user_input()
while is_valid_tile(chosen_tile[0], chosen_tile[1], play_board, is_unflagging) is False:
print(TILE_NOT_VALID)
chosen_tile = get_user_input()
return Chosen_Tile(chosen_tile[0], chosen_tile[1], is_flagging, is_unflagging)
def is_user_flagging() -> bool:
decision = input(PICK_FLAG)
if decision.lower() == 'y':
return True
return False
def is_user_unflagging(is_flagging: bool) -> bool:
if is_flagging is False:
decision = input(PICK_UNFLAG)
if decision.lower() == 'y' and is_flagging is False:
return True
return False