/
main.py
90 lines (62 loc) · 1.43 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
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
'''
The main module which
builds the pygame window
and contains the gameloop.
- Lonsdaleiter
'''
import config
import pygame
import drawer
import mouse
import assets
import keyboard
import board
import turnmanager
import time
import os
running = False
window = None
clock = None
def init():
global running
global window
global clock
pygame.init()
running = True
window = pygame.display.set_mode((config.WIDTH, config.HEIGHT))
pygame.display.set_caption("Chess")
clock = pygame.time.Clock()
drawer.window = window
board.init(window)
def update():
global running
global window
global clock
mouseup = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
mouseup = True
mouse.down = True
if not mouseup:
mouse.down = False
if event.type == pygame.MOUSEMOTION:
mouse.x = pygame.mouse.get_pos()[0]
mouse.y = pygame.mouse.get_pos()[1]
clock.tick(60)
drawer.draw(assets.background_image, 0, 0)
keyboard.update()
board.update()
pygame.display.flip()
if turnmanager.won:
os.system("say 'Closing the window in 5 seconds'")
time.sleep(5)
exit(0)
def end():
pygame.quit()
if __name__ == "__main__":
init()
while running:
update()
end()