black_or_white.py

Created by frablock

Created on June 21, 2022

815 Bytes

Un petit jeu, utilisez les flèches du clavier pour vous déplacer, et [ok] pour valider


from kandinsky import *;from time import *;from ion import *;from random import *
fr,ds,kd=fill_rect,draw_string,keydown
def pu(a,c="1",x=10,y=75,w=300,h=75):fr(x,y,w,h,(0,0,0));fr(x+1,y+1,w-2,h-2,c);ds(a,x+2,y+2,"0",c);ds("[ok]",x+2,y+h-20,"0",c)

def p(n,c):
 global m
 m,t=n,50
 fr(81+162*m-t//2,112-t//2,t,t,"red")
 fr(86+162*m-t//2,117-t//2,t-10,t-10,str(c))
 fr(81+162*(1-m)-t//2,112-t//2,t,t,str(1-d[m]))
def dr():
 global a,d
 a=randint(0,1)
 b=1-a
 d=[a,b]
 fr(0,0,325//2,225,str(a))
 fr(325//2,0,325//2,225,str(b))
g,s,m=0,0,0
while not kd(5) and not g:
 dr()
 ds(str(s),0,0)
 c=str(randint(0,1))
 p(m,c)
 while not kd(5):
  if kd(KEY_LEFT):p(0,c)
  if kd(KEY_RIGHT):p(1,c)
  if kd(KEY_OK):
   if str(d[m])==c:s+=1;break
   else:pu("GAME OVER\nScore : "+str(s));g=1;break
 sleep(0.2)