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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Delplanque Sara
Application 2048
Commits
74fe3b26
Commit
74fe3b26
authored
2 months ago
by
Delplanque Sara
Browse files
Options
Downloads
Patches
Plain Diff
ajout fonction calcul score
parent
2a0d8eca
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
applicationQT2048/gamemanager.cpp
+18
-1
18 additions, 1 deletion
applicationQT2048/gamemanager.cpp
applicationQT2048/gamemanager.h
+1
-0
1 addition, 0 deletions
applicationQT2048/gamemanager.h
with
19 additions
and
1 deletion
applicationQT2048/gamemanager.cpp
+
18
−
1
View file @
74fe3b26
...
...
@@ -47,6 +47,7 @@ void GameManager::moveLeft() {
//Mettre a jour l'état et l'enregistrer
historyArray
.
append
(
gridToJsonArray
());
emit
gridChanged
();
emit
calculscore
();
}
void
GameManager
::
moveRight
()
{
...
...
@@ -88,6 +89,7 @@ void GameManager::moveRight() {
//Mettre a jour l'état et l'enregistrer
historyArray
.
append
(
gridToJsonArray
());
emit
gridChanged
();
emit
calculscore
();
}
...
...
@@ -136,6 +138,7 @@ void GameManager::moveUp() {
//Mettre a jour l'état et l'enregistrer
historyArray
.
append
(
gridToJsonArray
());
emit
gridChanged
();
emit
calculscore
();
}
void
GameManager
::
moveDown
()
{
...
...
@@ -181,6 +184,7 @@ void GameManager::moveDown() {
//Mettre a jour l'état et l'enregistrer
historyArray
.
append
(
gridToJsonArray
());
emit
gridChanged
();
emit
calculscore
();
}
...
...
@@ -219,6 +223,7 @@ void GameManager::restartGame() {
//Mettre a jour l'état et l'enregistrer
historyArray
.
append
(
gridToJsonArray
());
emit
gridChanged
();
emit
calculscore
();
}
...
...
@@ -242,7 +247,7 @@ void GameManager::addRandomElement() {
int
row
=
emptyCells
[
randomIndex
].
first
;
int
col
=
emptyCells
[
randomIndex
].
second
;
// Placer un '2' dans cette case
// Placer un '2'
ou un '4'
dans cette case
int
randValue
=
std
::
rand
()
%
100
;
if
(
randValue
<
75
)
{
grid
[
row
][
col
]
=
2
;
...
...
@@ -314,6 +319,7 @@ void GameManager::undo() {
}
emit
gridChanged
();
// Notifiez que la grille a changé
emit
calculscore
();
}
}
...
...
@@ -382,4 +388,15 @@ void GameManager::chargerPartie(QString partieName){
file
.
close
();
}
void
GameManager
::
calculscore
(){
// Parcourir la grille pour additionner toute les cases
int
score
=
0
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
score
=
grid
[
i
][
j
]
+
score
;
}
}
}
This diff is collapsed.
Click to expand it.
applicationQT2048/gamemanager.h
+
1
−
0
View file @
74fe3b26
...
...
@@ -36,6 +36,7 @@ private:
Q_INVOKABLE
void
addRandomElement
();
Q_INVOKABLE
void
enregistrerPartie
(
QString
partieName
);
Q_INVOKABLE
void
calculscore
();
QJsonArray
gridToJsonArray
();
...
...
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