-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnake.py
More file actions
49 lines (35 loc) · 1010 Bytes
/
Copy pathsnake.py
File metadata and controls
49 lines (35 loc) · 1010 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
import random
tom = Turtle()
tom.shape('turtle')
tom.speed(100)
tom.ht()
size=10
def draw(x,y,c):
tom.pu()
tom.goto(x*size,y*size)
tom.color(c)
tom.pd()
for i in range(4):
tom.fd(size)
tom.right(90)
def applyChanges(changes):
for i in changes:
draw(i[0],i[1],i[2])
snakes=[{'name':'A','location':[(1,1),(1,2)],'color':'green'},
{'name':'B','location':[(-5,1),(-6,1)],'color':'blue'}]
food=(0,0)
def initiateChanges(snakes,food):
changes=[]
for snake in snakes:
for x,y in snake['location']:
changes.append((x,y,snake['color']))
changes.append((food[0],food[1],'red'))
return changes
def gameMetrixGen(snakes,food):
gameMatrix=[]
for snake in snakes:
gameMatrix+=snake['location']
gameMatrix.append(food)
return gameMatrix
applyChanges(initiateChanges(snakes,food))
print gameMetrixGen(snakes,food)