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
| def cmd_ok():
"""fonction qui affiche et initialise la fenêtre de jeu"""
global goal, hunter, size
ligne = lvar.get()
colonne = cvar.get()
tresor = tvar.get()
size=(colonne,ligne)
goal = (randrange(size[0]), randrange(size[1]))
if(ligne<=20 and ligne >=5 and colonne >=5 and colonne<=20):
hunter,fnt1 = {0:Tk()},'Arial 12'
hunter[1] = Frame(hunter[0])
hunter[1].pack(side=TOP,fill = BOTH , padx=2,pady=2)
hunter[11] = Button(hunter[1], font=fnt1, text="Règles du Jeu", command=cb_regles)
hunter[11].pack(side=LEFT,fill=BOTH)
hunter[12]= Label(hunter[1], font=fnt1, text="Vous devez trouver %d trésor(s)" % (tresor))
hunter[12].pack(side=LEFT, fill=BOTH, padx=2,pady=2)
hunter[2] = Frame(hunter[0])
hunter[2].pack(side=TOP, fill=BOTH, expand=YES, padx=2, pady=2)
for n in range(size[0]*size[1]):
c = divmod(n, size[1])
hunter[c] = Button(hunter[2], font=fnt1, bg=colors[5], width=1, height=1,
command=lambda cell=c: cb_cell(cell))
hunter[c].grid(column=c[0], row=c[1], sticky=N+E+W+S)
for n in range(size[0]): hunter[2].columnconfigure(n, weight=1)
for n in range(size[1]): hunter[2].rowconfigure(n, weight=1)
hunter[3] = Frame(hunter[0])
hunter[3].pack(side=TOP, fill=BOTH)
hunter[31] = Button(hunter[3], font=fnt1, text="Recommencer", command=cb_reset)
hunter[31].pack(side=RIGHT, fill=BOTH) |
Partager