jeu_allumettes_graph.py

Created by numworks

Created on March 30, 2022

1.31 KB

Touche de gauche pour enlever une allumette, touche du haut pour en enlever deux, touche de droite pour en enlever trois. Vous jouez à tour de rôle. Il ne faut pas prendre la dernière allumette !!


from math import *
from kandinsky import *
from ion import *
from time import *
from random import randint

def draw(nb, color, top):
  for i in range(nb):
    fill_rect(i*15+10,70,5,50,color)
    fill_rect(i*15+9,60,7,10,top)
brown=color(255,204,153)
red=color(255,0,0)
white=color(255,255,255)
allumettes=0
draw(20,brown,red)
while allumettes<19:
  while keydown(KEY_LEFT) or keydown(KEY_UP) or keydown(KEY_RIGHT):
    continue
  while True :
    draw_string("Enlevez 1, 2 ou 3 allumettes.",10,140)
    draw_string("L'ordinateur joue après vous.",10,160)
    draw_string("Gauche=1 ; haut=2 ; droite=3",10,180)
    if keydown(KEY_LEFT):
      allumettes+=1
      break
    else:
      if keydown(KEY_UP):
        allumettes+=2
        break
      else:
        if keydown(KEY_RIGHT):
          allumettes+=3
          break
  draw(allumettes,white,white)
  sleep(0.3)
  if allumettes==19:
    draw_string("Vous avez gagné",100,30)
  else:
    if (20-allumettes)%4==3:
      allumettes+=2
    else:
      if (20-allumettes)%4==0:
        allumettes+=3
      else:
        if (20-allumettes)%4==2:
          allumettes+=1
        else:
          allumettes+=randint(1,3 if allumettes<17 else 20-allumettes-1)
    draw(allumettes,white,white)
    if allumettes==19:
      draw_string("Vous avez perdu",100,30)

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