From e4afe613d7727428f1747d1fd04651ba667d5e69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr>
Date: Thu, 2 Jun 2022 15:23:47 +0200
Subject: [PATCH] Count and display moves during game

---
 android/gradle.properties  |  4 ++--
 lib/layout/game.dart       | 12 ++++++++++++
 lib/provider/data.dart     | 11 +++++++++++
 lib/utils/board_utils.dart |  2 ++
 4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/android/gradle.properties b/android/gradle.properties
index db7a1ee..14eed39 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=0.0.3
-app.versionCode=3
+app.versionName=0.0.4
+app.versionCode=4
diff --git a/lib/layout/game.dart b/lib/layout/game.dart
index b2720f6..342f1a2 100644
--- a/lib/layout/game.dart
+++ b/lib/layout/game.dart
@@ -17,6 +17,18 @@ class Game {
         mainAxisAlignment: MainAxisAlignment.start,
         crossAxisAlignment: CrossAxisAlignment.center,
         children: [
+          SizedBox(height: 8),
+          Container(
+            child: Text(
+              myProvider.movesCount.toString(),
+              style: TextStyle(
+                fontSize: 40,
+                fontWeight: FontWeight.w600,
+                color: Colors.black,
+              ),
+            ),
+          ),
+          SizedBox(height: 2),
           Expanded(
             child: Board.buildGameBoard(myProvider),
           ),
diff --git a/lib/provider/data.dart b/lib/provider/data.dart
index 9a16b9d..4f044ed 100644
--- a/lib/provider/data.dart
+++ b/lib/provider/data.dart
@@ -21,6 +21,7 @@ class Data extends ChangeNotifier {
   bool _gameWon = false;
   int _boardSize = 0;
   int _colorsCount = 0;
+  int _movesCount = 0;
   List _cells = [];
 
   String get level => _level;
@@ -125,6 +126,15 @@ class Data extends ChangeNotifier {
     notifyListeners();
   }
 
+  int get movesCount => _movesCount;
+  void updateMovesCount(int movesCount) {
+    _movesCount = movesCount;
+    notifyListeners();
+  }
+  void incrementMovesCount() {
+    updateMovesCount(movesCount + 1);
+  }
+
   bool get gameIsRunning => _gameIsRunning;
   void updateGameIsRunning(bool gameIsRunning) {
     _gameIsRunning = gameIsRunning;
@@ -144,6 +154,7 @@ class Data extends ChangeNotifier {
   void resetGame() {
     _gameIsRunning = false;
     _gameWon = false;
+    _movesCount = 0;
     notifyListeners();
   }
 
diff --git a/lib/utils/board_utils.dart b/lib/utils/board_utils.dart
index 61848e3..6971073 100644
--- a/lib/utils/board_utils.dart
+++ b/lib/utils/board_utils.dart
@@ -47,6 +47,8 @@ class BoardUtils {
     for (var cellIndex = 0; cellIndex < cellsToFill.length; cellIndex++) {
       myProvider.updateCellValue(cellsToFill[cellIndex][1], cellsToFill[cellIndex][0], value);
     }
+
+    myProvider.incrementMovesCount();
   }
 
   static List getSiblingFillableCells(Data myProvider, row, col, siblingCells) {
-- 
GitLab