snake.py

Created by chambounaudaubin

Created on January 30, 2025

5.1 KB


#Jeu par Aubin Chambounaud...
#fait le 02/11/2024 en 1h30min.
from math import *
from turtle import *
from random import *
from kandinsky import *
from ion import *
from time import *
x=150
y=80
go=1
stepx=-1
stepy=0
fpex=[]
fpey=[]
wait=100
lenght=0
pts=0
time=3000
sb=101
xa=randint(0,250)
ya=randint(0,200)
xb=randint(0,250)
yb=randint(0,250)
xc=randint(0,250)
yc=randint(0,250)
xd=randint(0,250)
yd=randint(0,250)
xf=randint(0,250)
yf=randint(0,250)
fill_rect(0,0,400,400,'green')
while go==1:
  time=time-1
  x=x+stepx
  y=y+stepy
  fill_rect(x,y,10,10,'blue')
  fill_rect(xa,ya,10,10,'red')
  fill_rect(xb,yb,10,10,'red')
  fill_rect(xc,yc,10,10,'black')
  fill_rect(xd,yd,10,10,'yellow')
  fill_rect(xf,yf,10,10,'yellow')
  if x>=xa-10 and x<xa+10 and y>=ya-10 and y<ya+10:
    fill_rect(xa,ya,10,10,'green')
    pts=pts+1
    xa=randint(0,250)
    ya=randint(0,200)
    fill_rect(xa,ya,10,10,'red')
  if x>=xb-10 and x<xb+10 and y>=yb-10 and y<yb+10:
    fill_rect(xb,yb,10,10,'green')
    pts=pts+1
    xb=randint(0,250)
    yb=randint(0,200)
    fill_rect(xb,yb,10,10,'red')
  if x>=xc-10 and x<xc+10 and y>=yc-10 and y<yc+10:
    fill_rect(xc,yc,10,10,'green')
    pts=pts-1
    xc=randint(0,250)
    yc=randint(0,200)
    fill_rect(xc,yc,10,10,'black')
  if x>=xd-10 and x<xd+10 and y>=yd-10 and y<yd+10:
    fill_rect(xd,yd,10,10,'green')
    fill_rect(xf,yf,10,10,'green')
    x=xf
    y=yf
    xd=randint(0,250)
    yd=randint(0,200)
    xf=randint(0,250)
    yf=randint(0,200)
    fill_rect(xd,yd,10,10,'yellow')
    fill_rect(xf,yf,10,10,'yellow')
  if x>=xf-10 and x<xf+10 and y>=yf-10 and y<yf+10:
    fill_rect(xf,yf,10,10,'green')
    fill_rect(xd,yd,10,10,'green')
    x=xd
    y=yd
    xd=randint(0,250)
    yd=randint(0,200)
    xf=randint(0,250)
    yf=randint(0,250)
    fill_rect(xd,yd,10,10,'yellow')
    fill_rect(xf,yf,10,10,'yellow')
  if keydown(KEY_UP):
    stepy=-1
    stepx=0
  if keydown(KEY_DOWN):
    stepy=1
    stepx=0
  if keydown(KEY_RIGHT):
    stepy=0
    stepx=1
  if keydown(KEY_LEFT):
    stepy=0
    stepx=-1
  if x<0:
    x=x+330
  if x>330:
    x=x-330
  if y<0:
    y=y+230
  if y>230:
    y=y-230
  if pts==0:
    draw_string("score=+0 ",100,10)
  if pts==1:
    draw_string("score=+1 ",100,10)
  if pts==2:
    draw_string("score=+2 ",100,10)
  if pts==3:
    draw_string("score=+3 ",100,10)
  if pts==4:
    draw_string("score=+4 ",100,10)
  if pts==5:
    draw_string("score=+5 ",100,10)
  if pts==6:
    draw_string("score=+6 ",100,10)
  if pts==7:
    draw_string("score=+7 ",100,10)
  if pts==8:
    draw_string("score=+8 ",100,10)
  if pts==9:
    draw_string("score=+9 ",100,10)
  if pts==10:
    draw_string("score=+10",100,10)
  if pts==11:
    draw_string("score=+11",100,10)
  if pts==12:
    draw_string("score=+12",100,10)
  if pts==13:
    draw_string("score=+13",100,10)
  if pts==14:
    draw_string("score=+14",100,10)
  if pts==15:
    draw_string("score=+15",100,10)
  if pts==16:
    draw_string("score=+16",100,10)
  if pts==17:
    draw_string("score=+17",100,10)
  if pts==18:
    draw_string("score=+18",100,10)
  if pts==19:
    draw_string("score=+19",100,10)
  if pts==20:
    draw_string("score=+20",100,10)
  if pts==21:
    draw_string("score=+21",100,10)
  if pts==22:
    draw_string("score=+22",100,10)
  if pts==23:
    draw_string("score=+23",100,10)
  if pts==24:
    draw_string("score=+24",100,10)
  if pts==25:
    draw_string("score=+25",100,10)
  if pts==26:
    draw_string("score=+26",100,10)
  if pts==27:
    draw_string("score=+27",100,10)
  if pts==28:
    draw_string("score=+28",100,10)
  if pts==29:
    draw_string("score=+29",100,10)
  if pts==30:
    draw_string("score=+30",100,10)
  if pts==-1:
    draw_string("score=-1",100,10)
  if pts==-2:
    draw_string("score=-2",100,10)
  if pts==-3:
    draw_string("score=-3",100,10)
    go=0
  fpex.append(x)
  fpey.append(y)
  lenght=lenght+1
  wait=wait-1
  if wait<-1:
    xe=fpex[lenght-100]
    ye=fpey[lenght-100]
    fill_rect(xe,ye,12,12,'green')
  if time<0:
    go=0
  sleep(0.01)
  sb=sb-1
  if sb==1:
    fill_rect(150,80,10,10,'green')
    sb=0
if pts>=25:
  fill_rect(0,0,400,400,'white')
  for i in range(100):
    draw_string("time's up! you won!!!",70,100,'blue')
    draw_string("you had to get at least",70,120)
    draw_string("25 apples",40,140)
    for i in range(100):
      fill_rect(randint(0,320),randint(0,280),10,10,'yellow')
      fill_rect(randint(0,320),randint(0,280),10,10,'green')
      fill_rect(randint(0,320),randint(0,280),10,10,'blue')
      fill_rect(randint(0,320),randint(0,280),10,10,'red')
      fill_rect(randint(0,320),randint(0,280),10,10,'orange')
      fill_rect(randint(0,320),randint(0,280),10,10,'pink')
      fill_rect(randint(0,320),randint(0,280),10,10,'purple')
  draw_string("time's up! you won!!!",70,100,'blue')
  draw_string("you had to get at least",70,120)
  draw_string("25 apples",40,140)  
elif pts>=-2:
  fill_rect(0,0,400,400,'white')
  draw_string("time's up,you lost:(",40,100,'blue')
  draw_string("next time, get more apples",40,120)
elif pts==-3:
  fill_rect(0,0,400,400,'white')
  draw_string("score=-3",50,100)
  draw_string("dont eat black squares",50,120)
print("your score was",pts)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.