toutnoirtoutblanc.py

Created by florian-allard

Created on July 29, 2020

2 KB

Jeu du tout noir ou tout blanc. Le but est de modifier la couleur des cases en appuyant sur EXE lorsqu’on est sur une case afin d’avoir toute la grille blanche ou toute la grille coloriée.


from kandinsky import *
from ion import *
from random import randint
kd = keydown
KE = KEY_EXE
KO = KEY_OK
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
  dx = kd(KEY_RIGHT)-kd(KEY_LEFT)
  dy = kd(KEY_DOWN)-kd(KEY_UP)
  curseur(x,y,get_pixel(x,y))
  x = (x+30*dx-101)%90+101
  y = (y+30*dy-101)%90+101
  curseur(x,y)
  while (dx != 0 or dy != 0) and (kd(KEY_LEFT) or kd(KEY_RIGHT) or kd(KEY_DOWN) or kd(KEY_UP)):True

def remplissage():
  for l in range(9):
    fill_rect(101+30*(l%3),101+30*(l//3),29,29,(255-95*Jeu[l],255-255*Jeu[l],255))

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

def fin():
  global mini
  if sum(Jeu) in [0,9]:
    draw_string("Gagné en "+str(nb)+" coup"+"s"*(nb>1),85-5*len(str(nb))+5*(nb<2),30,'blue')
    mini = min(nb,mini)
    draw_string("Appuyer sur EXE",85,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')
    while not (kd(KE) or kd(KO)):True
    draw_string(" "*25,70,30)
    draw_string(" "*17,80,50)
    return True
  return False

init()
nb = 0
mini = 1000
while True:
  while not (kd(KE) or kd(KO)):
    deplacement()
  appui()
  nb += 1
  remplissage()
  curseur(x,y)
  while kd(KE) or kd(KO):True
  if fin():
    init()
    nb = 0
    while kd(KE) or kd(KO):True

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 cookies policy.