diff --git a/game2048/2048_graphical.py b/game2048/2048_graphical.py index 3058cc312b6407251948b4b495ea150ed4f29843..287b228476a84fc3d29a8fa2cf261b2ba16e161b 100644 --- a/game2048/2048_graphical.py +++ b/game2048/2048_graphical.py @@ -42,6 +42,37 @@ def create_empty_grid(): #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 @@ -53,6 +84,6 @@ grid_size=4 background=Frame(game_2048) graphical_grid=[] -graphical_grid=create_empty_grid() +graphical_grid=update_graphical_grid(grid_game) game_2048.mainloop() diff --git a/game2048/__pycache__/grid_2048.cpython-36.pyc b/game2048/__pycache__/grid_2048.cpython-36.pyc index ae72e820e766b62ac22f66b77ac41ebd7dc2c787..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/grid_2048.py b/game2048/grid_2048.py index aea1406e7a7ae054b54a1d7bca05a50c95e8b2e6..0a16a41994a3d21d60b3b595e339de5291242359 100644 --- a/game2048/grid_2048.py +++ b/game2048/grid_2048.py @@ -58,11 +58,9 @@ def grid_add_new_tile(grid): #attention, la fonction modifie la liste passée en argument ! return grid -<<<<<<< HEAD -def init_game(n=4): -======= + def init_game(n = 4): ->>>>>>> 1faf1cea7fd45cb7d6a421ea0113d9508a596695 + grid = create_grid(n) for new_tile in range(2): grid = grid_add_new_tile(grid) @@ -231,8 +229,4 @@ def random_play(): else : print ("YOU FAIL, TRY AGAIN") return() -<<<<<<< HEAD -#TEST random_play() -======= ->>>>>>> 1faf1cea7fd45cb7d6a421ea0113d9508a596695