diff --git a/android/gradle.properties b/android/gradle.properties index 818e87b23b224ced309ae5c147e5ed827826e237..db7a1ee2908d6e94aeb319e1c1b548a8bb245891 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.2 -app.versionCode=2 +app.versionName=0.0.3 +app.versionCode=3 diff --git a/assets/ui/game_draw.png b/assets/ui/game_draw.png new file mode 100644 index 0000000000000000000000000000000000000000..047508dc7427561315ec1c3834f25ab888324c06 Binary files /dev/null and b/assets/ui/game_draw.png differ diff --git a/assets/ui/game_fail.png b/assets/ui/game_fail.png index 93f2801f9d6bb2ce508e1293cd64d6ff2e9970ec..047508dc7427561315ec1c3834f25ab888324c06 100644 Binary files a/assets/ui/game_fail.png and b/assets/ui/game_fail.png differ diff --git a/fastlane/metadata/android/en-US/changelogs/3.txt b/fastlane/metadata/android/en-US/changelogs/3.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0f6ddff22abedd8b4c519dfdc64ebeede9bfec8 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/3.txt @@ -0,0 +1 @@ +End game management. diff --git a/fastlane/metadata/android/fr-FR/changelogs/3.txt b/fastlane/metadata/android/fr-FR/changelogs/3.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c328914537950e087348354c8cfb7f757722991 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/3.txt @@ -0,0 +1 @@ +Gestion de la fin de partie. diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart index 6f80a6134baa14c33d69a7561a3eae76e6b5df25..ecc7b78a2c63a4f5b05fcfd891612c85028affff 100644 --- a/lib/cubit/game_cubit.dart +++ b/lib/cubit/game_cubit.dart @@ -37,7 +37,7 @@ class GameCubit extends HydratedCubit<GameState> { currentPlayer: state.currentGame.currentPlayer, scores: state.currentGame.scores, ); - game.dump(); + // game.dump(); updateState(game); } @@ -108,6 +108,12 @@ class GameCubit extends HydratedCubit<GameState> { toggleCurrentPlayer(); + if (!state.currentGame.canPlay()) { + printlog('user has no more move to play'); + state.currentGame.isFinished = true; + refresh(); + } + state.currentGame.animationInProgress = false; refresh(); } @@ -139,17 +145,20 @@ class GameCubit extends HydratedCubit<GameState> { if (state.currentGame.isOpponentHouse(lastCellIndex)) { final int seedsCount = state.currentGame.board.cells[lastCellIndex]; - printlog('found $seedsCount seed(s) on final house.'); + printlog('found $seedsCount seed(s) on final house'); if ([2, 3].contains(seedsCount)) { - printlog('ok will earn these seeds.'); + printlog('-> ok will earn these seeds'); state.currentGame.board.cells[lastCellIndex] = 0; state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount; refresh(); // (recursively) check previous cells + printlog('-> dispatch to previous cell'); animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex)); + } else { + printlog('-> nothing to do'); } } } diff --git a/lib/models/game/game.dart b/lib/models/game/game.dart index df87774498bd92650494ef70cdbb33cafab85353..74288db3b8be68459d82c99a3dbefc1c25fbbd60 100644 --- a/lib/models/game/game.dart +++ b/lib/models/game/game.dart @@ -124,6 +124,15 @@ class Game { return false; } + bool canPlay() { + for (int cellIndex = 0; cellIndex < board.cells.length; cellIndex++) { + if (isCurrentPlayerHouse(cellIndex) && isMoveAllowed(cellIndex)) { + return true; + } + } + return false; + } + void dump() { printlog(''); printlog('## Current game dump:'); diff --git a/lib/ui/widgets/game/game_board.dart b/lib/ui/widgets/game/game_board.dart index 91715a8c4469e6c7599b94338562e2e990b65d54..d8273bf5478c6b4af7a008929a4cf193678de9e1 100644 --- a/lib/ui/widgets/game/game_board.dart +++ b/lib/ui/widgets/game/game_board.dart @@ -39,7 +39,7 @@ class GameBoardWidget extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.center, children: [ GamePlayerWidget( - active: currentGame.currentPlayer == 0, + active: !currentGame.isFinished && currentGame.currentPlayer == 0, ), Container( margin: const EdgeInsets.all(2), @@ -95,7 +95,7 @@ class GameBoardWidget extends StatelessWidget { ), ), GamePlayerWidget( - active: currentGame.currentPlayer == 1, + active: !currentGame.isFinished && currentGame.currentPlayer == 1, ), ], ); diff --git a/lib/ui/widgets/game/game_end.dart b/lib/ui/widgets/game/game_end.dart index f94c8b89229de2922492e2ff7f038dd06fbef6c4..12add5f0d2a92c88b29e0eded194067bcd15bb25 100644 --- a/lib/ui/widgets/game/game_end.dart +++ b/lib/ui/widgets/game/game_end.dart @@ -14,10 +14,25 @@ class GameEndWidget extends StatelessWidget { builder: (BuildContext context, GameState gameState) { final Game currentGame = gameState.currentGame; - const Image decorationImage = Image( + const Image imageWinner = Image( image: AssetImage('assets/ui/game_win.png'), fit: BoxFit.fill, ); + const Image imageLoser = Image( + image: AssetImage('assets/ui/game_fail.png'), + fit: BoxFit.fill, + ); + const Image imageDraw = Image( + image: AssetImage('assets/ui/game_draw.png'), + fit: BoxFit.fill, + ); + + final Image player1 = currentGame.scores[0] == currentGame.scores[1] + ? imageDraw + : (currentGame.scores[0] > currentGame.scores[1] ? imageWinner : imageLoser); + final Image player2 = currentGame.scores[0] == currentGame.scores[1] + ? imageDraw + : (currentGame.scores[1] > currentGame.scores[0] ? imageWinner : imageLoser); return Container( margin: const EdgeInsets.all(2), @@ -27,18 +42,16 @@ class GameEndWidget extends StatelessWidget { children: [ TableRow( children: [ - const Column( - children: [decorationImage], + Column( + children: [player1], ), Column( children: [ - currentGame.animationInProgress - ? decorationImage - : const QuitGameButton() + currentGame.animationInProgress ? imageWinner : const QuitGameButton() ], ), - const Column( - children: [decorationImage], + Column( + children: [player2], ), ], ), diff --git a/pubspec.yaml b/pubspec.yaml index 7d63e14c0b6da81ef06c0a2a39d14a1d7e19ac7a..bf03338c9cbc32b227e8ad2b4e3ae2e053b12b4d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Awale game publish_to: "none" -version: 0.0.2+2 +version: 0.0.3+3 environment: sdk: "^3.0.0" diff --git a/resources/ui/images/game_draw.svg b/resources/ui/images/game_draw.svg new file mode 100644 index 0000000000000000000000000000000000000000..d988c4937ec1d00ce581b412ff4a859a0fd1862d --- /dev/null +++ b/resources/ui/images/game_draw.svg @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 93.665 93.676" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"/> diff --git a/resources/ui/images/game_fail.svg b/resources/ui/images/game_fail.svg index 2922fd7adc2bd2e813836c728f095376c73d4143..d988c4937ec1d00ce581b412ff4a859a0fd1862d 100644 --- a/resources/ui/images/game_fail.svg +++ b/resources/ui/images/game_fail.svg @@ -1,2 +1,2 @@ <?xml version="1.0" encoding="UTF-8"?> -<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 93.665 93.676" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><rect x=".44662" y=".89101" width="92.772" height="91.894" ry="11.689" fill="#d11717" stroke="#fff" stroke-width=".238"/><path d="m71.624 59.304c3.5089 3.5089 3.5089 9.0561 0 12.565-1.6976 1.6976-3.9623 2.6034-6.2261 2.6034s-4.5275-0.90569-6.2261-2.6034l-12.452-12.452-12.452 12.452c-1.6976 1.6976-3.9623 2.6034-6.2261 2.6034s-4.5275-0.90569-6.2261-2.6034c-3.5089-3.5089-3.5089-9.0561 0-12.565l12.452-12.452-12.452-12.452c-3.5089-3.5089-3.5089-9.0561 0-12.565s9.0561-3.5089 12.565 0l12.452 12.452 12.452-12.452c3.5089-3.5089 9.0561-3.5089 12.565 0s3.5089 9.0561 0 12.565l-12.452 12.452z" fill="#e7e7e7" stroke-width=".20213"/></svg> +<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 93.665 93.676" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"/>