Skip to content
Snippets Groups Projects
Commit 74fe3b26 authored by Delplanque Sara's avatar Delplanque Sara
Browse files

ajout fonction calcul score

parent 2a0d8eca
Branches
No related tags found
No related merge requests found
......@@ -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;
}
}
}
......@@ -36,6 +36,7 @@ private:
Q_INVOKABLE void addRandomElement();
Q_INVOKABLE void enregistrerPartie(QString partieName);
Q_INVOKABLE void calculscore();
QJsonArray gridToJsonArray();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment