Besoin d'aide Snake python
SweeDyx
-
_Ritchi_ Messages postés 21333 Date d'inscription Statut Contributeur Dernière intervention -
_Ritchi_ Messages postés 21333 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour je souhaiterais juste que l'on m'explique le debut du programme que je ne comprend pas trop , juste de "Def move()" à "vitesse de deplacement du serpent" merci surtout l'histoire du (serpent [i] [0].....)
merci vraiment j'ai besoin d'une réponse pour demain car je passe jeudi.
from tkinter import *
from random import randrange
score = 0 #On initialise le score
def move(): #On définit le mouvement qui correspond au niveau de difficulté facile
global x
global y,pX,pY
test()
global Serpent
can.delete('all')
i=len(Serpent)-1
j=0
while i > 0:
Serpent[i][0]=Serpent[i-1][0]
Serpent[i][1]=Serpent[i-1][1]
can.create_oval(Serpent[i][0], Serpent[i][1], Serpent[i][0] +10, Serpent[i][1]+10,outline='green', fill='green') #Propriété du serpent
i=i-1
#Propriété de la pomme
can.create_oval(pX, pY, pX+7, pY+7, outline='red', fill='red')
#Direction
if direction == 'gauche':
Serpent[0][0] = Serpent[0][0] - dx
if Serpent[0][0] < 5:
Serpent[0][0] = 493
labScore.configure(text= "Perdu ton score était de : " +str(score)) #Ici, nous avons mis le texte "Perdu ton score était de : " quand le serpent touche un bord du canvas + le score
fen.mainloop()
if direction == 'droite':
Serpent[0][0] = Serpent[0][0] + dx
if Serpent[0][0] > 500:
Serpent[0][0] = 0
labScore.configure(text= "Perdu ton score était de : " +str(score))
fen.mainloop()
if direction == 'haut':
Serpent[0][1] = Serpent[0][1] - dy
if Serpent[0][1] < 0:
Serpent[0][1] = 493
labScore.configure(text= "Perdu ton score était de : " +str(score))
fen.mainloop()
if direction == 'bas':
Serpent[0][1] = Serpent[0][1] + dy
if Serpent[0][1] > 493:
Serpent[0][1] = 0
labScore.configure(text= "Perdu ton score était de : " +str(score))
fen.mainloop()
can.create_oval(Serpent[0][0], Serpent[0][1], Serpent[0][0]+10, Serpent[0][1]+10,outline='green', fill='blue')
#Vitesse de déplacement du serpent
if flag != 0:
fen.after(70, move)#Ici c'est la vitesse de déplacment du serpent
def newGame():#Correspond au bouton de difficulté "Facile"
global pX,pY
global flag
if flag == 0:
flag = 1
move()
def Gagné():
global score, flag
if score == 3: #Quand le score est égal à 3 on gagne la partie
labScore.configure(text= "Gagné ")#Le texte "Gagné" s'affiche quand le score est de 3
stop()
def left(event): #Ce sont les directions qui permettent de déplacer le serpent
global direction
direction = 'gauche'
def right(event):
global direction
direction = 'droite'
def up(event):
global direction
direction = 'haut'
def down(event):
global direction
direction = 'bas'
def test(): #Création d'une nouvelle pomme à chaque fois que le serpent en mange une
global pomme
global x,y,pX,pY
global Serpent
global score
if Serpent[1][0]>pX-7 and Serpent[1][0]<pX+7:
if Serpent[1][1]>pY-7 and Serpent[1][1]<pY+7:
#On remet une pomme au hasard
pX = randrange(5, 495)
pY = randrange(5, 495)
can.coords(pomme,pX, pY, pX+5, pY+5)
score +=1
labScore.configure(text= "Nombre de Points: "+str(score))
Gagné()
#On ajoute un nouveau point au serpent
Serpent.append([0,0])
#print(Serpent)
def stop ():
global score
fen.mainloop()
labScore = Label (text= "Nombre de Points: 0")
labScore.grid(row= 3, column= 0)
#Position d'apparition du serpent
x = 240
y = 250
dx, dy = 10, 10
flag = 0
direction = 'haut'
Serpent=[[x,y],[x+2.5,y+2.5],[x+5,y+5],[0,0]]
pX = randrange(5, 495)
pY = randrange(5, 495)
fen = Tk()
fen.title("Jeu projet ISN")
can = Canvas(fen, width=500, height=500, bg='white', bd=5, relief="ridge")
can.pack(side=TOP, padx=5, pady=5)
oval1=can.create_oval(Serpent[1][0], Serpent[1][1], Serpent[1][0] +10, Serpent[1][1]+10, outline='green', fill='red')
oval = can.create_oval(Serpent[0][0], Serpent[0][1], Serpent[0][0]+10, Serpent[0][1]+10, outline='green', fill='green')
pomme = can.create_oval(pX, pY, pX+5, pY+5, outline='black', fill='red')
fen.bind("<Up>", up) # Flèche haut
fen.bind("<Down>", down) # Bas
fen.bind("<Left>", left) # Gauche
fen.bind("<Right>", right) # Droite
b2 = Button(fen, text='Niveau Difficile', command=newGame2, bg='black' , fg='green')
b2.pack(side=RIGHT, padx=5, pady =5)
b5 = Button (fen, text='Niveau Facile', command=newGame, bg='black' , fg='green')
b5.pack(side=LEFT, padx=5, pady=5)
b5 = Button (fen, text='Quitter', command=fen.destroy, bg='black' , fg='green')
b5.pack(side=TOP, padx=5, pady=5)
fen.mainloop()
merci vraiment j'ai besoin d'une réponse pour demain car je passe jeudi.
from tkinter import *
from random import randrange
score = 0 #On initialise le score
def move(): #On définit le mouvement qui correspond au niveau de difficulté facile
global x
global y,pX,pY
test()
global Serpent
can.delete('all')
i=len(Serpent)-1
j=0
while i > 0:
Serpent[i][0]=Serpent[i-1][0]
Serpent[i][1]=Serpent[i-1][1]
can.create_oval(Serpent[i][0], Serpent[i][1], Serpent[i][0] +10, Serpent[i][1]+10,outline='green', fill='green') #Propriété du serpent
i=i-1
#Propriété de la pomme
can.create_oval(pX, pY, pX+7, pY+7, outline='red', fill='red')
#Direction
if direction == 'gauche':
Serpent[0][0] = Serpent[0][0] - dx
if Serpent[0][0] < 5:
Serpent[0][0] = 493
labScore.configure(text= "Perdu ton score était de : " +str(score)) #Ici, nous avons mis le texte "Perdu ton score était de : " quand le serpent touche un bord du canvas + le score
fen.mainloop()
if direction == 'droite':
Serpent[0][0] = Serpent[0][0] + dx
if Serpent[0][0] > 500:
Serpent[0][0] = 0
labScore.configure(text= "Perdu ton score était de : " +str(score))
fen.mainloop()
if direction == 'haut':
Serpent[0][1] = Serpent[0][1] - dy
if Serpent[0][1] < 0:
Serpent[0][1] = 493
labScore.configure(text= "Perdu ton score était de : " +str(score))
fen.mainloop()
if direction == 'bas':
Serpent[0][1] = Serpent[0][1] + dy
if Serpent[0][1] > 493:
Serpent[0][1] = 0
labScore.configure(text= "Perdu ton score était de : " +str(score))
fen.mainloop()
can.create_oval(Serpent[0][0], Serpent[0][1], Serpent[0][0]+10, Serpent[0][1]+10,outline='green', fill='blue')
#Vitesse de déplacement du serpent
if flag != 0:
fen.after(70, move)#Ici c'est la vitesse de déplacment du serpent
def newGame():#Correspond au bouton de difficulté "Facile"
global pX,pY
global flag
if flag == 0:
flag = 1
move()
def Gagné():
global score, flag
if score == 3: #Quand le score est égal à 3 on gagne la partie
labScore.configure(text= "Gagné ")#Le texte "Gagné" s'affiche quand le score est de 3
stop()
def left(event): #Ce sont les directions qui permettent de déplacer le serpent
global direction
direction = 'gauche'
def right(event):
global direction
direction = 'droite'
def up(event):
global direction
direction = 'haut'
def down(event):
global direction
direction = 'bas'
def test(): #Création d'une nouvelle pomme à chaque fois que le serpent en mange une
global pomme
global x,y,pX,pY
global Serpent
global score
if Serpent[1][0]>pX-7 and Serpent[1][0]<pX+7:
if Serpent[1][1]>pY-7 and Serpent[1][1]<pY+7:
#On remet une pomme au hasard
pX = randrange(5, 495)
pY = randrange(5, 495)
can.coords(pomme,pX, pY, pX+5, pY+5)
score +=1
labScore.configure(text= "Nombre de Points: "+str(score))
Gagné()
#On ajoute un nouveau point au serpent
Serpent.append([0,0])
#print(Serpent)
def stop ():
global score
fen.mainloop()
labScore = Label (text= "Nombre de Points: 0")
labScore.grid(row= 3, column= 0)
#Position d'apparition du serpent
x = 240
y = 250
dx, dy = 10, 10
flag = 0
direction = 'haut'
Serpent=[[x,y],[x+2.5,y+2.5],[x+5,y+5],[0,0]]
pX = randrange(5, 495)
pY = randrange(5, 495)
fen = Tk()
fen.title("Jeu projet ISN")
can = Canvas(fen, width=500, height=500, bg='white', bd=5, relief="ridge")
can.pack(side=TOP, padx=5, pady=5)
oval1=can.create_oval(Serpent[1][0], Serpent[1][1], Serpent[1][0] +10, Serpent[1][1]+10, outline='green', fill='red')
oval = can.create_oval(Serpent[0][0], Serpent[0][1], Serpent[0][0]+10, Serpent[0][1]+10, outline='green', fill='green')
pomme = can.create_oval(pX, pY, pX+5, pY+5, outline='black', fill='red')
fen.bind("<Up>", up) # Flèche haut
fen.bind("<Down>", down) # Bas
fen.bind("<Left>", left) # Gauche
fen.bind("<Right>", right) # Droite
b2 = Button(fen, text='Niveau Difficile', command=newGame2, bg='black' , fg='green')
b2.pack(side=RIGHT, padx=5, pady =5)
b5 = Button (fen, text='Niveau Facile', command=newGame, bg='black' , fg='green')
b5.pack(side=LEFT, padx=5, pady=5)
b5 = Button (fen, text='Quitter', command=fen.destroy, bg='black' , fg='green')
b5.pack(side=TOP, padx=5, pady=5)
fen.mainloop()
A voir également:
- Besoin d'aide Snake python
- Citizen code python avis - Accueil - Outils
- Jeux google caché snake - Guide
- Mot secret python pix ✓ - Forum Python
- Python est introuvable. exúcutez sans argument pour procúder ó l ✓ - Forum Python
- Python par la pratique : 101 exercices corrigés pdf - Forum Python
1 réponse
Bonjour,
Python étant basé sur les indentations de lignes pour distinguer les blocs logiques, le copié/collé de ton code est incompréhensible!
Je t'encourage vivement à lire et à appliquer ce tutoriel:
Forum de CCM: Les Balises de Code
Ritchi
Python étant basé sur les indentations de lignes pour distinguer les blocs logiques, le copié/collé de ton code est incompréhensible!
Je t'encourage vivement à lire et à appliquer ce tutoriel:
Forum de CCM: Les Balises de Code
Ritchi