#------------------------------------------------------------------------------- # Name: module1 # Purpose: # # Author: bertolir # # Created: 07/05/2013 # Copyright: (c) bertolir 2013 # Licence: #------------------------------------------------------------------------------- #!/usr/bin/env python #-*- : Latin-1 -*- from Tkinter import * from random import * from threading import * import winsound global dxc, dyc, xc1,yc1, xc2, yc2, balle,x11, x21, x22, x12, y11, y12, y21, y22, dy, bip bip = 1200 dy = 10 def Descend1(event) : if not thread_descend1.isAlive() : thread_descend1.start() def Monte1(event) : if not thread_monte1.isAlive() : thread_monte1.start() def Descend2(event) : if not thread_descend2.isAlive() : thread_descend2.start() def Monte2(event) : if not thread_monte2.isAlive() : thread_monte2.start() def Descend12(event) : thread_descend1._Thread__stop() def Monte12(event) : thread_monte1._Thread__stop() def Descend22(event) : thread_descend2._Thread__stop() def Monte22(event) : thread_monte2._Thread__stop() def Descend11(toto) : global x11, x12, y11, y12, dy if y12 <= 495 : can.coords(joueur1, x11, y11+dy, x12, y12+dy) y11+=dy y12+=dy thread_descend1._Thread__stop() def Monte11(toto) : global x11, x12, y11, y12, dy if y11 >= 5 : can.coords(joueur1, x11, y11-dy, x12, y12-dy) y11-=dy y12-=dy thread_monte1._Thread__stop() def Descend21(toto) : global x21, x22, y21, y22, dy if y22 <= 495 : can.coords(joueur2, x21, y21+dy, x22, y22+dy) y21+=dy y22+=dy thread_descend2._Thread__stop() def Monte21(toto) : global x21, x22, y21, y22, dy if y21 >= 5: can.coords(joueur2, x21, y21-dy, x22, y22-dy) y21-=dy y22-=dy thread_monte2._Thread__stop() def Deplacer() : "Deplace le cercle en ligne droite jusqu'au bord du canevas" global dxc, dyc, xc1,yc1, xc2, yc2, balle,x11, x21, x22, x12, y11, y12, y21, y22, dy, bip xc1, yc1, xc2, yc2 = xc1+dxc,yc1+dyc, xc2+dxc, yc2+dyc can.coords(balle,xc1, yc1, xc2, yc2 ) if (xc1 <= x12 and ((yc2+yc1/2.0) >= y11 and (yc1+yc2)/2.0 <= y12)) or (xc2 >= x21 and ((yc2+yc1)/2.0 >= y21 and ((yc2+yc1)/2.0 <= y22))) : dxc -= 2*dxc winsound.Beep(bip,50) if bip == 1200 : #La balle touche une palette bip = 800 else : bip = 1200 if yc1 <= 0 or yc2 >= 500 : # La balle touche le côté haut ou bas dyc -= 2*dyc winsound.Beep(500,50) if xc1 <= 0 or xc2 >= 800 : # La balle touche un côté droit ou gauche : game over Label(master=None, text = "GAME OVER", anchor = CENTER, fg = "white", bg="blue").pack() i = 0 while i <= 800 : winsound.Beep(1000-i,20) i+=20 tkMessageBox.showinfo("You lost", "You lost") dxc -= 2*dxc ident = fen.after(1,Deplacer) fen = Tk() can = Canvas(fen, bg = 'black', height = 500, width = 800) can.pack() x11, y11, x12, y12 = 10,210,30,290 x21, y21, x22, y22 = 770,210,790,290 xc1, yc1, xc2, yc2 = 395,245,405,255 dxc = random() * 5 dyc = random() * 5 balle = can.create_oval(xc1, yc1, xc2, yc2, fill="white", outline="white") toto = "tutu" thread_monte1 = Thread(None, Monte11, None, (toto,), None) thread_monte2 = Thread(None, Monte21, None, (toto,), None) thread_descend1 = Thread(None, Descend11, None, (toto,), None) thread_descend2 = Thread(None, Descend21, None, (toto,), None) joueur1 = can.create_rectangle(x11, y11, x12, y12, fill="white", outline = "white") joueur2 = can.create_rectangle(x21, y21, x22, y22, fill="white", outline = "white") thread_descend1.start() thread_descend2.start() thread_monte1.start() thread_monte2.start() thread_descend1._Thread__stop() thread_descend2._Thread__stop() thread_monte1._Thread__stop() thread_monte2._Thread__stop() fen.bind("", Monte1) fen.bind("", Descend1) fen.bind("q", Descend2) fen.bind("a", Monte2) fen.bind("Release", Monte12) fen.bind("Release", Descend12) fen.bind("", Descend22) fen.bind("", Monte22) Deplacer() fen.mainloop() #print chr(7) #winsoud, Beep(Fhz, temps)