diff --git a/android/gradle.properties b/android/gradle.properties index 14eed3944b547f02179b1b42f4b601f91b7957c0..aa51064abebb79ba519e600afb7af23779154d4e 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.4 -app.versionCode=4 +app.versionName=0.0.5 +app.versionCode=5 diff --git a/fastlane/metadata/android/en-US/changelogs/5.txt b/fastlane/metadata/android/en-US/changelogs/5.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a25f846a8a914a699b29a1f6d487c1db5c89563 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/5.txt @@ -0,0 +1 @@ +Add counters: moves and remaining pegs \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/5.txt b/fastlane/metadata/android/fr-FR/changelogs/5.txt new file mode 100644 index 0000000000000000000000000000000000000000..dfa97fe4ee9b8e9b87290896f0b978d3e7748770 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/5.txt @@ -0,0 +1 @@ +Ajout des compteurs : nombre de coups et pions restants \ No newline at end of file diff --git a/lib/layout/game.dart b/lib/layout/game.dart index a84f48beb939f5b1c69243f832481628f9099a1d..e0c193b5f55e87056ba426556b929199db77f0e7 100644 --- a/lib/layout/game.dart +++ b/lib/layout/game.dart @@ -35,27 +35,19 @@ class Game { Column( children: [ Text( - 'SCORE', + '♟️ ' + myProvider.remainingPegsCount.toString(), style: TextStyle( fontSize: 40, fontWeight: FontWeight.w600, color: Colors.black, ), ), - Text( - 'TARGET', - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w600, - color: Colors.grey, - ), - ), ], ), Column( children: [ Text( - 'INFOS', + myProvider.movesCount.toString(), style: TextStyle( fontSize: 20, fontWeight: FontWeight.w600, diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 61e1e394c07c8598db1e2dddddbe2ba07c03dc64..4dbc65ca4bb827eba1d95830b398d7ce1b6405f3 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:solitaire_game/entities/tile.dart'; +import 'package:solitaire_game/utils/game_utils.dart'; class Data extends ChangeNotifier { // Configuration available values @@ -26,6 +27,8 @@ class Data extends ChangeNotifier { List<List<Tile?>> _board = []; int _boardSize = 0; double _tileSize = 0; + int _movesCount = 0; + int _remainingPegsCount = 0; String _currentState = ''; void updateParameterSkin(String parameterSkin) { @@ -84,6 +87,7 @@ class Data extends ChangeNotifier { var currentState = { 'skin': _parameterSkin, + 'movesCount': _movesCount.toString(), 'boardValues': boardValues, }; @@ -147,6 +151,7 @@ class Data extends ChangeNotifier { void updateBoard(List<List<Tile?>> board) { _board = board; updateBoardSize(board.length); + updateRemainingPegsCount(GameUtils.countRemainingPegs(this)); notifyListeners(); } @@ -159,6 +164,22 @@ class Data extends ChangeNotifier { } } + int get movesCount => _movesCount; + void updateMovesCount(int movesCount) { + _movesCount = movesCount; + notifyListeners(); + } + + void incrementMovesCount() { + updateMovesCount(movesCount + 1); + } + + int get remainingPegsCount => _remainingPegsCount; + void updateRemainingPegsCount(int remainingPegsCount) { + _remainingPegsCount = remainingPegsCount; + notifyListeners(); + } + bool get gameIsRunning => _gameIsRunning; bool get isGameFinished => !_gameIsRunning; void updateGameIsRunning(bool gameIsRunning) { @@ -172,6 +193,8 @@ class Data extends ChangeNotifier { void resetGame() { _gameIsRunning = false; + _movesCount = 0; + _remainingPegsCount = 0; notifyListeners(); } } diff --git a/lib/utils/board_utils.dart b/lib/utils/board_utils.dart index 5f60126993ddea1db46d2e9f72e7d4d4e4b60b17..ad74ca521767c6cc3aeed49be61cbf2733ed7cee 100644 --- a/lib/utils/board_utils.dart +++ b/lib/utils/board_utils.dart @@ -2,6 +2,7 @@ import 'dart:math'; import 'package:solitaire_game/entities/tile.dart'; import 'package:solitaire_game/provider/data.dart'; +import 'package:solitaire_game/utils/game_utils.dart'; class BoardUtils { static printGrid(List cells) { diff --git a/lib/utils/game_utils.dart b/lib/utils/game_utils.dart index c618e456ea8f3a9cdc662dee00dec690c355c399..9b14d5675a64feec3b886fd1c2ef4fc4574a88c8 100644 --- a/lib/utils/game_utils.dart +++ b/lib/utils/game_utils.dart @@ -1,4 +1,5 @@ import 'package:solitaire_game/entities/tile.dart'; +import 'package:solitaire_game/layout/game.dart'; import 'package:solitaire_game/provider/data.dart'; import 'package:solitaire_game/utils/board_utils.dart'; @@ -24,6 +25,7 @@ class GameUtils { if (savedState.isNotEmpty) { try { myProvider.setParameterValue('skin', savedState['skin']); + myProvider.updateMovesCount(int.parse(savedState['movesCount'])); myProvider.updateBoard( BoardUtils.createBoardFromSavedState(myProvider, savedState['boardValues'])); @@ -101,5 +103,26 @@ class GameUtils { myProvider.updatePegValue(targetRow, targetCol, true); // remove peg from middle tile myProvider.updatePegValue(middleRow, middleCol, false); + + // increment moves count + myProvider.incrementMovesCount(); + // update remaining pegs count + myProvider.updateRemainingPegsCount(GameUtils.countRemainingPegs(myProvider)); + } + + static int countRemainingPegs(Data myProvider) { + int count = 0; + + List<List<Tile?>> board = myProvider.board; + for (var rowIndex = 0; rowIndex < board.length; rowIndex++) { + for (var colIndex = 0; colIndex < board[rowIndex].length; colIndex++) { + Tile? tile = board[rowIndex][colIndex]; + if (tile != null && tile.hasPeg == true) { + count++; + } + } + } + + return count; } }