-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
72 lines (61 loc) · 1.78 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import pygame
MAP = [["","",""],
["","",""],
["","",""]]
WIDTH, HEIGHT = 600, 600
COLOR_O = (125,0,125)
COLOR_X = (0,125,125)
BLACK = (0,0,0)
WHITE = (255,255,255)
x_to_move = True
def is_empty(row,column):
if MAP[row][column] == "":
return True
else:
return False
def draw_o(surface, color, center, radius):
pygame.draw.circle(surface, color, center, radius, 4)
def draw_x(surface, color, start_pos, end_pos):
pygame.draw.line(surface, color, start_pos, end_pos, 4)
pygame.draw.line(surface, color, (start_pos[0] + 170, start_pos[1]), (end_pos[0] - 170, end_pos[1]), 4)
def check_for_winner(MAP):
line = ""
for row in range(3):
for column in range(3):
line += MAP[row][column]
if line == "xxx" or line == "ooo":
return False
else:
line = ""
for column in range(3):
for row in range(3):
line += MAP[row][column]
if line == "xxx" or line == "ooo":
return False
else:
line = ""
for row in range(3):
for column in range(3):
if row == column:
line += MAP[row][column]
if line == "xxx" or line == "ooo":
return False
else:
line = ""
line += MAP[1][1]
for row in range(3):
for column in range(3):
if abs(row - column) == 2:
line += MAP[row][column]
if line == "xxx" or line == "ooo":
return False
else:
line = ""
if line == "":
return True
def check_draw(MAP):
for row in range(3):
for column in range(3):
if MAP[row][column] == "":
return False
return True