Projet Tetris ISN | comment perdre ?
PierreVarenn
-
trifou -
trifou -
Bonjour,
J'ai élaboré un programme tetris pour mon projet isn mais je n'arrive pas a trouver comment je pourrais faire loose le programme dans le sens ou qd mes blocs sont en haut HOP affichage "Loose" ou n'importe mais je cherche à faire stopper le programme.
meric de m'aider si qql c'est ? je met le prog ci dessous
y'a 300 lignes desole ^^ (INTERDICTION A PYGAME)
J'ai élaboré un programme tetris pour mon projet isn mais je n'arrive pas a trouver comment je pourrais faire loose le programme dans le sens ou qd mes blocs sont en haut HOP affichage "Loose" ou n'importe mais je cherche à faire stopper le programme.
meric de m'aider si qql c'est ? je met le prog ci dessous
y'a 300 lignes desole ^^ (INTERDICTION A PYGAME)
<config>###############################TETRIS YAP###################################### ############################################################################### # By Yanis, Pierre, Arthur # ############################################################################### ############################################################################### from tkinter import * #################################Variable###################################### limite = True x=0 #-#-#-#-#-#-# PosX1 = 100 PosX2 = 120 PosX3 = 100 PosX4 = 120 PosY1 = 20 PosY2 = 20 PosY3 = 40 PosY4 = 40 posx1 = 4 posx2 = 5 posx3 = 4 posx4 = 5 posy1 = 0 posy2 = 0 posy3 = 1 posy4 = 1 #-#-#-#-#-#-# Largeur = 220 Hauteur = 460 ################################MODULE######################################### ############################################################################### def mouvement(event): global PosX1,PosX2,PosX3,PosX4,PosY1,PosY2,PosY3,PosY4,limite,Pion1,Pion2,Pion3,Pion4, posx1, posx2,posx3,posx4,posy1,posy2,posy3,posy4, tab touche = event.keysym # déplacement vers le bas if touche == 'Down' and (posy1 and posy2 and posy3 and posy4) != 21 and tab[posy3+1][posx3] == 0 and tab[posy4+1][posx4] == 0 : tab[posy1][posx1]=0 #on donne la valeur 0 au position x/y aux pions tab[posy2][posx2]=0 #dans le tableau 'tab' tab[posy3][posx3]=0 tab[posy4][posx4]=0 PosY1 = PosY1 + 20 #deplacement du groupe d'objet composant notre PosY2 = PosY2 + 20 #composant notre carré de quatre petit carré en y (ordonné) PosY3 = PosY3 + 20 PosY4 = PosY4 + 20 posy1 = posy1 + 1 #pareil pour x (abscisse) posy2 = posy2 + 1 posy3 = posy3 + 1 posy4 = posy4 + 1 tab[posy1][posx1]=Pion1 #on redefinit leurs valeurs dans le tableau tab[posy2][posx2]=Pion2 #pour figer les pions dans le 'tab' tab[posy3][posx3]=Pion3 tab[posy4][posx4]=Pion4 print(tab) # déplacement vers la droite (meme processus) if touche == 'Right' and (posx1 and posx2 and posx3 and posx4) != 9 and tab[posy2][posx2+1] == 0 and tab[posy4][posx4+1] == 0: tab[posy1][posx1]=0 tab[posy2][posx2]=0 tab[posy3][posx3]=0 tab[posy4][posx4]=0 PosX1 = PosX1 +20 PosX2 = PosX2 +20 PosX3 = PosX3 +20 PosX4 = PosX4 +20 posx1 = posx1 +1 posx2 = posx2 +1 posx3 = posx3 +1 posx4 = posx4 +1 tab[posy1][posx1]=Pion1 tab[posy2][posx2]=Pion2 tab[posy3][posx3]=Pion3 tab[posy4][posx4]=Pion4 print(tab) # déplacement vers la gauche (meme processus) if touche == 'Left' and (posx1 and posx2 and posx3 and posx4) != 0 and tab[posy1][posx1-1] == 0 and tab[posy3][posx3-1] == 0: tab[posy1][posx1]=0 tab[posy2][posx2]=0 tab[posy3][posx3]=0 tab[posy4][posx4]=0 PosX1 = PosX1 - 20 PosX2 = PosX2 - 20 PosX3 = PosX3 - 20 PosX4 = PosX4 - 20 posx1 = posx1 - 1 posx2 = posx2 - 1 posx3 = posx3 - 1 posx4 = posx4 - 1 tab[posy1][posx1]=Pion1 tab[posy2][posx2]=Pion2 tab[posy3][posx3]=Pion3 tab[posy4][posx4]=Pion4 print(tab) #On renvoie les coordonnées du pion pour ne pas avoirn de decalage avec #d'autres fonctions canvas.coords(Pion1,PosX1 -10, PosY1 -10, PosX1 +10, PosY1 +10) canvas.coords(Pion2,PosX2 -10, PosY2 -10, PosX2 +10, PosY2 +10) canvas.coords(Pion3,PosX3 -10, PosY3 -10, PosX3 +10, PosY3 +10) canvas.coords(Pion4,PosX4 -10, PosY4 -10, PosX4 +10, PosY4 +10) #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# def lost(): global PosX1,PosX2,PosX3,PosX4,PosY1,PosY2,PosY3,PosY4,limite,Pion1,Pion2,Pion3,Pion4, posx1,posx2,posx3,posx4,posy1,posy2,posy3,posy4,tab if #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# def chutelibre(): global limite, PosX1,PosX2,PosX3,PosX4,PosY1,PosY2,PosY3,PosY4,limite,Pion1,Pion2,Pion3,Pion4, posx1, posx2,posx3,posx4,posy1,posy2,posy3,posy4, tab,x while limite == False : if x == 50: x=0 tab[posy1][posx1]=0 tab[posy2][posx2]=0 tab[posy3][posx3]=0 tab[posy4][posx4]=0 PosY1 = PosY1 + 20 PosY2 = PosY2 + 20 PosY3 = PosY3 + 20 PosY4 = PosY4 + 20 posy1 = posy1 + 1 posy2 = posy2 + 1 posy3 = posy3 + 1 posy4 = posy4 + 1 tab[posy1][posx1]=Pion1 tab[posy2][posx2]=Pion2 tab[posy3][posx3]=Pion3 tab[posy4][posx4]=Pion4 canvas.coords(Pion1,PosX1 -10, PosY1 -10, PosX1 +10, PosY1 +10) canvas.coords(Pion2,PosX2 -10, PosY2 -10, PosX2 +10, PosY2 +10) canvas.coords(Pion3,PosX3 -10, PosY3 -10, PosX3 +10, PosY3 +10) canvas.coords(Pion4,PosX4 -10, PosY4 -10, PosX4 +10, PosY4 +10) #print tab #print posy1 #print Pion2 #print Pion3 #print Pion4 else : x = x + 1 canvas.after(1) if (PosY3 > Hauteur - 40 or PosY4 > Hauteur - 40 or tab[posy3+1][posx3] != 0 or tab[posy4+1][posx4] != 0): tab[posy1][posx1] = Pion1 tab[posy2][posx2] = Pion2 tab[posy3][posx3] = Pion3 tab[posy4][posx4] = Pion4 Ligne() lost() PosX1 = 100 PosX2 = 120 PosX3 = 100 PosX4 = 120 PosY1 = 20 PosY2 = 20 PosY3 = 40 PosY4 = 40 posx1 = 4 posx2 = 5 posx3 = 4 posx4 = 5 posy1 = 0 posy2 = 0 posy3 = 1 posy4 = 1 Pion1=canvas.create_rectangle(PosX1-10,PosY1-10,PosX1+10,PosY1+10,width=2,outline='red',fill='AntiqueWhite') Pion2=canvas.create_rectangle(PosX2-10,PosY2-10,PosX2+10,PosY2+10,width=2,outline='red',fill='AntiqueWhite') Pion3=canvas.create_rectangle(PosX3-10,PosY3-10,PosX3+10,PosY3+10,width=2,outline='red',fill='AntiqueWhite') Pion4=canvas.create_rectangle(PosX4-10,PosY4-10,PosX4+10,PosY4+10,width=2,outline='red',fill='AntiqueWhite') canvas.coords(Pion1,PosX1 -10, PosY1 -10, PosX1 +10, PosY1 +10) canvas.coords(Pion2,PosX2 -10, PosY2 -10, PosX2 +10, PosY2 +10) canvas.coords(Pion3,PosX3 -10, PosY3 -10, PosX3 +10, PosY3 +10) canvas.coords(Pion4,PosX4 -10, PosY4 -10, PosX4 +10, PosY4 +10) canvas.update() #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# def Ligne(): global PosX1,PosX2,PosX3,PosX4,PosY1,PosY2,PosY3,PosY4,limite,Pion1,Pion2,Pion3,Pion4, posx1,posx2,posx3,posx4,posy1,posy2,posy3,posy4,tab n=0 for p in range (posy4, posy4-4,-1): nb = 0 for x in range (10): if tab[p][x]!=0: nb = nb + 1 if nb == 10 : for i in range (10): canvas.delete(tab[p][i]) tab[p][i]=0 n = n + 1 for s in range (n): for y in range (posy4, 0, -1): for x in range (10): tab[y][x]=tab[y-1][x] PosX = x * 20 + 20 PosY = y * 20 + 20 canvas.coords(tab[y][x],PosX -10, PosY -10, PosX +10, PosY +10) #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# def Demarrer(): global limite if limite == True: limite = False chutelibre() ############################################################################### # la variable tab sera desormais notre plan de jeu tab= [[0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0]] listpion=[0] #creation, de quadrillage # on créé notre fenetre window = Tk() window.title('Tetris YAP') # creation du canevas + dimensions declarées Largeur = 220 Hauteur = 460 canvas = Canvas(window, width = Largeur, height =Hauteur, bg ='azure') canvas.focus_set() canvas.bind('<Key>',mouvement) canvas.pack(padx =5, pady =5) BoutonGo = Button(window, text ='Play', command = Demarrer) BoutonGo.pack(side = LEFT, padx = 10, pady = 10) ### # creation d'un bouton pour quitter le programme Button(window, text ='Quitter', command = window.destroy).pack(side=LEFT,padx=5,pady=5) Pion1=canvas.create_rectangle(PosX1-10,PosY1-10,PosX1+10,PosY1+10,width=2,outline='red',fill='AntiqueWhite') Pion2=canvas.create_rectangle(PosX2-10,PosY2-10,PosX2+10,PosY2+10,width=2,outline='red',fill='AntiqueWhite') Pion3=canvas.create_rectangle(PosX3-10,PosY3-10,PosX3+10,PosY3+10,width=2,outline='red',fill='AntiqueWhite') Pion4=canvas.create_rectangle(PosX4-10,PosY4-10,PosX4+10,PosY4+10,width=2,outline='red',fill='AntiqueWhite') window.mainloop() </config>
A voir également:
- Projet Tetris ISN | comment perdre ?
- Comment changer d'adresse mail sans rien perdre - Guide
- Filigrane projet - Guide
- Gant projet - Télécharger - Gestion de projets
- Tetris webmaster - Forum Webmastering
- Reinstaller windows sans rien perdre - Guide
1 réponse
Bonjour,
Avoir pris connaissance de la méthode after, c'est bien, mais il faudrait s'en servir convenablement, s'en servir pour juste faire un sleep ne va pas du tout. Tu dois bien te rendre compte que les pièces descendent trop vite et que ce n'est pas jouable.
Maintenant pour ton problème, si tu remplis ton tableau
Avoir pris connaissance de la méthode after, c'est bien, mais il faudrait s'en servir convenablement, s'en servir pour juste faire un sleep ne va pas du tout. Tu dois bien te rendre compte que les pièces descendent trop vite et que ce n'est pas jouable.
Maintenant pour ton problème, si tu remplis ton tableau
tabcorrectement, alors il suffit de regarder si la 1ère ligne du tableau contient autre chose que 0 à tel index pour déterminer que le joueur a perdu avant de lâcher la pièce suivante.
Alors after permet de faire attendre le programme sans avoir de conséquences sur le jeu, c’est a dire que qd j’utilisais Time ou Thread mon programme effectuait les mouvements puis ensuite elle lançait la partie graphique, la vitesse est réglable grace a la valeurs de x donc en réalité c’est assez jouable.
Ensuite j’y ai pensé dès le début, le problème c’est que qd la pièce s’initialise elle est sur la case en haut donc si elle passe sur cette case le jeu indiquera que le joueur a perdu