Ce mini jeu consiste à attraper des carrés apparaissant aléatoirement sur l’écran. Les carrés bleus rapportent uniquement des points, les carrés verts vous donnent plus de maniabilité, les carrés jaunes attirent les carrés aux alentours et les carrés violets activent l’ensembles des bonus précédents et activent un bonus de carrés bleus.
ATTENTION : Les éléments de ce jeu peuvent clignoter très rapidement à cause du système de rendu de la calculatrice ! Vous pouvez limiter ces clignotements en désactivant les particules et l’update des carrés dans les options du jeu.
Vous pouvez naviguer dans le menu principal avec les flèches et sélectionner une option avec “ok”. Pour quitter les options, utilisez “flèche gauche” (et non pas “retours” qui kill le programme). Vous pouvez arrêter la partie avec le bouton “effacer”. Il existe 4 modes de jeu sélectionnables à la fin des options.
Il n’y a pas de système de sauvegarde car il est impossible d’utiliser la fonction “open()”.
Petite info : le programme a été entièrement tapé directement sur la calculatrice …
from kandinsky import * from ion import * from time import * from random import * btnc1=(100,0,255) btnc2=(150,50,150) gms=["libre","chrono 100","max 1min","max 2min"] def dbtn(x,y,w,h,t,s): fill_rect(x,y,w+2,h+2,(255,255,255)) fill_rect(x+4,y+4,w,h,(50,50,50)) if s: fill_rect(x+2,y+2,w,h,btnc2) draw_string(t,x+w//2-len(t)*5+2,y+h//2-6,(255,255,255),btnc2) else: fill_rect(x,y,w,h,btnc1) draw_string(t,x+w//2-len(t)*5,y+h//2-8,(255,255,255),btnc1) def dswtch(x,y,t,s,a): fill_rect(x,y,80,30,(255,255,255)) if s: fill_rect(x,y,80,30,(50,50,50)) fill_rect(x+3,y+3,74,24,(150,150,150)) if a: fill_rect(x+53,y+3,24,24,(0,255,0)) else: fill_rect(x+3,y+3,24,24,(255,0,0)) draw_string(t,x+90,y+6) def dsq(i): if i[3]==1: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(0,255,0)) elif i[3]==2: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(255,255,20)) elif i[3]==3: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(200,0,200)) else: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(0,0,255)) class Game: def __init__(self): self.state=1 self.btns=0 self.lbtns=-1 self.swtch=0 self.lswtch=-1 self.acpart=1 self.gm=0 self.updts=1 self.px=0 self.py=0 self.spx=0 self.spy=0 self.s=0.4 self.bs=0.4 self.ms=10 self.bns=0 self.bnm=0 self.bnl=0 self.sq=[] self.part=[] self.score=0 self.chrono=0 def gtick(self): pt=monotonic() adding=False if keydown(KEY_RIGHT): self.spx+=self.s adding=True if keydown(KEY_LEFT): self.spx-=self.s adding=True if keydown(KEY_DOWN): self.spy+=self.s adding=True if keydown(KEY_UP): self.spy-=self.s adding=True if self.spx>self.ms: self.spx=self.ms if self.spy>self.ms: self.spy=self.ms if self.spx<-self.ms: self.spx=-self.ms if self.spy<-self.ms: self.spy=-self.ms moved=False if self.spx or self.spy: moved=True if moved: fill_rect(int(self.px),int(self.py),32,32,(255,255,255)) self.px+=self.spx self.py+=self.spy if self.px>288: self.px=288 self.spx=-self.spx if self.px<0: self.px=0 self.spx=-self.spx if self.py>190: self.py=190 self.spy=-self.spy if self.py<0: self.py=0 self.spy=-self.spy if not adding: if self.spx>0: self.spx-=min(self.spx,self.s) elif self.spx<0: self.spx+=min(-self.spx,self.s) if self.spy>0: self.spy-=min(self.spy,self.s) elif self.spy<0: self.spy+=min(-self.spy,self.s) for i in self.sq.copy(): if self.px<i[0]+i[2] and self.py<i[1]+i[2] and self.px+32>i[0] and self.py+32>i[1]: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(255,255,255)) self.sq.remove(i) self.score+=1 if self.acpart: for _ in range(10): si=randint(2,i[2]//2) self.part.append([randint(int(i[0]),int(i[0])+max(i[2]-si,0)),randint(int(i[1]),int(i[1])+max(i[2]-si,0)),si,random()-0.5,random()-0.5,0,randint(5,80),i[3]]) if i[3]==1: self.bns=6 if i[3]==2: self.bnm=6 if i[3]==3: self.bns=5 self.bnm=5 self.bnl=5 elif self.updts: dsq(i) if self.bns>0: self.s=1.4 if self.bnm>0: for i in self.sq: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(255,255,255)) i[0]+=((self.px+16)-i[0])/16 i[1]+=((self.py+16)-i[1])/16 dsq(i) for i in self.part.copy(): fill_rect(int(i[0]),int(i[1]),i[2],i[2],(255,255,255)) i[0]+=i[3] i[1]+=i[4] i[5]+=1 if i[5]>=i[6]: self.part.remove(i) else: tv=i[5]/i[6] if i[7]==1: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(255*tv,255,255*tv)) elif i[7]==2: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(255,255,20+235*tv)) elif i[7]==3: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(200+55*tv,255*tv,200+55*tv)) else: fill_rect(int(i[0]),int(i[1]),i[2],i[2],(255*tv,255*tv,255)) fill_rect(int(self.px),int(self.py),32,32,(255,0,0)) sleep(1/40-(monotonic()-pt)) self.chrono+=1/40 if self.bns>0: self.bns-=1/40 if self.bnm>0: self.bnm-=1/40 if self.bnl>0: self.bnl-=1/40 if self.bns<=0: self.s=self.bs if self.bnl>0 and randint(0,10)==2 and len(self.sq)<21: sqwh=randint(5,25) x,y=randint(0,320-sqwh),randint(0,222-sqwh) t=0 tp=random() self.sq.append([x,y,sqwh,t]) fill_rect(x,y,sqwh,sqwh,(0,0,255)) if randint(0,40)==2 and len(self.sq)<21: sqwh=randint(5,25) x,y=randint(0,320-sqwh),randint(0,222-sqwh) t=0 tp=random() if tp<0.1: t=1 elif 0.1<tp<0.17: t=2 elif 0.17<tp<0.19: t=3 self.sq.append([x,y,sqwh,t]) if t==1: fill_rect(x,y,sqwh,sqwh,(0,255,0)) if t==2: fill_rect(x,y,sqwh,sqwh,(255,255,20)) if t==3: fill_rect(x,y,sqwh,sqwh,(200,0,200)) else: fill_rect(x,y,sqwh,sqwh,(0,0,255)) draw_string("score: "+str(self.score),5,5) mi=str(int(self.chrono//60)) se=str(int(self.chrono%60)) draw_string("chrono: "+"0"*max(2-len(mi),0)+mi+":"+"0"*max(2-len(se),0)+se,5,22) if self.gm==1 and self.score>=100: self.score=100 self.state=3 fill_rect(0,0,330,222,(255,255,255)) if (self.gm==2 and self.chrono>=60) or (self.gm==3 and self.chrono>=120): self.state=3 fill_rect(0,0,330,222,(255,255,255)) if keydown(KEY_BACKSPACE): self.state=3 fill_rect(0,0,330,222,(255,255,255)) sleep(0.2) def mtick(self): draw_string("Squares",125,30,(0,0,0),(255,255,255)) if self.lbtns!=self.btns: dbtn(110,100,100,30,"jouer",self.btns==0) dbtn(110,150,100,30,"obtions",self.btns==1) self.lbtns=self.btns if keydown(KEY_DOWN): self.btns+=1 sleep(0.2) if keydown(KEY_UP): self.btns-=1 sleep(0.2) btnbr=2 if self.btns>=btnbr: self.btns=0 if self.btns<0: self.btns=btnbr-1 if keydown(KEY_OK): if self.btns==0: self.state=0 if self.btns==1: self.state=2 fill_rect(0,0,330,222,(255,255,255)) self.swtch=0 self.lswtch=-1 sleep(0.2) def otick(self): mo=False if self.lswtch!=self.swtch: mo=True if keydown(KEY_DOWN): self.swtch+=1 mo=True sleep(0.2) if keydown(KEY_UP): self.swtch-=1 mo=True sleep(0.2) stchn=3 if self.swtch<0: self.swtch=stchn-1 if self.swtch>=stchn: self.swtch=0 if keydown(KEY_OK): if self.swtch==0: self.acpart=not self.acpart elif self.swtch==1: self.updts=not self.updts elif self.swtch==2: self.gm+=1 if self.gm>=len(gms): self.gm=0 mo=1 sleep(0.2) if keydown(KEY_LEFT): self.state=1 fill_rect(0,0,330,222,(255,255,255)) self.btns=0 self.lbtns=-1 sleep(0.2) if mo: dswtch(10,10,"particules ?",self.swtch==0,self.acpart) dswtch(10,50,"rafraichir carres ?",self.swtch==1,self.updts) dbtn(10,90,100,30,gms[self.gm],self.swtch==2) draw_string("mode de jeu ?",120,96) self.lswtch=self.swtch def ftick(self): draw_string("score: "+str(self.score),70,90) mi=str(int(self.chrono//60)) se=str(int(self.chrono%60)) draw_string("temps: "+"0"*max(2-len(mi),0)+mi+":"+"0"*max(2-len(se),0)+se,70,110) if keydown(KEY_OK): fill_rect(0,0,330,222,(255,255,255)) self.state=1 sleep(0.2) self.btns=0 self.lbtns=-1 self.px=0 self.py=0 self.spx=0 self.spy=0 self.s=0.4 self.ms=10 self.bns=0 self.bnm=0 self.bnl=0 self.sq=[] self.part=[] self.score=0 self.chrono=0 def loop(self): while True: if self.state==1: self.mtick() elif self.state==0: self.gtick() elif self.state==2: self.otick() elif self.state==3: self.ftick() game=Game() game.loop()