stack.py

Created by marius-layan

Created on February 05, 2024

3.85 KB

Voici une reconstitution en 3d du jeu mobile stack. Le but est de faire la plus haute pile de rectangles.

Plus vous montez en niveau, plus vous débloquerez de nouvelles couleurs dans le menu.

Placer le rectangle: [ OK ]

Menu: [ EXE ]


from random import *
from kandinsky import *
from ion import *
from time import *
score1,d,d1,l1,l2=0,0,0,['black','white','red','blue','yellow','brown','pink','orange','purple'],['white','black','red','blue','yellow','brown','pink','orange','purple']
while True:
  a,l,score=100,[[110,100,0,randint(1,5)]],0
  while keydown(KEY_OK):continue
  while True:
    l.append([0,a,0,randint(1,5)])
    if randint(0,50)==0:l[-1][3]==0.2
    score+=1
    if score1<score:score1=score
    fill_rect(0,0,320,222,l1[d])
    if d==1:draw_string("Score: "+str(score),5,5,'black','white');draw_string("max: "+str(score1),5,20,'black','white')
    elif d==4:draw_string("Score: "+str(score),5,5,'black','yellow');draw_string("max: "+str(score1),5,20,'black','yellow')
    else:draw_string("Score: "+str(score),5,5,'yellow',l1[d]);draw_string("max: "+str(score1),5,20,'yellow',l1[d])
    if len(l)==5:del l[0]
    while True:
      for i in range(len(l)):
        b=0
        if score in (1,2):b+=1
        if score==1:b+=1
        fill_rect(l[i][0],142+(len(l)-1-i)*20+b*20,l[i][1],20,l2[d1])
      if l[-1][2]==0:fill_rect(l[-1][0],142+b*20,1,20,l1[d]);l[-1][0]+=1
      else:fill_rect(l[-1][0]+l[-1][1],142+b*20,1,20,l1[d]);l[-1][0]-=1
      if l[-1][0]==320-l[-1][1]:l[-1][2]=1
      if l[-1][0]==0:l[-1][2]=0
      sleep(l[-1][3]/300)
      if keydown(KEY_OK):
        if len(l)!=1:
          if l[-1][0]>l[-2][0]:a-=l[-1][0]-l[-2][0]
          else:a-=l[-2][0]-l[-1][0];l[-1][0]+=l[-2][0]-l[-1][0]
          l[-1][1]=a
        while keydown(KEY_OK):continue
        break
    if a<1:break
  c,e,e1,f=1,0,0,0
  while True:
    if c==1:
      fill_rect(0,0,320,222,l1[d])
      for i in range(len(l)-1):fill_rect(l[i][0],142+(len(l)-1-i)*20+b*20,l[i][1],20,l2[d1])
      if d==2:draw_string("GAME OVER",110,60,'white',l1[d])
      else:draw_string("GAME OVER",110,60,'red',l1[d])
      if d==4:draw_string("Score: "+str(score),5,5,'black','yellow');draw_string("max: "+str(score1),5,20,'black','yellow');draw_string("Colors: exe",200,5,'black','yellow')
      elif d==1:draw_string("Score: "+str(score),5,5,'black','white');draw_string("max: "+str(score1),5,20,'black','white');draw_string("Colors: exe",200,5,'black','white')
      else:draw_string("Score: "+str(score),5,5,'yellow',l1[d]);draw_string("max: "+str(score1),5,20,'yellow',l1[d]);draw_string("Colors: exe",200,5,'yellow',l1[d])
      c=0
    if c==2:
      fill_rect(0,0,320,222,'black');fill_rect(27,50,26,26,'gray')
      for i in range(len(l1)):
        if score1>=i*10:fill_rect(i*30+27,50,26,26,'gray')
        else:fill_rect(i*30+27,50,26,26,(80,80,80))
        if d==i:fill_rect(i*30+27,50,26,26,(0,50,0))
        fill_rect(i*30+31,54,18,18,l1[i])
        if score1>=i*10:fill_rect(i*30+27,90,26,26,'gray')
        else:fill_rect(i*30+27,90,26,26,(80,80,80))
        if d1==i:fill_rect(i*30+27,90,26,26,(0,50,0))
        fill_rect(i*30+31,94,18,18,l2[i])
      if f==0:fill_rect(e*30+27,76,26,5,'green')
      else:fill_rect(e1*30+27,116,26,5,'green')
      c=3
    if keydown(KEY_RIGHT) and c==3 and f==0 and e<8:
      e+=1;c=2
      while keydown(KEY_RIGHT):continue
    if keydown(KEY_RIGHT) and c==3 and f==1 and e1<8:
      e1+=1;c=2
      while keydown(KEY_RIGHT):continue
    if keydown(KEY_LEFT) and c==3 and f==0 and e>0:
      e-=1;c=2
      while keydown(KEY_LEFT):continue
    if keydown(KEY_LEFT) and c==3 and f==1 and e1>0:
      e1-=1;c=2
      while keydown(KEY_LEFT):continue
    if keydown(KEY_UP) and c==3:
      f=0;c=2
      while keydown(KEY_UP):continue
    if keydown(KEY_DOWN) and c==3:
      f=1;c=2
      while keydown(KEY_DOWN):continue
    if keydown(KEY_EXE):
      if c==0:c=2
      else:c=1
      while keydown(KEY_EXE):continue
    if keydown(KEY_OK) and c==3 and score1>=e*10:
      if f==0:d=e
      else:d1=e1
      c=2
      while keydown(KEY_OK):continue
    if keydown(KEY_OK) and c==0:
      while keydown(KEY_OK):continue
      break

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.