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

jeu fonctionnel

parent 1faf1cea
Branches
No related tags found
No related merge requests found
from tkinter import * from tkinter import *
from tkinter.messagebox import *
from run_2048 import * from run_2048 import *
from functools import partial
THEMES = {"0": {"name": "Default", 0: "", 2: "2", 4: "4", 8: "8", 16: "16", 32:"32", 64: "64", 128: "128", 256: "256", 512: "512", 1024: "1024", 2048: "2048",4096: "4096", 8192: "8192"}, "1": {"name": "Chemistry", 0: "", 2: "H", 4: "He", 8:"Li", 16: "Be", 32: "B", 64: "C", 128: "N", 256: "O", 512: "F", 1024: "Ne", 2048:"Na", 4096: "Mg", 8192: "Al"}, "2": {"name": "Alphabet", 0: "", 2: "A", 4: "B", 8:"C", 16: "D", 32: "E", 64: "F", 128: "G", 256: "H", 512: "I", 1024: "J", 2048: "K",4096: "L", 8192: "M"}} THEMES = {"0": {"name": "Default", 0: "", 2: "2", 4: "4", 8: "8", 16: "16", 32:"32", 64: "64", 128: "128", 256: "256", 512: "512", 1024: "1024", 2048: "2048",4096: "4096", 8192: "8192"}, "1": {"name": "Chemistry", 0: "", 2: "H", 4: "He", 8:"Li", 16: "Be", 32: "B", 64: "C", 128: "N", 256: "O", 512: "F", 1024: "Ne", 2048:"Na", 4096: "Mg", 8192: "Al"}, "2": {"name": "Alphabet", 0: "", 2: "A", 4: "B", 8:"C", 16: "D", 32: "E", 64: "F", 128: "G", 256: "H", 512: "I", 1024: "J", 2048: "K",4096: "L", 8192: "M"}}
...@@ -16,7 +18,26 @@ TILES_FG_COLOR = {0: "#776e65", 2: "#776e65", 4: "#776e65", 8: "#f9f6f2", \ ...@@ -16,7 +18,26 @@ TILES_FG_COLOR = {0: "#776e65", 2: "#776e65", 4: "#776e65", 8: "#f9f6f2", \
TILES_FONT = {"Verdana", 40, "bold"} TILES_FONT = {"Verdana", 40, "bold"}
def main_run(): def graphical_update():
global graphical_grid,game_grid,grid_size,theme
for i in range(grid_size):
for j in range(grid_size):
graphical_grid[i][j].config(bg = TILES_BG_COLOR[game_grid[i][j]], fg = TILES_FG_COLOR[game_grid[i][j]], text = theme[game_grid[i][j]])
return
def grid_update(direction,fen):
global graphical_grid,game_grid,grid_size,theme
if not is_game_over(game_grid):
possibles = list_move_possible(game_grid)
if direction in possibles:
game_grid = move_grid(game_grid,direction)
game_grid = grid_add_new_tile(game_grid)
graphical_update()
elif did_you_win(game_grid):
showinfo("Victoire","Vous avez gagné !")
else:
showinfo("Echec","Vous avez perdu...")
root = Tk() root = Tk()
background = Frame(root) background = Frame(root)
...@@ -31,19 +52,15 @@ def main_run(): ...@@ -31,19 +52,15 @@ def main_run():
labels.append([]) labels.append([])
for j in range(grid_size): for j in range(grid_size):
graphical_grid[i].append(Label(master = background, bd = 1,relief = "ridge", bg = TILES_BG_COLOR[0], text = "",height = 5, width = 10)) graphical_grid[i].append(Label(master = background, bd = 1,relief = "ridge", bg = TILES_BG_COLOR[0], text = "",height = 5, width = 10))
graphical_grid[i][j].grid(column = i, row = j) graphical_grid[i][j].grid(column = j, row = i)
graphical_grid = graphical_update(graphical_grid,game_grid,grid_size,theme) graphical_update()
background.pack() background.pack()
root.mainloop() root.bind("<KeyPress-Down>",partial(grid_update,"down"))
root.bind("<KeyPress-Up>",partial(grid_update,"up"))
def graphical_update(graphical_grid,game_grid,grid_size,theme): root.bind("<KeyPress-Right>",partial(grid_update,"right"))
root.bind("<KeyPress-Left>",partial(grid_update,"left"))
for i in range(grid_size):
for j in range(grid_size):
graphical_grid[i][j].config(bg = TILES_BG_COLOR[game_grid[i][j]], fg = TILES_FG_COLOR[game_grid[i][j]], text = theme[game_grid[i][j]])
return graphical_grid root.mainloop()
main_run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment