From 68d97b108865d1443a6bdae98b82f25dc87f3c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Thu, 2 Jun 2022 15:53:48 +0200 Subject: [PATCH] Compute and display a "target" moves count --- android/gradle.properties | 4 ++-- lib/layout/game.dart | 8 ++++++++ lib/provider/data.dart | 7 +++++++ lib/utils/board_utils.dart | 8 ++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index aa51064..135006f 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.5 -app.versionCode=5 +app.versionName=0.0.6 +app.versionCode=6 diff --git a/lib/layout/game.dart b/lib/layout/game.dart index 0c70fe6..558cde4 100644 --- a/lib/layout/game.dart +++ b/lib/layout/game.dart @@ -55,6 +55,14 @@ class Game { color: Colors.black, ), ), + Text( + '(max: ' + myProvider.maxMovesCount.toString() + ')', + style: TextStyle( + fontSize: 15, + fontWeight: FontWeight.w600, + color: Colors.grey, + ), + ), ] ), Column( diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 3ecfa09..6b31d5e 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -22,6 +22,7 @@ class Data extends ChangeNotifier { int _boardSize = 0; int _colorsCount = 0; int _movesCount = 0; + int _maxMovesCount = 0; List _cells = []; int _progress = 0; @@ -140,6 +141,11 @@ class Data extends ChangeNotifier { updateMovesCount(movesCount + 1); } + int get maxMovesCount => _maxMovesCount; + void updateMaxMovesCount(int maxMovesCount) { + _maxMovesCount = maxMovesCount; + } + int get progress => _progress; int get progressTotal => _progressTotal; int get progressDelta => _progressDelta; @@ -176,6 +182,7 @@ class Data extends ChangeNotifier { _gameIsRunning = false; _gameWon = false; _movesCount = 0; + _maxMovesCount = 0; _progress = 0; notifyListeners(); } diff --git a/lib/utils/board_utils.dart b/lib/utils/board_utils.dart index 405685c..5127b15 100644 --- a/lib/utils/board_utils.dart +++ b/lib/utils/board_utils.dart @@ -39,11 +39,19 @@ class BoardUtils { myProvider.resetGame(); myProvider.updateCells(grid); + myProvider.updateMaxMovesCount(computeMaxMovesCountLimit(myProvider)); int initProgress = BoardUtils.getSiblingFillableCells(myProvider, 0, 0, [[0, 0]]).length; myProvider.updateProgress(initProgress); } + static int computeMaxMovesCountLimit(myProvider) { + int boardSize = myProvider.boardSize; + int colorsCount = myProvider.colorsCount; + + return (30 * (boardSize * colorsCount) / (17 * 6)).round(); + } + static fillBoardFromFirstCell(Data myProvider, int value) { List cellsToFill = BoardUtils.getSiblingFillableCells(myProvider, 0, 0, [[0, 0]]); int progressBeforeMove = cellsToFill.length; -- GitLab