forked from hhhrrrttt222111/PyBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile-15.txt
More file actions
99 lines (79 loc) · 1.93 KB
/
Tile-15.txt
File metadata and controls
99 lines (79 loc) · 1.93 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# This game is from the official documentation of freegames
# https://pypi.org/project/freegames/
# pip install freegames
# Tap on Tile to Move
# import modules
from random import *
import turtle as t
from freegames import floor, vector
# Set window title, color and icon
t.title("Tile-15")
root = t.Screen()._root
root.iconbitmap("logo-ico.ico")
t.bgcolor('#990099')
tiles = {}
neighbors = [
vector(100, 0),
vector(-100, 0),
vector(0, 100),
vector(0, -100),
]
# Functions
# Load tiles and scramble
def load():
count = 1
for y in range(-200, 200, 100):
for x in range(-200, 200, 100):
mark = vector(x, y)
tiles[mark] = count
count += 1
tiles[mark] = None
for count in range(1000):
neighbor = choice(neighbors)
spot = mark + neighbor
if spot in tiles:
number = tiles[spot]
tiles[spot] = None
tiles[mark] = number
mark = spot
# Draw white square with black outline and number
def square(mark, number):
t.up()
t.goto(mark.x, mark.y)
t.down()
t.color('#003325', '#ffb3e6')
t.begin_fill()
for count in range(4):
t.forward(99)
t.left(90)
t.end_fill()
if number is None:
return
elif number < 10:
t.forward(20)
t.write(number, font=('Arial', 45, 'normal'))
# Swap tile and empty square
def tap(x, y):
x = floor(x, 100)
y = floor(y, 100)
mark = vector(x, y)
for neighbor in neighbors:
spot = mark + neighbor
if spot in tiles and tiles[spot] is None:
number = tiles[mark]
tiles[spot] = number
square(spot, number)
tiles[mark] = None
square(mark, None)
# Draw all tiles
def draw():
for mark in tiles:
square(mark, tiles[mark])
t.update()
t.setup(420, 420, 370, 0)
t.hideturtle()
t.tracer(False)
load()
draw()
t.onscreenclick(tap)
t.done()