Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
2048
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Bianco
2048
Commits
0d17810a
Commit
0d17810a
authored
6 years ago
by
Garance Guey
Browse files
Options
Downloads
Patches
Plain Diff
affichage grid
parent
a21bd447
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
game2048/2048_graphical.py
+32
-1
32 additions, 1 deletion
game2048/2048_graphical.py
game2048/__pycache__/grid_2048.cpython-36.pyc
+0
-0
0 additions, 0 deletions
game2048/__pycache__/grid_2048.cpython-36.pyc
game2048/grid_2048.py
+2
-8
2 additions, 8 deletions
game2048/grid_2048.py
with
34 additions
and
9 deletions
game2048/2048_graphical.py
+
32
−
1
View file @
0d17810a
...
...
@@ -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
=
cre
ate_
empty_grid
(
)
graphical_grid
=
upd
ate_
graphical_grid
(
grid_game
)
game_2048
.
mainloop
()
This diff is collapsed.
Click to expand it.
game2048/__pycache__/grid_2048.cpython-36.pyc
+
0
−
0
View file @
0d17810a
No preview for this file type
This diff is collapsed.
Click to expand it.
game2048/grid_2048.py
+
2
−
8
View file @
0d17810a
...
...
@@ -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
):
>>>>>>>
1
faf1cea7fd45cb7d6a421ea0113d9508a596695
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()
=======
>>>>>>>
1
faf1cea7fd45cb7d6a421ea0113d9508a596695
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment