-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (43 loc) · 1.64 KB
/
main.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
import sys
from gameboard import GameBoard
NUM_OF_ROWS_COLUMNS = 18
GAME_COLORS = ["r", "g", "b", "y"]
COLORS_COLOR = [1, 2, 4, 3]
ALLOWED_STEPS = 21
# starts a coloring game
def main():
# create a game board - with randomized colors (rgby)
gb = GameBoard(NUM_OF_ROWS_COLUMNS, GAME_COLORS, COLORS_COLOR)
steps_played = 0
print("Welcome to the Coloring Game!")
print(f"Please enter one of the possible colors to play this game: {GAME_COLORS}")
gb.print_board()
# start listening on inputs from the user (the actual game)
print(f"Available game colors: {GAME_COLORS}")
print(f"Please select a color:")
for line in sys.stdin:
# game over if played too many steps
if steps_played == ALLOWED_STEPS:
print(f'Game over! Unfortunately you ran out of steps. (Allowed steps: {ALLOWED_STEPS})')
break
steps_played += 1
# remove the newline char from the input line
line = line[:-1]
# when quit/q - exit game
if line in ["quit", "q"]:
print("Exiting game!")
return
# when input is a color - paint the board accordingly
if line in GAME_COLORS:
# color with the selected color
gb.color(line)
if gb.is_game_finished():
print("Congratulations! you finished the game")
break
# TODO: add an option to retry
print("Current game board:")
gb.print_board()
print(f"Please select the next color: (Remaining steps: {ALLOWED_STEPS - steps_played})")
print("Goodbye! Hope to see you back soon!")
if __name__ == "__main__":
main()