Skip to content

Instantly share code, notes, and snippets.

@HuproZ
Created November 14, 2015 15:57
Show Gist options
  • Save HuproZ/a5cc561c7c641caefeba to your computer and use it in GitHub Desktop.
Save HuproZ/a5cc561c7c641caefeba to your computer and use it in GitHub Desktop.
import time, os
from Tkinter import *
from math import *
import random
from tkMessageBox import *
import pygame
#####################################################
countdown=True
c2=True
c3=True
pygame.mixer.init()
def new():
photomdr = PhotoImage(file="explosion.gif")
btnrejouer= PhotoImage(file="bouton_rejouer.gif")
bombe= PhotoImage(file="bombe1.gif")
########################################################################### Decomptes+résultats
def explosion():
canvasvrai= Canvas(fen1, width=879, height=660)
canvasvrai.grid(row=0, column=0)
canvasvrai.create_image(440, 330, image=photomdr)
btn6=Button(fen1, image=btnrejouer, relief="flat", borderwidth=0, highlightthickness=1, command=recommencer)
btn6.place(x=400,y=500)
def decompte(label, count=10):
label.config(text="{:.2f}".format(count))
if count > 0 and countdown:
fen1.after(10,decompte, *(label, count-0.01))
if count<0.15:
lab4.configure(text="Parfait", bg="green")
if 0.2<count<0.4:
lab4.configure(text="Peut mieux faire", bg="orange")
if count>0.4:
lab4.configure(text="Mauvais timing",bg="red")
if count==0 or count<0:
explosion()
pygame.mixer.music.stop()
pygame.mixer.music.load( "explosion.wav" )
pygame.mixer.music.play(0)
def decompte2(label, count=10):
label.config(text="{:.2f}".format(count))
if count > 0 and c2:
fen1.after(10,decompte2, *(label, count-0.01))
if count<0.15:
lab5.configure(text="Parfait", bg="green")
if 0.2<count<0.4:
lab5.configure(text="Peut mieux faire", bg="orange")
if count>0.4:
lab5.configure(text="Mauvais timing", bg="red")
if count==0 or count<0:
explosion()
pygame.mixer.music.stop()
pygame.mixer.music.load( "explosion.wav" )
pygame.mixer.music.play(0)
def decompte3(label, count=10):
label.config(text="{:.2f}".format(count))
if count > 0 and c3:
fen1.after(10,decompte3, *(label, count-0.01))
if count<0.15:
lab6.configure(text="Bien !", bg="green")
if 0.2<count<0.4:
lab6.configure(text="Pas mal !", bg="orange")
if count>0.4:
lab6.configure(text="A chier !", bg="red")
if count==0 or count<0:
explosion()
pygame.mixer.music.stop()
pygame.mixer.music.load( "explosion.wav" )
pygame.mixer.music.play(0)
####################################################################### Arrêts + Jeu en lui même + sélection au hasard des valeurs de départ pour les bombes
def stop():
global countdown
countdown = False
def stop2():
global c2
c2 = False
def stop3():
global c3
c3 = False
pygame.mixer.music.stop()
pygame.mixer.music.load("desamorce.wav")
pygame.mixer.music.play(0)
fen1=Toplevel(bg="black")
fen1.geometry("879x660")
lab=Label(fen1, text="")
lab2=Label(fen1, text="")
lab3=Label(fen1,text="")
lab3.place(x=300,y=200)
lab4=Label(fen1,text="")
lab4.place(x=100,y=250)
lab5=Label(fen1,text="")
lab5.place(x=200,y=250)
lab6=Label(fen1,text="")
lab6.place(x=300,y=250)
x=(random.uniform(1.5,2))
y=(random.uniform(3,3.5))
z=(random.uniform(4.5,5))
decompte(lab, x)
decompte2(lab2, y)
decompte3(lab3,z)
btn1=Button(fen1, text="stop", command=stop)
btn1.place(x=100,y=225)
btn5=Button(fen1, text="Stop", command=stop2)
btn5.place(x=200,y=225)
btn6=Button(fen1, text="Stop", command=stop3)
btn6.place(x=300,y=225)
btn3=Button(fen1, text="quit",command=fen1.destroy)
btn3.place(x=375,y=350)
lab.place(x=100,y=200)
lab2.place(x=200,y=200)
lab3.place(x=300,y=200)
##################################################### Recommencement
def recommencer():
global countdown
global c2
global c3
countdown= True
c2=True
c3=True
fen1.destroy()
new()
btn4=Button(fen1, text="rejouer", command=recommencer)
btn4.place(x=300,y=350)
###################################################### Introduction
fenetre= Tk()
fenetre.geometry("1024x620")
canvas= Canvas(fenetre, width=1024, height=620,bg="black")
canvas.grid(row=0, column=0)
photo = PhotoImage(file="demineur.gif")
canvas.create_image(512,310, image=photo)
############################################################## Ready ?! GO !
def demande():
askyesno("Prêt(e)?","Êtes-vous prêt(e) ?",parent=fenetre,type='ok')
pygame.mixer.music.stop()
new()
pygame.mixer.music.load("musique_bombe.wav")
pygame.mixer.music.play(-1)
##############################################################
btnjouer=PhotoImage(file="jouer.gif")
btn= Button(fenetre, image=btnjouer, relief="flat", borderwidth=0, highlightthickness=1, command=demande)
btn.place(x=100,y=460)
pygame.mixer.music.load("musique_menu.wav")
pygame.mixer.music.play(-1)
fenetre.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment