-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
57 lines (35 loc) · 924 Bytes
/
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
import pygame as pg
import sys
from pygame import mouse
pg.init()
screen = pg.display.set_mode((500, 500))
pg.display.set_caption("Tic-Tac-Toe")
grid = pg.image.load("Grid.png")
icon = pg.image.load("Window_icon.png")
x_img = pg.image.load("X.png")
o_img = pg.image.load("O.png")
pg.display.set_icon(icon)
moves = 0
def bg():
screen.blit(grid, (0, 0))
def move(x, y):
global moves
global screen
if moves % 2 == 1:
screen.blit(o_img, (x, y))
else:
screen.blit(x_img, (x, y))
running = True
while running:
screen.fill((255, 255, 255))
bg()
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
if event.type == pg.MOUSEBUTTONDOWN:
moves +=1
mouse_x, mouse_y = pg.mouse.get_pos()
move(mouse_x, mouse_y)
pg.display.update()
pg.quit()
sys.exit()