Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Application 2048
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Delplanque Sara
Application 2048
Commits
dad5730c
Commit
dad5730c
authored
3 months ago
by
Breitwiller Josephine
Browse files
Options
Downloads
Patches
Plain Diff
mise a jour de la grille liée à grid
parent
85a2e5ec
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
applicationQT2048/Main.qml
+19
-8
19 additions, 8 deletions
applicationQT2048/Main.qml
applicationQT2048/gamemanager.cpp
+31
-9
31 additions, 9 deletions
applicationQT2048/gamemanager.cpp
applicationQT2048/gamemanager.h
+9
-2
9 additions, 2 deletions
applicationQT2048/gamemanager.h
with
59 additions
and
19 deletions
applicationQT2048/Main.qml
+
19
−
8
View file @
dad5730c
...
...
@@ -112,8 +112,7 @@ Window {
MouseArea
{
id
:
buttonMouseArea
anchors.fill
:
parent
//anchor all sides of the mouse area to the rectangle's anchors
//onClicked handles valid mouse button clicks
anchors.fill
:
parent
onClicked
:
gameManager
.
restartGame
()
}
}
...
...
@@ -149,7 +148,7 @@ Window {
anchors.horizontalCenter
:
parent
.
horizontalCenter
y
:
170
color
:
"
grey
"
radius
:
10
radius
:
5
Grid
{
...
...
@@ -162,16 +161,28 @@ Window {
Repeater
{
model
:
16
model
:
gameManager
.
gridValues
Rectangle
{
width
:
78
height
:
78
color
:
"
lightgrey
"
radius
:
10
color
:
modelData
==
2
?
"
#EEE4DA
"
:
modelData
==
4
?
"
#EDE0C8
"
:
modelData
==
8
?
"
#F2B179
"
:
modelData
==
16
?
"
#F59563
"
:
modelData
==
32
?
"
#F67C5F
"
:
modelData
==
64
?
"
#F65E3B
"
:
modelData
==
128
?
"
#EDCF72
"
:
modelData
==
256
?
"
#EDCC61
"
:
modelData
==
512
?
"
#EDC850
"
:
modelData
==
1024
?
"
#EDC53F
"
:
modelData
==
2048
?
"
#EDC22E
"
:
"
#BBADA0
"
radius
:
5
Text
{
text
:
modelData
>
0
?
modelData
:
""
anchors.centerIn
:
parent
text
:
""
font.bold
:
true
font.pixelSize
:
30
color
:
"
grey
"
}
}
}
...
...
This diff is collapsed.
Click to expand it.
applicationQT2048/gamemanager.cpp
+
31
−
9
View file @
dad5730c
#include
"gamemanager.h"
#include
"random"
GameManager
::
GameManager
(
QObject
*
parent
)
:
QObject
(
parent
),
grid
(
4
,
std
::
vector
<
int
>
(
4
,
0
))
{
generateTile
();
generateTile
();
}
void
GameManager
::
moveLeft
()
{
...
...
@@ -23,14 +23,36 @@ void GameManager::moveDown() {
void
GameManager
::
restartGame
()
{
grid
.
assign
(
4
,
std
::
vector
<
int
>
(
4
,
0
));
generateTile
();
generateTile
();
}
std
::
random_device
rd
;
std
::
uniform_int_distribution
<
int
>
distrib
(
0
,
15
);
int
num1
=
distrib
(
rd
);
int
num2
=
distrib
(
rd
);
// Assure que num2 est différent de num1
do
{
num2
=
distrib
(
rd
);
}
while
(
num2
==
num1
);
int
rg1
=
num1
/
4
;
int
col1
=
num1
-
(
4
*
rg1
);
int
rg2
=
num2
/
4
;
int
col2
=
num2
-
(
4
*
rg2
);
grid
[
rg1
][
col1
]
=
2
;
grid
[
rg2
][
col2
]
=
2
;
emit
gridChanged
();
void
GameManager
::
generateTile
()
{
// Implémentation de la génération de tuiles
}
void
GameManager
::
mergeTiles
()
{
// Implémentation de la fusion des tuiles
QVector
<
int
>
GameManager
::
getGridValues
()
const
{
QVector
<
int
>
flattenedGrid
;
for
(
const
auto
&
row
:
grid
)
{
// 🔹 Parcourt chaque ligne
for
(
int
value
:
row
)
{
// 🔹 Parcourt chaque colonne
flattenedGrid
.
append
(
value
);
}
}
return
flattenedGrid
;
}
This diff is collapsed.
Click to expand it.
applicationQT2048/gamemanager.h
+
9
−
2
View file @
dad5730c
...
...
@@ -7,6 +7,9 @@
class
GameManager
:
public
QObject
{
Q_OBJECT
Q_PROPERTY
(
QVector
<
int
>
gridValues
READ
getGridValues
NOTIFY
gridChanged
)
public:
explicit
GameManager
(
QObject
*
parent
=
nullptr
);
Q_INVOKABLE
void
moveLeft
();
...
...
@@ -15,10 +18,14 @@ public:
Q_INVOKABLE
void
moveDown
();
Q_INVOKABLE
void
restartGame
();
QVector
<
int
>
getGridValues
()
const
;
private:
std
::
vector
<
std
::
vector
<
int
>>
grid
;
void
generateTile
();
void
mergeTiles
();
signals:
void
gridChanged
();
};
...
...
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