diff --git a/android/gradle.properties b/android/gradle.properties index 135006f9c1386c8757595c43e890e911f732f5a3..85b94f88ee157e1d1b3cec184c8948902443d36f 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.6 -app.versionCode=6 +app.versionName=0.0.7 +app.versionCode=7 diff --git a/fastlane/metadata/android/en-US/changelogs/7.txt b/fastlane/metadata/android/en-US/changelogs/7.txt new file mode 100644 index 0000000000000000000000000000000000000000..8011497040871ca4da971de9f01b713cfaccbeea --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/7.txt @@ -0,0 +1 @@ +Add check end game \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/7.txt b/fastlane/metadata/android/fr-FR/changelogs/7.txt new file mode 100644 index 0000000000000000000000000000000000000000..a2909428c8f126a4a651b89fa8eacf30fa0f74b5 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/7.txt @@ -0,0 +1 @@ +Ajout du test de fin de partie \ No newline at end of file diff --git a/lib/layout/game.dart b/lib/layout/game.dart index aeeeab7844029cca9f4abcb0d6a1d8548d9d7b77..1b1372758e211f96d90b58c63c79a373f75397c1 100644 --- a/lib/layout/game.dart +++ b/lib/layout/game.dart @@ -5,7 +5,7 @@ import 'package:solitaire_game/utils/game_utils.dart'; class Game { static Container buildGameWidget(Data myProvider) { - bool gameIsFinished = myProvider.isGameFinished; + bool gameIsFinished = myProvider.gameIsFinished; return Container( child: Column( @@ -28,6 +28,8 @@ class Game { } static Widget buildTopIndicatorWidget(Data myProvider) { + int allowedMovesCount = myProvider.allowedMovesCount; + return Table( children: [ TableRow( @@ -47,7 +49,7 @@ class Game { Column( children: [ Text( - GameUtils.countAllowedMoves(myProvider).toString(), + allowedMovesCount.toString(), style: TextStyle( fontSize: 20, fontWeight: FontWeight.w600, @@ -79,7 +81,7 @@ class Game { if (myProvider.gameWon()) { decorationImageAssetName = 'assets/icons/game_win.png'; } else { - decorationImageAssetName = 'assets/icons/game_fail.png'; + decorationImageAssetName = 'assets/icons/placeholder.png'; } Image decorationImage = Image( diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 4dbc65ca4bb827eba1d95830b398d7ce1b6405f3..a1c0aa613df58922f80932382a6f6f34e292edf5 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -24,11 +24,13 @@ class Data extends ChangeNotifier { // Game data bool _assetsPreloaded = false; bool _gameIsRunning = false; + bool _gameIsFinished = false; List<List<Tile?>> _board = []; int _boardSize = 0; double _tileSize = 0; int _movesCount = 0; int _remainingPegsCount = 0; + int _allowedMovesCount = 0; String _currentState = ''; void updateParameterSkin(String parameterSkin) { @@ -152,6 +154,7 @@ class Data extends ChangeNotifier { _board = board; updateBoardSize(board.length); updateRemainingPegsCount(GameUtils.countRemainingPegs(this)); + updateAllowedMovesCount(GameUtils.countAllowedMoves(this)); notifyListeners(); } @@ -180,19 +183,34 @@ class Data extends ChangeNotifier { notifyListeners(); } + int get allowedMovesCount => _allowedMovesCount; + void updateAllowedMovesCount(int allowedMovesCount) { + _allowedMovesCount = allowedMovesCount; + if (allowedMovesCount == 0) { + updateGameIsFinished(true); + } + notifyListeners(); + } + bool get gameIsRunning => _gameIsRunning; - bool get isGameFinished => !_gameIsRunning; + bool get gameIsFinished => _gameIsFinished; void updateGameIsRunning(bool gameIsRunning) { _gameIsRunning = gameIsRunning; notifyListeners(); } + void updateGameIsFinished(bool gameIsFinished) { + _gameIsFinished = gameIsFinished; + notifyListeners(); + } + bool gameWon() { - return isGameFinished; + return gameIsFinished && (remainingPegsCount == 1); } void resetGame() { _gameIsRunning = false; + _gameIsFinished = false; _movesCount = 0; _remainingPegsCount = 0; notifyListeners(); diff --git a/lib/utils/game_utils.dart b/lib/utils/game_utils.dart index 2d7d7cc6f55679be90d86c8e256d930807605645..78b2154ff079dbb82b1feec3b478dd0d5927ef55 100644 --- a/lib/utils/game_utils.dart +++ b/lib/utils/game_utils.dart @@ -124,6 +124,8 @@ class GameUtils { myProvider.incrementMovesCount(); // update remaining pegs count myProvider.updateRemainingPegsCount(GameUtils.countRemainingPegs(myProvider)); + // update allowed moves count + myProvider.updateAllowedMovesCount(GameUtils.countAllowedMoves(myProvider)); } static List<Tile> listRemainingPegs(Data myProvider) { @@ -165,6 +167,7 @@ class GameUtils { } }); }); + return allowedMovesCount; } }