-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathflippingtile.py
More file actions
81 lines (67 loc) · 1.54 KB
/
Copy pathflippingtile.py
File metadata and controls
81 lines (67 loc) · 1.54 KB
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
# import modules
from random import *
from turtle import *
# set the screen
screen = Screen()
#choose background color
screen.bgcolor("yellow")
# define the function
# for creating a square section
# for the game
def Square(x, y):
up()
goto(x, y)
down()
color('white', 'green')
begin_fill()
for count in range(4):
forward(50)
left(90)
end_fill()
# define function to
# keep a check of index number
def Numbering(x, y):
return int((x + 200) // 50 + ((y + 200) // 50) * 8)
# define function
def Coordinates(count):
return (count % 8) * 50 - 200, (count // 8) * 50 - 200
# define function
# to make it interactive
# user click
def click(x, y):
spot = Numbering(x, y)
mark = state['mark']
if mark is None or mark == spot or tiles[mark] != tiles[spot]:
state['mark'] = spot
else:
hide[spot] = False
hide[mark] = False
state['mark'] = None
def draw():
clear()
goto(0, 0)
stamp()
for count in range(64):
if hide[count]:
x, y = Coordinates(count)
Square(x, y)
mark = state['mark']
if mark is not None and hide[mark]:
x, y = Coordinates(mark)
up()
goto(x + 2, y)
color('black')
write(tiles[mark], font=('Arial', 30, 'normal'))
update()
ontimer(draw, 10)
tiles = list(range(32)) * 2
state = {'mark': None}
hide = [True] * 64
# for shuffling the
# numbers placed inside
# the square tiles
shuffle(tiles)
tracer(False)
onscreenclick(click)
draw()
done()