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 56 57 58 59 60 61 62 63
| import numpy as np
from tkinter import *
from random import *
fenetre = Tk()
M=np.zeros((11,11),int) #Création grille de bombes
for x in range(1,10):
for y in range(1,10):
M[x,y]=randint(1,10)
if M[x,y] > 1:
M[x,y] = 0
Blist = [[0 for k in range(1,10)] for i in range(1,10)]
for x in range(1,10): #Grille des boutons
tmp = []
for y in range(1,10):
tmp.append(Button(fenetre, text=' ', borderwidth=1,command=lambda x=x, y=y:appuie(x,y)).grid(row=x, column=y))
Blist.append(tmp)
def perdu():
fenetreperdu = Tk()
textperdu = Label(fenetreperdu,text='Vous avez perdu').pack()
boutonperdu = Button(fenetreperdu,text='Quitter',command=quit).pack()
def test(x,y):
nbomb=0
if M[x+1,y] == 1:
nbomb = nbomb + 1
if M[x+1,y-1] == 1:
nbomb = nbomb + 1
if M[x,y-1] == 1:
nbomb = nbomb + 1
if M[x-1,y-1] == 1:
nbomb = nbomb + 1
if M[x-1,y] == 1:
nbomb = nbomb + 1
if M[x-1,y+1] == 1:
nbomb = nbomb + 1
if M[x,y+1] == 1:
nbomb = nbomb + 1
if M[x+1,y+1] == 1:
nbomb = nbomb + 1
Blist [(x-1)][(y-1)].config(text=nbomb)
if testgg() == True:
gg()
def testgg():
return True
for x in range(1,10):
for y in range(1,10):
if M[x,y] == 0:
return False
def gg():
fenetregg = Tk()
textgg = Label(fenetreperdu,text='Vous avez gagné !').pack()
boutongg = Button(fenetreperdu,text='Quitter',command=quit).pack()
def appuie(x,y):
if M[x,y]== 1:
perdu()
else:
M[x,y] = 1
test(x,y) |
Partager