-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
129 lines (95 loc) · 3.85 KB
/
game.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from gameboard import GameBoard
from flask import Flask
import PySimpleGUI as sg
def playVisualGame():
sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0,0))
window = sg.Window("Time Tracker", auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(2,1))
recording = have_data = False
while True:
print("Starting game")
gb = GameBoard(16,16,True)
gb.printGameBoard()
sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0,0))
layout = gb.getGameBoard()
window = sg.Window("Time Tracker", auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(2,1))
window.Layout(layout)
recording = have_data = False
while True:
event, values = window.Read()
if(event == None):
quit()
# print(event)
if(event == "Reset"):
window.Close()
#Break the inner loop to reset the game
break
x = event.split(',')
if(len(x) < 2 or len(x)>3):
print("Invalid input length")
continue
row = None
col = None
F = False
if(len(x) == 2):
row,col = x
else:
row,col,F = x
gb.userInput(int(row),int(col))
if(gb.gamestate == gb.GAME_WIN):
print("YOU WIN!!!")
elif(gb.gamestate == gb.GAME_OVER):
print("YOU LOSE :(")
new_board = gb.getGameBoard()
for row in range(0,gb.height):
for col in range(0,gb.width):
try:
if(window.FindElement(str(row)+','+str(col)).GetText() == "F"):
window.FindElement(str(row)+','+str(col)).Update("?")
if(new_board[row+3][col].GetText() != "?"):
if(new_board[row+3][col].GetText() != "F"):
window.FindElement(str(row)+','+str(col)).Update(disabled=True)
window.FindElement(str(row)+','+str(col)).Update(new_board[row+3][col].GetText())
except AttributeError as e:
#We need to catch and pass over non button elements
pass
window.Refresh()
window.Close()
def playCLIGame():
gb = GameBoard(16,16,False)
gb.printGameBoard()
while(gb.gamestate == gb.GAME_RUNNING):
print("Please input your command in the following format: [row,col,flag(optional)]. Parenthesis are not required")
user_input = input()
user_input = str(user_input)
user_input = user_input.strip()
user_input = user_input.lstrip('[')
user_input = user_input.rstrip(']')
x = user_input.split(',')
if(len(x) < 2 or len(x)>3):
print("Invalid input length")
continue
row = None
col = None
F = ""
if(len(x) == 2):
row,col = x
else:
row,col,F = x
if(len(F) > 0 and (F[0].lower() == 't' or F[0].lower() == 'f')):
gb.userInput(int(row),int(col),True)
else:
gb.userInput(int(row),int(col))
gb.printGameBoard()
if __name__ == "__main__":
print("Do you want to play a Visual Game? (If not the game with be command line based) : Y/N")
choice = input()
print(choice[0])
print("Starting game")
if(choice[0].lower() == 'y'):
playVisualGame()
else:
playCLIGame()