synthkey.py

Created by schraf

Created on January 10, 2023

1.08 KB

Découvrez ma chaine YouTube (Python, JavaScript, calculatrices…)

Le principe est très simple, en une minute vous devez réaliser le score le plus élevé possible. Pour cela appuyez sur les touches 0, ., x10^x,Ans ou EXE en fonction des rectangles bleus qui apparaissent en bas de l’écran.

OK = Nombre d’appuis réussis et KO = Nombre d’appuis ratés.


from kandinsky import *
from random import random
from time import monotonic,sleep
from ion import *

P,DELAI,T=.4,.8,64
col=range(5)
def down(cases,p):
 cases.insert(0,[random()<p for _ in col])
 cases=cases[:-1]
 for l in range(8):
  coul=(0,0,255) if l==7 else (180,)*3
  for c in col:
   fill_rect(T*c,22+25*l,T-1,24,coul if cases[l][c] else (255,)*3)
 return cases
def action_joueur(cases,ok,ko):
 dep=monotonic()
 while True:
  for (i,k) in enumerate([KEY_ZERO,KEY_DOT,KEY_EE,KEY_ANS,KEY_EXE]):
   if keydown(k):
    if cases[7][i]==1:
     ok+=1;fill_rect(T*i,197,T-1,24,(0,255,0))
    elif cases[7][i]==0:
     ko+=1;fill_rect(T*i,197,T-1,24,(255,0,0))
    cases[7][i]=2
  if monotonic()-dep>DELAI:
   ko+=cases[7].count(1)
   return (ok,ko)
def aff(ok,ko):
 draw_string("OK: {}".format(ok),0,0)
 draw_string("KO: {}".format(ko),90,0)
 if ok+ko>0:
  draw_string("Score: {} %  ".format(int(100*ok/(ok+ko))),180,0)

cases=[[0 for _ in col] for _ in range(8)]
ok,ko=0,0
sleep(.2)
go=monotonic()
while monotonic()-go<60:
 cases=down(cases,P)
 (ok,ko)=action_joueur(cases,ok,ko)
 aff(ok,ko)

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.