diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index b13f5e449d3d486ecece82ebb2de113583a7cb38..08da5fd6adbefd024ebbbec04b447b1654a9b7fc 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -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> diff --git a/game2048/2048_graphical.py b/game2048/2048_graphical.py new file mode 100644 index 0000000000000000000000000000000000000000..287b228476a84fc3d29a8fa2cf261b2ba16e161b --- /dev/null +++ b/game2048/2048_graphical.py @@ -0,0 +1,89 @@ +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() diff --git a/game2048/__pycache__/__init__.cpython-36.pyc b/game2048/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000000000000000000000000000000000000..065a20323e853b10333fdd127742f9b62611e672 Binary files /dev/null and b/game2048/__pycache__/__init__.cpython-36.pyc differ diff --git a/game2048/__pycache__/grid_2048.cpython-36.pyc b/game2048/__pycache__/grid_2048.cpython-36.pyc index 06b19fca769b3891eef2effb4d8aff82f9ecd0f6..d3569437ff86da6f9ef6ba44cc4ac14b63314f4c 100644 Binary files a/game2048/__pycache__/grid_2048.cpython-36.pyc and b/game2048/__pycache__/grid_2048.cpython-36.pyc differ diff --git a/game2048/__pycache__/textual_2048.cpython-36.pyc b/game2048/__pycache__/textual_2048.cpython-36.pyc index 4fcab3570c43c02c800419b57b77edf6e961e609..609e8a662e6c72cce4a0e3db853329556a351a51 100644 Binary files a/game2048/__pycache__/textual_2048.cpython-36.pyc and b/game2048/__pycache__/textual_2048.cpython-36.pyc differ diff --git a/game2048/grid_2048.py b/game2048/grid_2048.py index b245e0b619426b95b75ead9b14262ddcea2a9a77..0a16a41994a3d21d60b3b595e339de5291242359 100644 --- a/game2048/grid_2048.py +++ b/game2048/grid_2048.py @@ -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() + diff --git a/game2048/run_2048.py b/game2048/run_2048.py index 53d5f1417e33c57380af29024bd1130609292095..81f7aaa561f45e886c6b08baa92439de68c6666d 100644 --- a/game2048/run_2048.py +++ b/game2048/run_2048.py @@ -53,3 +53,4 @@ def game_play(): print ("YOU FAIL, TRY AGAIN") return +game_play() diff --git a/game2048/tuto_GUI.py b/game2048/tuto_GUI.py new file mode 100644 index 0000000000000000000000000000000000000000..9eb9afaada6f727186ace949c92041cdaca2c164 --- /dev/null +++ b/game2048/tuto_GUI.py @@ -0,0 +1,74 @@ +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()"""