-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (26 loc) · 879 Bytes
/
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
from chessUI import UI
from Board import Board
import time
# initiate variables
UI = UI()
PlayingBoard = Board()
UI.init_board(PlayingBoard.getCoords())
while UI.get_state():
UI.user_input()
# await selected source coord
if UI.get_ready_state()[0]:
coords = UI.get_selected_coords()[0]
possibleMoves = PlayingBoard.getPossibleMoves(coords)
UI.set_possible_moves(possibleMoves)
# await selected target coord
if UI.get_ready_state()[1]:
PlayingBoard.move(*UI.get_selected_coords())
UI.clear_selection()
# check if a winner exists
if PlayingBoard.getWinner():
UI.message(f"{PlayingBoard.getWinner().upper()} WON THE GAME")
time.sleep(4)
UI.change_state()
UI.render(PlayingBoard.getCoords())
# sleep for 1/60 of a second to prevent unnecesary CPU overload
time.sleep(1/60)