forked from hhhrrrttt222111/PyBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaze.txt
More file actions
50 lines (40 loc) · 932 Bytes
/
Maze.txt
File metadata and controls
50 lines (40 loc) · 932 Bytes
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
# This game is from the official documentation of freegames
# https://pypi.org/project/freegames/
# pip install freegames
# import modules
import turtle as t
from random import random
from freegames import line
# Set window title, color and icon
t.title("Maze")
root = t.Screen()._root
root.iconbitmap("logo-ico.ico")
t.bgcolor('#b3ffe6')
# Functions
# Draw maze
def draw():
t.color('black')
t.width(5)
for x in range(-200, 200, 40):
for y in range(-200, 200, 40):
if random() > 0.5:
line(x, y, x + 40, y + 40)
else:
line(x, y + 40, x + 40, y)
t.update()
#Draw line and dot for screen tap
def tap(x, y):
if abs(x) > 198 or abs(y) > 198:
t.up()
else:
t.down()
t.width(2)
t.color('red')
t.goto(x, y)
t.dot(4)
t.setup(420, 420, 370, 0)
t.hideturtle()
t.tracer(False)
draw()
t.onscreenclick(tap)
t.done()