Inspiré du jeu d'infogramme pour Thomson TO8, mon code propose différents textes cryptés qu'il faut décoder à l'aide d'indices.
Pour éviter de surcharger l'archive zip, je n'ai inclus qu'un seul texte, mais il est possible d'en ajouter une infinitée via l'utilitaire joint(fichier ajouter.py)
Pour les plus nostalgiques d'entre vous, quelques bons sites:
http://nostalgies.thomsonistes.org/
http://dcmoto.free.fr/
http://dcmoto.free.fr/prog/000/index.html
Source / Exemple :
# -*- coding: cp1252 -*-
# Les contes de Monte Crypto est un jeu pour Thomson TO8 et suppérieurs.
# Je m'en suis inspirer pour écrire ce petit jeu ludique et estival ;)
# Amaury
from Tkinter import *
import os
import time
import tkFont
import random
import tkMessageBox
import winsound
os.chdir("source")
lettres=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
LETTRES=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
points=0
def GUI():
global texte,root,bou1,bou2,bou3,bou4,img,LETTRES,entrees,affichage,ind
root=Tk()
root.title("Les Contes de Monte Crypto")
police=tkFont.Font(family="times", size=20, weight=NORMAL)
police2=tkFont.Font(family="times", size=20, weight=NORMAL)
police3=tkFont.Font(family="symbol", size=20, weight=NORMAL)
police4=tkFont.Font(family="symbol", size=20, weight=NORMAL)
police5=tkFont.Font(family="times", size=10, weight=NORMAL)
img=PhotoImage(file="start.gif")
can=Label(root,image=img)
bou1=Button(root,text="Dévoiler indice 1",font=police5)
bou2=Button(root,text="Dévoiler indice 2",font=police5)
bou3=Button(root,text="Dévoiler indice 3",font=police5)
bou4=Button(root,text="Dévoiler indice 4",font=police5)
lst=Listbox(root,width=30,height=47,bg="aquamarine",fg="blue")
affichage=Label(root,text="Votre score : 0",font=police2)
texte=Text(root,width=46,height=24,font=police,fg="blue",bg="black",state="normal")
ind=Text(root,width=30,height=6,font=police4,fg="blue",bg="black",state="normal")
texte.tag_config("min",foreground="green",font=police)
texte.tag_config("maj",foreground="red",font=police3)
ind.tag_config("min",foreground="green",font=police2)
ind.tag_config("maj",foreground="red",font=police4)
bou1.configure(command=lambda ar1=0, ar2=bou1 : Devoiler (ar1,ar2))
bou2.configure(command=lambda ar1=2, ar2=bou2 : Devoiler (ar1,ar2))
bou3.configure(command=lambda ar1=4, ar2=bou3 : Devoiler (ar1,ar2))
bou4.configure(command=lambda ar1=6, ar2=bou4 : Devoiler (ar1,ar2))
lst.bind("<Double-1>",lambda ar1 , ar2=lst : Load(ar1,ar2))
a=30
b=1
c=0
entrees={}
for i in LETTRES:
Label(root,text=i+":", font=police4,fg="red").grid(row=a,column=b)
entrees[i]=Entry(root,width=2)
entrees[i].grid(row=a,column=b+1)
entrees[i].bind("<Return>",lambda ar1 , ar2=i : Decoder(ar1,ar2))
if (c==12):
a=31
b=1
else:
b+=2
c+=1
fichier=open("liste",'r')
temp=fichier.read()
fichier.close()
temp=temp.split('\n')
for i in temp:
lst.insert(END,i)
can .grid(row=1,column=0)
bou1.grid(row=2,column=0)
bou2.grid(row=3,column=0)
bou3.grid(row=4,column=0)
bou4.grid(row=5,column=0)
texte.grid(row=1,column=1,rowspan=29,columnspan=26)
lst.grid(row=0,column=30,rowspan=30)
affichage.grid(row=6,column=0)
ind.grid(row=7,column=0)
root.mainloop()
def Devoiler(indice,bouton):
global indices,etat,points,ind,LETTRES,lettres
ind.configure(state="normal")
temp=indices[indice] + " : " + indices[indice+1]
temp=temp.replace('\n','')
etat[indice/2]=1
points-=10
bouton.configure(state="disable")
for i in temp:
if i in LETTRES:
ind.insert(END,i,"maj")
else:
ind.insert(END,i,"min")
ind.insert(END,'\n')
ind.configure(state="disable")
Update()
def Load(e,liste):
global indices,contenu,img,titre,bou1,bou2,bou3,bou4,texte,flag,entrees,LETTRES,etat,attendu,courant,ind
texte.configure(state="normal")
etat=[0,0,0,0]
ind.configure(state="normal")
ind.delete(0.0,END)
ind.configure(state="disable")
attendu,courant=0,0
indices=[]
flag=True
path=liste.get(liste.curselection())
fichier=open(path,'r')
titre=path
titre=titre.replace('\n','')
root.title("Les Contes de Monte Crypto: " + titre)
img.configure(file=str(path+'.gif'))
a=0
while (a<8):
indices.append(fichier.readline())
a+=1
a=1
while(a<9):
indices[a]=Encoder(indices[a])
a+=2
contenu=fichier.read()
texte.delete(0.0,END)
temp=Encoder(contenu)
for i in temp:
if i in LETTRES:
texte.insert(END,i,"maj")
else:
texte.insert(END,i,"min")
bou1.configure(text="Dévoiler indice 1",state="normal")
bou2.configure(text="Dévoiler indice 2",state="normal")
bou3.configure(text="Dévoiler indice 3",state="normal")
bou4.configure(text="Dévoiler indice 4",state="normal")
temp=texte.get(0.0,END)
for i in LETTRES:
if i in temp:
entrees[i].configure(state="normal",bg="blue")
attendu+=1
else:
entrees[i].configure(state="disable")
fichier.close()
texte.configure(state="disable")
def Encoder(texte):
global lettres,flag,tableau
if flag:
tableau=CreerTableCodage()
flag=False
a=0
for i in lettres:
texte=texte.replace(i,tableau[a])
a+=1
return texte
def Update():
global points,affichage,indices,etat,root,attendu,courant
root.update()
if courant==attendu:
tkMessageBox.showinfo(title="Félicitation",message="""Félicitation!
Vous avez terminé le niveau.""")
winsound.PlaySound('SystemExclamation',winsound.SND_ASYNC)
points+=20
courant+=1
affichage.configure(text="Votre score : " + str(points))
def Decoder(e,lettre):
global entrees,texte,root,decode,indices,points,courant,ind,lettres,LETTRES
temp=texte.get(0.0,END)
texte.configure(state="normal")
try:
new=entrees[lettre].get()
if (decode[new]==lettre):
temp=temp.replace(lettre,new)
entrees[lettre].configure(state="disable")
courant+=1
a=1
while(a<9):
indices[a]=indices[a].replace(lettre,new)
a+=2
texte.delete(0.0,END)
for i in temp:
if i in lettres:
texte.insert(END,i,"min")
elif i in LETTRES:
texte.insert(END,i,"maj")
else:
texte.insert(END,i)
points+=5
winsound.PlaySound('SystemAsterisk',winsound.SND_ASYNC )
else:
points-=5
winsound.PlaySound('SystemHand',winsound.SND_ASYNC)
Update()
entrees[lettre].configure(bg="orange")
entrees[lettre].delete(0,END)
except KeyError:
pass
temp=ind.get(0.0,END)
ind.configure(state="normal")
try:
new=entrees[lettre].get()
if (decode[new]==lettre):
temp=temp.replace(lettre,new)
entrees[lettre].configure(state="disable")
a=1
while(a<9):
indices[a]=indices[a].replace(lettre,new)
a+=2
ind.delete(0.0,END)
for i in temp:
if i in lettres:
ind.insert(END,i,"min")
elif i in LETTRES:
ind.insert(END,i,"maj")
else:
ind.insert(END,i)
except KeyError:
pass
Update()
texte.configure(state="disable")
ind.configure(state="disable")
def CreerTableCodage():
global decode,lettres
decode={}
dispo=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
table=[]
a=0
while (a<26):
ind=random.randint(0,len(dispo)-1)
table.append(dispo[ind])
decode[lettres[a]]=dispo[ind]
del (dispo[ind])
a+=1
return table
GUI()
Conclusion :
Ce code m'a permis de me replonger dans la programmation d'interfaces graphiques, avec notamment la découverte du widget Text.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.