-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameevents.py
28 lines (25 loc) · 1.05 KB
/
gameevents.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
from Game import Game
import pygame
def handleEvents(events, game, state):
for event in events:
if event.type == pygame.QUIT:
Game.running = False
pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
# verificam daca am apasat pe butonul de quit
if event.button == 1 and pos[0] >= 1100 and pos[1] <= 70:
Game.running = False
break
# mutarea jucatorului
if event.button == 1 and game.isValidMove(state.currentPlayer):
x, y = game.makeMove(state.currentPlayer)
game.showMatrix()
game.matrix[y][x] = state.currentPlayer[0]
game.solution = game.findSolution()
if not game.gameOver():
state.currentPlayer = game.otherPlayer(state.currentPlayer)
else:
game.text = 'Game over! {} wins!'.format(state.currentPlayer.capitalize())
return True
return False