# rubpix.py

Created by schraf

Created on September 10, 2021

1.75 KB

Explications en vidéo ici

```from random import choice
from kandinsky import fill_rect,draw_string
from ion import *
from time import sleep

JEU = { KEY_ZERO:[6,7,8], KEY_ONE:[3,4,5], KEY_FOUR:[0,1,2],\
KEY_FIVE:[0,3,6], KEY_SIX:[1,4,7], KEY_MULTIPLICATION:[2,5,8],\
KEY_DIVISION:[2,1,0], KEY_MINUS:[5,4,3], KEY_EXE:[8,7,6],\
KEY_DOT:[6,3,0], KEY_EE:[7,4,1], KEY_ANS:[8,5,2]}

TOUCHES = list(JEU.keys())+[KEY_BACKSPACE]

COUL = [(0,0,0),(255,0,0),(0,255,0),(0,0,255),(255,0,255),(0,255,255)]

def melange(pos, perm):
finale = list(pos)
for k in range(3):
finale[perm[k]] = pos[perm[(k + 1) % 3]]
aff_cube(finale,True,perm)
return finale

def aff_cube(pos, gauche = True, plage = range(9)):
[mx,my,t] = [20,20,60] if gauche else [220,80,30]
for i in plage:
fill_rect(mx + t * (i % 3), my + t * (i // 3), t - 2, t - 2, pos[i])

def key(t):
while True:
for k in t:
if keydown(k): return k

def go(niveau = 2):
while True:
pos_final = [choice(COUL) for i in range(9)]
draw_string("NIV "+str(niveau),230,40,(0,0,0),(255,255,255))
while True:
pos_melange = list(pos_final)
for i in range(niveau // 2):
pos_melange = melange(pos_melange, choice(list(JEU.values())))
if pos_final != pos_melange: break
pos_depart = list(pos_melange)
aff_cube(pos_final, False)
aff_cube(pos_melange)
while pos_final != pos_melange:
sleep(.2)
t = key(TOUCHES)
if t != KEY_BACKSPACE:
pos_melange = melange(pos_melange,JEU[t])
else:
pos_melange = list(pos_depart)
aff_cube(pos_melange)
aff_cube(pos_final)
niveau += 1

go(2)```