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
|
from tkinter import *
from random import randrange
import random
def nouveau_jeu():
a=0
def rectangle(): # creation de 3 rectangles
global dx, dy, x, y, x1, y1, x3, y3 , x2, y2, nana
m=0
x1=randrange(0,266)
x2=randrange(267,532)
x3=randrange(533,800)
y1=randrange(0,200)
y2=randrange(201,400)
y3=randrange(401,600)
can1.create_rectangle(x1, y1, y1+30, x1+50, fill='blue')
can1.create_rectangle(x2, y2, y2+30, x2+50, fill='red')
can1.create_rectangle(x3, y3, y3+30, x3+50, fill='white')
def perso():
global dx, dy, x, y, x1, y1, x3, y3 , x2, y2, nana
nana=can1.create_image(100,100,image=nana2)
def pomme(): # création de pommes aléatoires + test d'avoir pas les mêmes coordonnées que les rectangles.
global dx, dy, x, y, x1, y1, x3, y3 , x2, y2, nana
c=0
a=0
b=0
x=randrange(800)
y=randrange(600)
x5= x+10
y5= y+10
while c<10:
while a<=50:
while b<=30:
if x!=x1 and x!=x1+a and x!=x2 and x!=x2+a and x!=x3 and
x!=x3+a and y!=y1 and y!=y1+b and y!=y2 and y!=y2+b and
y!=y3 and y!=y3+b and x5!=x1 and x5!=x1+a and x5!=x2 and
x5!=x2+a and x5!=x3 and x5!=x3+a and y5!=y1 and y5!=y1+a
and y5!=y2+a and y5!=y3+a and y5!=y2 and y5!=y3:
can1.create_oval(x,y, x5, y5, fill='green')
break
else:
b=b+1
a=a+1
b=0
c=c+1
a=0
def avant(event):
global dx, dy,nana
dx=0
dy=-10
can1.move(nana, dx, dy)
def gauche(event):
global dx, dy, nana
dx=-10
dy=0
can1.move(nana, dx, dy)
def droite(event):
global dx, dy, nana
dx=10
dy=0
can1.move(nana, dx, dy)
direction=0
def bas(event):
global dx, dy, nana
dx=0
dy=10
can1.move(nana, dx, dy)
fen1=Tk()
fen1.title("SUPER NANA ! :D")
nana2= PhotoImage(file='perso.gif')
photo= PhotoImage(file='background.gif')
can1= Canvas (fen1, bg='blue', width = 800, height = 600)
can1.create_image(802, 2, image=photo, anchor=NE)
#nana=can1.create_image(100,100,image=nana2)
can1.grid(row=0, column=0, rowspan=10)
can1.bind_all("<Up>", avant)
can1.bind_all("<Right>", droite)
can1.bind_all("<Down>", bas)
can1.bind_all("<Left>", gauche)
Button(fen1, text="Nouveau Jeu", font=("ComicSansMS"), command=rectangle).grid(row =4, column=1, sticky=N, padx=5)
Button(fen1, text="Pomme", font=("ComicSansMS"), command=pomme).grid(row =5, column=1, sticky=N, padx=2)
Button(fen1, text="Perso", font=("ComicSansMS"), command=perso).grid(row =6, column=1, sticky=N, padx=2)
Button(fen1, text="Quitter", font=("ComicSansMS"),command=fen1.destroy).grid(row =8, column=1, sticky=N)
dx=0
dy=0
direction=0
score=0
fen1.mainloop() |
Partager