# toutnoirtoutblanc0.py

Created by florian-allard

Created on July 29, 2020

2.28 KB

```from kandinsky import *
from ion import *
from time import *
from random import randint
purple=(160,0,255)

def init():
global Jeu,x,y
Jeu=[randint(0,1) for i in range(9)]
x,y=100+45,100+45

for i in range(4):
fill_rect(100+30*i,100,1,91,'orange')
fill_rect(100,100+30*i,91,1,'orange')
remplissage()
curseur(x,y)

# Affichage du curseur
def curseur(x,y,couleur='orange'):
for k in range(2,5):
set_pixel(x-k,y,couleur)
set_pixel(x+k,y,couleur)
set_pixel(x,y-k,couleur)
set_pixel(x,y+k,couleur)

# Deplacement
def deplacement():
global x,y
dep=0
if keydown(KEY_LEFT):
curseur(x,y,get_pixel(x,y))
x=(x-30-101)%90+101
dep=1
elif keydown(KEY_RIGHT):
curseur(x,y,get_pixel(x,y))
x=(x+30-101)%90+101
dep=1
elif keydown(KEY_DOWN):
curseur(x,y,get_pixel(x,y))
y=(y+30-101)%90+101
dep=1
elif keydown(KEY_UP):
curseur(x,y,get_pixel(x,y))
y=(y-30-101)%90+101
dep=1
curseur(x,y)
while (keydown(KEY_LEFT) or keydown(KEY_RIGHT) or keydown(KEY_DOWN) or keydown(KEY_UP)) and dep==1:True

def remplissage():
global Jeu
for l in range(9):
couleur='white'
if Jeu[l]==1:
couleur=purple
fill_rect(101+30*(l%3),101+30*(l//3),29,29,couleur)

def appui():
global Jeu,x,y
rang=(x-115)//30+3*(y-115)//30
Jeu[rang]=1-Jeu[rang]
if rang-3>=0:
Jeu[rang-3]=1-Jeu[rang-3]
if rang-1>=0 and rang not in [3,6]:
Jeu[rang-1]=1-Jeu[rang-1]
if rang+1<=8 and rang not in [2,5]:
Jeu[rang+1]=1-Jeu[rang+1]
if rang+3<=8:
Jeu[rang+3]=1-Jeu[rang+3]

def fin():
global Jeu,mini
if sum(Jeu) in [0,9]:
draw_string("Gagné en "+str(nb)+" coup"+"s"*(nb>1),90,30,'blue')
if nb<mini:
mini=nb
draw_string("Appuyer sur EXE",90+5*len(str(nb)),50,purple)
draw_string("Record : ",220,130,'blue')
draw_string("   ",220+6*10,148)
draw_string(str(mini)+" coup"+"s"*(mini>1),220,148,'red')
sleep(1)
while not (keydown(KEY_EXE) or keydown(KEY_OK)):True
draw_string("                   ",90,30)
draw_string("                 ",90,50)
return True
return False

global x,y,Jeu
init()
nb=0
mini=1000
while True:
deplacement()
if keydown(KEY_EXE) or keydown(KEY_OK):
appui()
nb+=1
remplissage()
curseur(x,y)
if fin():
init()
nb=0```