wordlefix.py

Created by maelg0000

Created on March 15, 2026

3.44 KB


from math import *
from kandinsky import *
from ion import *
from time import *

attempts=6
#MOT=input("Choisit le mot: ")
MOT="pomme"
MOT=MOT.upper()

lmot=len(MOT)
invlettres={}
for char2 in MOT:
  if char2 not in invlettres:
    invlettres[char2]=1
  else:
    invlettres[char2]+=1

cw=10
ch=18
def g():
  x=10
  y=10
  ec=22
  epais=2
  for i in range(6):
    for i in range(lmot):
      fill_rect(x,y,cw+epais*2,ch+epais*2,color(80,90,80))
      x+=ec
    y+=30
    x=10

l_noires=[]
l_oranges=[]
l_vertes=[]
noir=color(0,0,0)
orange=color(250,120,0)
vert=color(0,150,0)
blanc=color(255,255,255)

def show_lettres():
  lettres=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  x=130
  y=60
  for i in range(len(lettres)):
      char = lettres[i].upper()
      if char in l_vertes:
        draw_string(lettres[i],x,y,blanc,vert)
      elif char in l_oranges:
        draw_string(lettres[i],x,y,blanc,orange)
      elif char in l_noires:
        draw_string(lettres[i],x,y,color(160,160,160),noir)
      else:
        draw_string(lettres[i],x,y,blanc,color(80,90,80))
      if x>290:
        y+=21
        x=130
      x+=13

def writetoline(line,txt,couleurs=None):
  if couleurs is None:
    for i in range(lmot):
      char = txt[i] if i < len(txt) else " "
      draw_string(char,12+22*i,12+line*30,blanc,color(80,90,80))
  else:
    for i in range(lmot):
      char = txt[i]
      bg = couleurs[i]
      col = color(160,160,160) if bg == noir else blanc
      draw_string(char, 12+22*i, 12+line*30, col, bg)
      sleep(0.1)

# print('Utilise game("mot") pour lancer la partie\nle mot choisi doit avoir 5 lettres')

def game(mot=""):
  if mot=="":
    print("Tu doit mettre un mot pour \nque le jeu se lance")
    return
  
  fill_rect(0,0,320,222,color(60,60,60))
  g()
  show_lettres()
  line=0
  txt=""
  touches={18:"A",19:"B",20:"C",21:"D",22:"E",23:"F",24:"G",25:"H",26:"I",27:"J",28:"K",29:"L",30:"M",31:"N",32:"O",33:"P",34:"Q",36:"R",37:"S",38:"T",39:"U",40:"V",42:"W",43:"X",44:"Y",45:"Z"}
  
  while True:
    for touche,char in touches.items():
      if keydown(touche) and len(txt)<lmot:
        txt+=char
        writetoline(line,txt)
        while keydown(touche): pass
        
    if keydown(KEY_BACKSPACE) and len(txt)>0:
      txt=txt[:-1]
      writetoline(line,txt)
      while keydown(KEY_BACKSPACE): pass

    if keydown(KEY_OK) or keydown(KEY_EXE):
      if len(txt)==lmot: #ddddd
        inv2 = invlettres.copy()
        res_cols = [noir] * lmot
        
        for i in range(lmot):
          if txt[i] == mot[i]:
            res_cols[i] = vert
            inv2[txt[i]] -= 1
            if txt[i] not in l_vertes: l_vertes.append(txt[i])

        for i in range(lmot):
          if res_cols[i] != vert:
            if txt[i] in mot and inv2[txt[i]] > 0:
              res_cols[i] = orange
              inv2[txt[i]] -= 1
              if txt[i] not in l_vertes and txt[i] not in l_oranges: l_oranges.append(txt[i])
            else:
              if txt[i] not in l_vertes and txt[i] not in l_oranges and txt[i] not in l_noires:
                l_noires.append(txt[i])
        
        writetoline(line,txt,res_cols)
        show_lettres()
        
        if txt==mot:
          draw_string("GAGNE!",200,110,vert,blanc)
          return
        
        line+=1
        if line == 6:
          draw_string("PERDU!",200,110,noir,orange)
          draw_string(mot,200,130,blanc,noir)
          return
        txt=""
        while keydown(KEY_OK) or keydown(KEY_EXE): pass

game(MOT)

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.