-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (42 loc) · 1.65 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
import pygame
import sys
from const import *
from game import Game
class Main:
def __init__(self):
self.screen = pygame.display.set_mode( (WIDTH, HEIGHT) )
pygame.display.set_caption('ULTIMATE TIC TAC TOE')
self.game = Game(ultimate=True, max=True)
def mainloop(self):
screen = self.screen
game = self.game
self.screen.fill( BG_COLOR )
game.render_board(screen)
while True:
for event in pygame.event.get():
# click
if event.type == pygame.MOUSEBUTTONDOWN and game.playing:
xclick, yclick = event.pos
if game.board.valid_square(xclick, yclick):
game.board.mark_square(xclick, yclick, game.player)
game.board.draw_fig(screen, xclick, yclick)
# ultimate winner ?
winner = game.board.check_draw_win(screen)
if winner:
game.board.manage_win(screen, winner, onmain=True)
game.ultimate_winner(screen, winner)
game.next_turn()
# keypress
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
game.restart()
self.screen.fill( BG_COLOR )
game.render_board(screen)
# quit
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
if __name__ == '__main__':
main = Main()
main.mainloop()