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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
from random import *
from tkinter import *
import webbrowser
from tkinter import messagebox
from time import sleep
# fenetre démineur
fenetre = Tk()
fenetre.title("démineur")
fenetre.geometry("430x465")
fenetre.minsize(410, 465)
fenetre.config(background='#FFFFFF')
# fenetre1
window = Tk()
window.title("démineur")
window.geometry("1080x720")
window.minsize(1080, 720)
window.config(background='#FFFFFF')
#fenetre score board
score_board = Tk()
score_board.title("démineur")
score_board.geometry("1080x720")
score_board.minsize(1080, 720)
score_board.config(background='#FFFFFF')
#sous fentre 1
frame = Frame(window, bg='#FFFFFF')
#class Application(fenetre):
# global ligne,colonne
# def __init__(self, master=None):
# super().__init__(master)
# self.master = master
# self.grid()
# self.create_widgets()
#
# def create_widgets(self):
# self.hi_there = fenetre.Button(self)
# self.hi_there["text"] = "mine?"
# self.hi_there["command"] = self.destroy
# self.hi_there.grid(row=ligne,column=colonne)
#
# def destroy(self):
# global ligne,colonne
# self.grid_forget()
def open_github():
webbrowser.open_new("https://github.com")
def fermer_fenetre():
window.quit()
sleep(1)
fenetre.mainloop()
# fenetre 1 bouton et texte
textedebut = Label(frame, text="bienvenue sur le démineur", font=("Courrier", 40), bg='#FFFFFF')
textedebut.pack(expand=YES)
credit = Label(frame, text="réaliser par Olivier", font=("Courrier", 20), bg='#FFFFFF')
credit.pack(expand=YES)
gt_buttion = Button(frame, text="ouvrir github", font=("Courrier", 20), bg='#FFFFFF', command=open_github)
gt_buttion.pack(side=BOTTOM, pady=100)
quit_buttion = Button(frame, text="quitter crédit", font=("Courrier", 20), bg='#FFFFFF', command=fermer_fenetre)
quit_buttion.pack(side=BOTTOM, pady=50)
frame.pack(expand=YES)
#position mine
xmin1 = randint(0, 18)
ymin1 = randint(0, 9)
xmin2 = randint(0, 18)
ymin2 = randint(0, 9)
xmin3 = randint(0, 19)
ymin3 = randint(0, 9)
xmin4 = randint(0, 18)
ymin4 = randint(0, 9)
print(xmin1,ymin1,xmin2,ymin2,xmin3,ymin3,xmin4,ymin4)
nb = 1
tab=[Button]*200
score=0
#score ( case déactiver avant de toucher une mine )
def point():
global score
score=score+1
return score
# affiche score précédant dans scoreboard
def score_precedent():
with open("score.txt","a+") as file:
nb_ligne= file.readlines()
tab_score = [0]*len(nb_ligne)
for x in range(len(nb_ligne)):
tab_score[x]=int(file.read())
print(nb_ligne,"&bc")
tab_score.sort(reverse = True)
for p in range(len(nb_ligne)):
scoreint=str(tab_score)
Label(score_board,text="{} avec le score de {}".format(p,scoreint))
file.close()
score_precedent()
def minetoucher():
print("vous avez perdu")
global score
messagebox.showerror(title="démineur", message=" tu as perdu \n partie termier !\n ton score est de {}".format(score))
sleep(5)
score=str(score)
with open("score.txt","a+") as file:
file.write(score+ "\n")
print(score)
file.close()
window.destroy()
fenetre.destroy()
return 0
tabnb=[[0,0]]*191
tabm=[0]*191
i=1
z=1
e=1
def disparait(i):
tab[i]['text']='rien'
def change_nom_proche(none):
globals()
none.config(text="proche")
# creation grille button dans une matrice
i=1
for ligne in range(19):
for colonne in range(10):
if ligne == xmin1 and colonne == ymin1 or ligne == xmin2 and colonne == ymin2 or ligne == xmin3 and colonne == ymin3 or ligne == xmin4 and colonne == ymin4:
tab[i]=Button(fenetre, text="mine0", command=lambda : tab[i].grid_forget and point,bg='#111111')
tab[i].grid(row=ligne, column=colonne)
print("a", i)
elif ligne == xmin1 - 1 or ligne == xmin1 + 1 and colonne == ymin1 - 1 or colonne == ymin1 + 1 and ligne == xmin2 - 1 or ligne == xmin2 + 1 and colonne == ymin2 - 1 or colonne == ymin2 + 1 and ligne == xmin3 - 1 or ligne == xmin3 + 1 and colonne == ymin3 - 1 or colonne == ymin3 + 1 and ligne == xmin4 - 1 or ligne == xmin4 + 1 and colonne == ymin4 - 1 or colonne == ymin4 + 1:
tab[i]=Button(fenetre, text="mine?",command=lambda : tab[i].grid_forget and point)
tab[i].grid(row=ligne, column=colonne)
print("2",i)
else:
tab[i] = Button(fenetre, text="mine?", command=lambda: tab[i].grid_forget and print(i))
tab[i].grid(row=ligne,column=colonne)
print(i)
i=i+1
window.mainloop() |
Partager