1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
   |  
´# -*- coding: cp1252 -*-
 
def load_mots():
    with open('mots.txt', 'r') as f_mots:
        for l in f_mots:
            liste_mots.append(l.strip())
 
liste_mots = []
load_mots()
 
try:
    print("Bienvenu.\nPour quitter utilisez ctrl+c")
    while 1:
        # Gerer la liste
        if len(liste_mots) == 0:
            recharger = raw_input("Plus de mots dans la liste... Voulez vous la recharger ? (O/N) ")
            if recharger.lower == 'o':
                load_mots()
            else:
                print("Dommage... A bientot")
                break
        elif len(liste_mots) == 1:
            print("Formidable ! Dernier mots a trouver !")
            mots_a_trouver = liste_mots.pop()
        else:
            mots_a_trouver = liste_mots.pop(randrange(len(liste_mots)-1))
        nb_essai = len(mots_a_trouver)*1.5
        cache = '*'*len(mots_a_trouver)
        while nb_essai > 0:
            ...
except KeyboardInterrupt:
    print("\nA bientot !\n")
 
 
mots_a_trouver = "test"
cache = '*'*len(mots_a_trouver)
while 1:
    print("Mots a trouver : %s" % cache)
    print("Mots a trouver : %s" % mots_a_trouver)
    chr_to_test = raw_input("Donnez une lettre : ").lower()
    if chr_to_test == '':
        print("Dommage... Mots suivant")
        break
    elif chr_to_test in cache:
        print("Vous avez deja proposer cette lettre")
    elif chr_to_test in mots_a_trouver:
        for i, ch in enumerate(mots_a_trouver):
            if ch == chr_to_test:
                cache = cache[:i] + ch + cache[i+1:]
    if cache == mots_a_trouver:
        rejouer = raw_input("Bravo ! Mots suivant ? (o/n) ").lower()
        if rejouer != "o":
            print("Dommage, A bientot")
            break | 
Partager