snack.py

Created by marius-layan

Created on February 05, 2024

1.43 KB

Voici une reconstitution d’un jeu bien connu nommé snack.

Le but est de manger les pastilles rouges pour grandir de plus en plus. On perd si on se mort la queue ou si on se prend un mur.

Déplacement: flèches directionnelles

que le plus grand gagne, BON JEU !


from random import *
from ion import *
from kandinsky import *
from time import *
pos,look,red,fin=[[16,10]],0,[randint(0,31),randint(0,21)],0
fill_rect(0,0,320,222,'black');fill_rect(red[0]*10,red[1]*10,10,10,'red')
while fin==0:
  m=monotonic()
  if not -1<pos[-1][0]<32 or not -1<pos[-1][1]<22:break
  fill_rect(0,0,320,222,'black')
  for i in range(len(pos)):
    if pos[i][0]==red[0] and pos[i][1]==red[1]:
      fill_rect(red[0]*10,red[1]*10,10,10,'green')
      red=[randint(0,31),randint(0,21)]
      pos.insert(0,[pos[0][0],pos[0][1]])
  for i in pos:fill_rect(i[0]*10,i[1]*10,10,10,'green')
  fill_rect(red[0]*10,red[1]*10,10,10,'red')
  for i in range(len(pos)-1):
    pos[i][0]=pos[i+1][0];pos[i][1]=pos[i+1][1]
    if i!=len(pos)-2 and pos[-1]==pos[i]:fin=1;break
  while monotonic()-m<0.1:
    if keydown(KEY_UP) and look!=1:look=3;break
    if keydown(KEY_DOWN) and look!=3:look=1;break
    if keydown(KEY_RIGHT) and look!=2:look=0;break
    if keydown(KEY_LEFT) and look!=0:look=2;break
    if keydown(KEY_OK):
      while True:
        draw_string("PAUSE",135,100,'yellow','black')
        if not keydown(KEY_OK):
          while not keydown(KEY_OK):continue
          while keydown(KEY_OK):continue
          break
  if look==0:pos[-1][0]+=1
  elif look==1:pos[-1][1]+=1
  elif look==2:pos[-1][0]-=1
  else:pos[-1][1]-=1
  sleep(0.1-(monotonic()-m))
fill_rect(0,0,320,222,'red')
draw_string("score: "+str(len(pos)),0,0,'black','red')

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.