simon_game.py

Created by marius-layan

Created on February 05, 2024

3.25 KB

Voici un petit jeu nommé simon. une suite de couleur est affichée, retenez-la et reproduisez la grâce à vos touche allant de 1 à 9. A chaque fois que vous réussissez, un dernier carré de couleur vient se rajouter au précédentes (ok pour commencer la partie).


from random import *
from kandinsky import *
from ion import *
from time import *
def reset():
  fill_rect(0,0,320,222,'white');fill_rect(58,9,204,204,'black')
  for i in range(1,4):
    for j in range(1,4):fill_rect(66*i-4,66*j-53,64,64,color)
color=(255,255,255);reset()
while keydown(KEY_OK):continue
while keydown(KEY_OK)!=True:continue
b,c=0,0
while b==0:
  a,l,color=1,[[randint(1,3),randint(1,3)]],(255,255,255)
  while True:
    l.append([randint(1,3),randint(1,3)]);l1=[]
    for i in range(len(l)):fill_rect(66*l[i][0]-4,66*l[i][1]-53,64,64,'blue');sleep(0.4);fill_rect(66*l[i][0]-4,66*l[i][1]-53,64,64,'white');sleep(0.2)
    i=0
    while len(l1)!=len(l):
      if keydown(KEY_ONE):
        l1.append([1,3]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_ONE):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_TWO):
        l1.append([2,3]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_TWO):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_THREE):
        l1.append([3,3]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_THREE):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_FOUR):
        l1.append([1,2]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_FOUR):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_FIVE):
        l1.append([2,2]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_FIVE):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_SIX):
        l1.append([3,2]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_SIX):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_SEVEN):
        l1.append([1,1]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_SEVEN):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_EIGHT):
        l1.append([2,1]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_EIGHT):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
      if keydown(KEY_NINE):
        l1.append([3,1]);fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'blue')
        while keydown(KEY_NINE):continue
        fill_rect(66*l1[i][0]-4,66*l1[i][1]-53,64,64,'white');i+=1
    if l!=l1:
      color=(255,0,0);reset();sleep(1);break
    else:
      color=(0,255,0);reset();sleep(1);color=(255,255,255);reset()
  fill_rect(0,0,320,222,'black')
  draw_string("rejouer :",120,60,'yellow','black')
  draw_string("oui",145,90,'green','black')
  draw_string("non",145,120,'white','black')
  draw_string("score: "+str(len(l)),5,200,'yellow','black')
  while True:
    if keydown(KEY_UP):draw_string("oui",145,90,'green','black');draw_string("non",145,120,'white','black');b=0
    if keydown(KEY_DOWN):draw_string("oui",145,90,'white','black');draw_string("non",145,120,'green','black');b=1
    if keydown(KEY_OK):
      while keydown(KEY_OK):continue
      break
  if b==0:color=(255,255,255);reset()