This repository was archived by the owner on Apr 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfinalcommit.py
More file actions
111 lines (107 loc) · 3.14 KB
/
finalcommit.py
File metadata and controls
111 lines (107 loc) · 3.14 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
100
101
102
103
104
105
106
107
108
109
110
111
import simplegui
import random
pos=[[70,10],[60,10],[50,10],[40,10],[30,10],[20,10],[10,10]]
px,py=random.randint(1,49),random.randint(1,49)
px*=10
py*=10
def over():
global pos
t=False
for i in range(0,len(pos)):
for j in range(i+1,len(pos)):
if(pos[i]==pos[j]):
timer.stop()
frame.stop()
def moveon(key='0'):
global pos
check()
over()
print(pos)
if(pos[0]==[px,py]):
size()
if(key=='0'):
if(pos[0][0]>pos[1][0] and pos[0][1]==pos[1][1]):
temp=[pos[0][0],pos[0][1]]
pos[0][0]=pos[0][0]+10
shift(temp)
if(pos[0][0]<pos[1][0] and pos[0][1]==pos[1][1]):
temp=[pos[0][0],pos[0][1]]
pos[0][0]=pos[0][0]-10
shift(temp)
if(pos[0][1]>pos[1][1] and pos[0][0]==pos[1][0]):
temp=[pos[0][0],pos[0][1]]
pos[0][1]=pos[0][1]+10
shift(temp)
if(pos[0][1]<pos[1][1] and pos[0][0]==pos[1][0]):
temp=[pos[0][0],pos[0][1]]
pos[0][1]=pos[0][1]-10
shift(temp)
if(key!='0'):
print(key)
if(str(key)=='38'and pos[0][1]==pos[1][1] and pos[0][1]!=10):
temp=[pos[0][0],pos[0][1]]
pos[0][1]-=10
print(key)
shift(temp)
if(str(key)=='39'and pos[0][1]!=pos[1][1] and pos[0][0]!=490):
temp=[pos[0][0],pos[0][1]]
pos[0][0]+=10
print(key)
shift(temp)
if(str(key)=='40'and pos[0][1]==pos[1][1] and pos[0][1]!=490):
temp=[pos[0][0],pos[0][1]]
pos[0][1]+=10
print(key)
shift(temp)
if(str(key)=='37'and pos[0][1]!=pos[1][1] and pos[0][0]!=0):
temp=[pos[0][0],pos[0][1]]
pos[0][0]-=10
print(key)
shift(temp)
def shift(pos0):
global pos
n=len(pos)
temp=pos[0:n]
temp[0]=pos0
for i in range(0,n-1):
pos[i+1]=temp[i]
print(pos)
def size():
global pos,px,py
n=len(pos)
if(pos[n-2][0]==pos[n-1][0]):
pos.append([pos[n-1][0],pos[n-1][1]+10])
elif(pos[n-2][1]==pos[n-1][1]):
pos.append([pos[n-1][0]+10,pos[n-1][1]])
px,py=random.randint(1,49),random.randint(1,49)
px*=10
py*=10
def check():
global pos
n=len(pos)
if (pos[0][0]==490 and pos[1][0]!=490):
temp=[pos[0][0],pos[0][1]]
pos[0]=[490,temp[1]+10]
shift(temp)
if (pos[0][0]==10 and pos[1][0]!=10):
temp=[pos[0][0],pos[0][1]]
pos[0]=[10,temp[1]-10]
shift(temp)
if (pos[0][1]==490 and pos[1][1]!=490):
temp=[pos[0][0],pos[0][1]]
pos[0]=[temp[0]-10,490]
shift(temp)
if (pos[0][1]==10 and pos[1][1]!=10):
temp=[pos[0][0],pos[0][1]]
pos[0]=[temp[0]+10,10]
shift(temp)
def draw_handler(canvas):
canvas.draw_polyline(pos, 10, 'Red')
canvas.draw_line([px-5,py],[px+5,py], 10, 'Red')
frame = simplegui.create_frame('Testing', 500, 500)
frame.set_keydown_handler(moveon)
frame.set_draw_handler(draw_handler)
timer = simplegui.create_timer(100, moveon)
print(1)
timer.start()
frame.start()