Skip to content
Snippets Groups Projects
Commit f6436076 authored by Thomas Bianco's avatar Thomas Bianco
Browse files

Merge branch 'master' of gitlab.viarezo.fr:2018biancot/2048

parents d04d0468 0d17810a
No related branches found
No related tags found
No related merge requests found
......@@ -12,10 +12,13 @@
<option value="E501" />
<option value="W29" />
<option value="E501" />
<<<<<<< HEAD
=======
<option value="W29" />
<option value="E501" />
<option value="W29" />
<option value="E501" />
>>>>>>> 1faf1cea7fd45cb7d6a421ea0113d9508a596695
</list>
</option>
</inspection_tool>
......
from tkinter import *
from game2048.grid_2048 import *
# DICTIONNAIRE
TILES_BG_COLOR = {0: "#9e948a", 2: "#eee4da", 4: "#ede0c8", 8: "#f1b078", \
16: "#eb8c52", 32: "#f67c5f", 64: "#f65e3b", \
128: "#edcf72", 256: "#edcc61", 512: "#edc850", \
1024: "#edc53f", 2048: "#edc22e", 4096: "#5eda92", \
8192: "#24ba63"}
TILES_FG_COLOR = {0: "#776e65", 2: "#776e65", 4: "#776e65", 8: "#f9f6f2", \
16: "#f9f6f2", 32: "#f9f6f2", 64: "#f9f6f2", 128: "#f9f6f2", \
256: "#f9f6f2", 512: "#f9f6f2", 1024: "#f9f6f2", \
2048: "#f9f6f2", 4096: "#f9f6f2", 8192: "#f9f6f2"}
TILES_FONT = {"Verdana", 40, "bold"}
#FIN DICTIONNAIRE
#FONCTIONS
def graphical_inti():
game_2048=Tk()
fenetre=Toplevel()
fenetre.title("2048")
game_2048.title("2048")
game_2048["bg"]="pink"
return(game_2048)
#attention il faut toujours faire game_2048.mainloop() à la fin du programme
def create_empty_grid():
list_tuile=[]
for ligne in range (4):
list_tuile.append([])
for colonne in range (4):
list_tuile[ligne].append(Frame(game_2048,borderwidth=2, relief="solid",height = 100, width = 100,bg=TILES_BG_COLOR[0]))
list_tuile[ligne][colonne].grid(row=ligne,column=colonne)
return(list_tuile)
#ATTENTION lors de la création d'un frame, sa hauteur et sa largeur vaut 0 de base : modifier directement lors de la création par height= et width=
def update_graphical_grid(grid_game):
#cette fonction ne marche que pour les grilles 4x4
list_tuile=[]
list_label=[]
for ligne in range (4):
list_tuile.append([])
list_label.append([])
#pour chaque ligne
for colonne in range (4):
#on liste les colonnes où il va y avoir des numéros
list_colonne_wt_label=[]
#on regarde la valeur de la tuile
value_tuile=grid_game[ligne][colonne]
#si la valeur est zero, il n'y a pas de label
if value_tuile==0 :
list_tuile[ligne].append(Frame(game_2048,borderwidth=2, relief="solid",height = 100, width = 100,bg=TILES_BG_COLOR[0]))
#sinon on dit crée un label et retenir sa position pour le positionner
else :
#création de la tuile
list_tuile[ligne].append(Frame(game_2048,borderwidth=2, relief="solid",height = 100, width = 100,bg=TILES_BG_COLOR[value_tuile]))
#création du label
list_label[ligne].append(Label(list_tuile[ligne][colonne],text=str(value_tuile),fg=TILES_FG_COLOR[value_tuile],bg=TILES_BG_COLOR[value_tuile],height = 5, width = 10,font=TILES_FONT))
#mémoire de sa position
list_colonne_wt_label.append(colonne)
#on positionne correctement le label
for lab in range (len(list_colonne_wt_label)):
list_label[ligne][lab].grid(row=ligne,column=list_colonne_wt_label[lab])
#on positionne correctement les tuiles
list_tuile[ligne][colonne].grid(row=ligne,column=colonne)
return(list_tuile)
#FIN FONCTION
#EXECUTION
game_2048=graphical_inti()
grid_game=init_game()
grid_size=4
background=Frame(game_2048)
graphical_grid=[]
graphical_grid=update_graphical_grid(grid_game)
game_2048.mainloop()
File added
No preview for this file type
No preview for this file type
......@@ -58,7 +58,9 @@ def grid_add_new_tile(grid):
#attention, la fonction modifie la liste passée en argument !
return grid
def init_game(n = 4):
grid = create_grid(n)
for new_tile in range(2):
grid = grid_add_new_tile(grid)
......@@ -227,3 +229,4 @@ def random_play():
else :
print ("YOU FAIL, TRY AGAIN")
return()
......@@ -53,3 +53,4 @@ def game_play():
print ("YOU FAIL, TRY AGAIN")
return
game_play()
from tkinter import *
"""window=Tk()
label_field = Label(window,text="Hello World !")
label_field.pack(fill=BOTH)
window.mainloop()"""
#disposition :
# dans .pack
#placement cardinal : side =(Tkinter.TOP, Tkinter.LEFT, Tkinter.RIGHT, Tkinter.BOTTOM
# grosseur de la fenetre : fill= X,Y,BOTH
#acction
#les boutons :
#Les boutons (Button) sont des widgets sur lesquels on peut cliquer et qui peuvent déclencher des actions ou commandes.
"""def write_text():
print("Hello CentraleSupelec")
root = Tk()
frame =Frame(root)
frame.pack()
button = Button(frame,
text="QUIT",
activebackground = "blue",
fg="red",
command=quit)
button.pack(side=LEFT)
slogan = Button(frame,
fg="blue",
text="Hello",
command=write_text)
slogan.pack(side=LEFT)
root.mainloop()"""
"""from tkinter import Tk, StringVar, Label, Entry, Button
from functools import partial
def update_label(label, stringvar):
#Met à jour le texte d'un label en utilisant une StringVar.
text = stringvar.get()
label.config(text=text)
stringvar.set('merci')
root = Tk()
text = StringVar(root)
label = Label(root, text='Your name')
entry_name = Entry(root, textvariable=text)
button = Button(root, text='clic',
command=partial(update_label, label, text))
label.grid(column=0, row=0)
entry_name.grid(column=0, row=1)
button.grid(column=0, row=2)
root.mainloop()"""
"""from tkinter import Tk, Label, Frame
root = Tk()
f1 = Frame(root, bd=1, relief='solid')
Label(f1, text='je suis dans F1').grid(row=0, column=0)
Label(f1, text='moi aussi dans F1').grid(row=0, column=1)
f1.grid(row=0, column=0)
Label(root, text='je suis dans root').grid(row=1, column=0)
Label(root, text='moi aussi dans root').grid(row=2, column=0)
root.mainloop()"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment