# snake.py

Created by eta45

Created on April 15, 2021

2.1 KB

```from math import *
from kandinsky import *
from random import *
from ion import *
from time import *

fr=fill_rect
x=[0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310]
y=[30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210]
a,b=10,15
old1=[(15,10)]

def efface():
v,w=old1[len(old1)-derniere]
fr(x[v],y[w],10,10,color(248,252,248))

def pg():
r=a,b
old1.append(r)

xo,yo=choice(x),choice(y)
l,derniere,a,b,direc,t,fin,point=0,2,15,10,2,0.15,False,0
fr(xo,yo,10,10,color(0,250,0)),fr(0,0,320,30,color(0,0,250)),draw_string("nombre de point:",10,5),draw_string(str(point),180,5),draw_string("niveau:",210,5),draw_string("1",300,5)
while not fin:
pg()
c=1
if keydown(KEY_UP):
direc,c=1,0
b-=1
if keydown(KEY_RIGHT):
direc,c=2,0
a+=1
if keydown(KEY_DOWN):
direc,c=3,0
b+=1
if keydown(KEY_LEFT):
direc,c=4,0
a-=1
if c==1:
if direc==1:b-=1
if direc==2:a+=1
if direc==3:b+=1
if direc==4:a-=1
if a==32 or a<0 or b>18 or b<0:
draw_string("perdu",150,110,color(248,0,0),color(0,252,0))
break
h=get_pixel(x[a],y[b])
if h==(248,0,0):
fr(x[a],y[b],10,10,color(0,0,248))
draw_string("perdu!",150,110,color(248,0,0),color(0,250,0))
break
efface()
fr(x[a],y[b],10,10,color(250,0,0))
sleep(t)
if x[a]==xo and y[b]==yo:
point+=1
draw_string(str(point),180,5)
derniere+=1
find=False
while not find:
xo,yo=choice(x),choice(y)
if get_pixel(xo+2,yo+2)==(248,252,248):break
fr(xo,yo,10,10,color(0,250,0))
if point==5 and l==0:
t,l=0.12,1
fr(130,90,60,10,color(250,0,0)),fr(130,150,60,10,color(250,0,0)),draw_string("2",300,5)
if point==10 and l==1:
t,l==0.09,2
draw_string("3",300,5),fr(0,110,10,20,color(250,0,0)),fr(310,110,10,20,color(250,0,0)),fr(150,30,20,10,color(250,0,0)),fr(150,210,20,10,color(250,0,0))
if point==15 and l==2:
t,l=0.07,3
draw_string("4",300,5),fr(60,70,20,20,color(250,0,0)),fr(60,150,20,20,color(250,0,0)),fr(230,70,20,20,color(250,0,0)),fr(230,150,20,20,color(250,0,0))```