From bee0c4112470a998934d154376783d6334a7dfcc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Thu, 22 Aug 2024 13:25:55 +0200
Subject: [PATCH] Add "guesses count" indicator

---
 android/gradle.properties                         |  4 ++--
 fastlane/metadata/android/en-US/changelogs/25.txt |  1 +
 fastlane/metadata/android/fr-FR/changelogs/25.txt |  1 +
 lib/cubit/game_cubit.dart                         | 10 ++++++----
 lib/models/game/game.dart                         | 12 ++++++------
 lib/ui/widgets/game/game_top.dart                 |  9 ++++++++-
 pubspec.yaml                                      |  2 +-
 7 files changed, 25 insertions(+), 14 deletions(-)
 create mode 100644 fastlane/metadata/android/en-US/changelogs/25.txt
 create mode 100644 fastlane/metadata/android/fr-FR/changelogs/25.txt

diff --git a/android/gradle.properties b/android/gradle.properties
index 33c4377..5a36ab8 100644
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -1,5 +1,5 @@
 org.gradle.jvmargs=-Xmx1536M
 android.useAndroidX=true
 android.enableJetifier=true
-app.versionName=1.0.23
-app.versionCode=24
+app.versionName=1.0.24
+app.versionCode=25
diff --git a/fastlane/metadata/android/en-US/changelogs/25.txt b/fastlane/metadata/android/en-US/changelogs/25.txt
new file mode 100644
index 0000000..51d986d
--- /dev/null
+++ b/fastlane/metadata/android/en-US/changelogs/25.txt
@@ -0,0 +1 @@
+Add "guesses count" indicator.
diff --git a/fastlane/metadata/android/fr-FR/changelogs/25.txt b/fastlane/metadata/android/fr-FR/changelogs/25.txt
new file mode 100644
index 0000000..3404cfe
--- /dev/null
+++ b/fastlane/metadata/android/fr-FR/changelogs/25.txt
@@ -0,0 +1 @@
+Ajout d'un compteur de coups.
diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart
index e4f60ed..6a43fa8 100644
--- a/lib/cubit/game_cubit.dart
+++ b/lib/cubit/game_cubit.dart
@@ -36,7 +36,7 @@ class GameCubit extends HydratedCubit<GameState> {
       // Base data
       board: state.currentGame.board,
       // Game data
-      movesCount: state.currentGame.movesCount,
+      guessesCount: state.currentGame.guessesCount,
       pairsFound: state.currentGame.pairsFound,
     );
     game.dump();
@@ -130,6 +130,9 @@ class GameCubit extends HydratedCubit<GameState> {
         }
       }
 
+      state.currentGame.guessesCount++;
+      refresh();
+
       // timer + check pair + unselect
       Timer(const Duration(seconds: 2), () {
         if (hasSameValue) {
@@ -137,12 +140,11 @@ class GameCubit extends HydratedCubit<GameState> {
 
           final int itemValue = state.currentGame.board.tiles[selectedTilesIndexes[0]].value;
           state.currentGame.pairsFound.add(itemValue);
+          refresh();
         }
 
-        state.currentGame.movesCount++;
-        refresh();
-
         state.currentGame.isFinished = state.currentGame.gameWon;
+        refresh();
 
         unselectAllTiles();
         allowInteractions(true);
diff --git a/lib/models/game/game.dart b/lib/models/game/game.dart
index 0261c27..2cd02fc 100644
--- a/lib/models/game/game.dart
+++ b/lib/models/game/game.dart
@@ -28,7 +28,7 @@ class Game {
     required this.board,
 
     // Game data
-    required this.movesCount,
+    required this.guessesCount,
     required this.pairsFound,
   });
 
@@ -47,7 +47,7 @@ class Game {
   final Board board;
 
   // Game data
-  int movesCount;
+  int guessesCount;
   List<int> pairsFound = [];
 
   factory Game.createNull() {
@@ -58,7 +58,7 @@ class Game {
       // Base data
       board: Board.createNull(),
       // Game data
-      movesCount: 0,
+      guessesCount: 0,
       pairsFound: [],
     );
   }
@@ -83,7 +83,7 @@ class Game {
       // Base data
       board: board,
       // Game data
-      movesCount: 0,
+      guessesCount: 0,
       pairsFound: [],
     );
   }
@@ -111,7 +111,7 @@ class Game {
     printlog('  Base data');
     board.dump();
     printlog('  Game data');
-    printlog('    movesCount: $movesCount');
+    printlog('    guessesCount: $guessesCount');
     printlog('    pairsFound: $pairsFound');
     printlog('');
   }
@@ -135,7 +135,7 @@ class Game {
       // Base data
       'board': board.toJson(),
       // Game data
-      'movesCount': movesCount,
+      'guessesCount': guessesCount,
       'pairsFound': pairsFound,
     };
   }
diff --git a/lib/ui/widgets/game/game_top.dart b/lib/ui/widgets/game/game_top.dart
index 4520997..8d1e937 100644
--- a/lib/ui/widgets/game/game_top.dart
+++ b/lib/ui/widgets/game/game_top.dart
@@ -13,7 +13,14 @@ class GameTopWidget extends StatelessWidget {
       builder: (BuildContext context, GameState gameState) {
         final Game currentGame = gameState.currentGame;
 
-        return const Text('');
+        return Text(
+          currentGame.guessesCount.toString(),
+          style: TextStyle(
+            fontSize: 40,
+            fontWeight: FontWeight.bold,
+            color: Theme.of(context).colorScheme.primary,
+          ),
+        );
       },
     );
   }
diff --git a/pubspec.yaml b/pubspec.yaml
index d6e42a2..5aed35a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@ description: A simple and classic memory game.
 
 publish_to: "none"
 
-version: 1.0.23+24
+version: 1.0.24+25
 
 environment:
   sdk: "^3.0.0"
-- 
GitLab