From 147a86da16285cee821290a30bc0a1cac36c8887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Sun, 7 Jul 2024 16:10:31 +0200 Subject: [PATCH] Fix game end --- android/gradle.properties | 4 +- .../metadata/android/en-US/changelogs/31.txt | 1 + .../metadata/android/fr-FR/changelogs/31.txt | 1 + lib/cubit/game_cubit.dart | 12 ----- lib/models/game/game.dart | 10 +++- lib/ui/game/game_end.dart | 46 +++++++++---------- lib/ui/widgets/actions/button_game_quit.dart | 2 +- lib/ui/widgets/game/game_board.dart | 7 +-- pubspec.yaml | 2 +- 9 files changed, 39 insertions(+), 46 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/31.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/31.txt diff --git a/android/gradle.properties b/android/gradle.properties index f93f181..fe70351 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.1.0 -app.versionCode=30 +app.versionName=0.1.1 +app.versionCode=31 diff --git a/fastlane/metadata/android/en-US/changelogs/31.txt b/fastlane/metadata/android/en-US/changelogs/31.txt new file mode 100644 index 0000000..120738e --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/31.txt @@ -0,0 +1 @@ +Fix game end. diff --git a/fastlane/metadata/android/fr-FR/changelogs/31.txt b/fastlane/metadata/android/fr-FR/changelogs/31.txt new file mode 100644 index 0000000..d7891f0 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/31.txt @@ -0,0 +1 @@ +Corrections sur fin de partie. diff --git a/lib/cubit/game_cubit.dart b/lib/cubit/game_cubit.dart index d208274..b11d400 100644 --- a/lib/cubit/game_cubit.dart +++ b/lib/cubit/game_cubit.dart @@ -2,7 +2,6 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart'; -import 'package:momomotus/config/default_game_settings.dart'; import 'package:momomotus/models/game/game.dart'; import 'package:momomotus/models/settings/settings_game.dart'; import 'package:momomotus/models/settings/settings_global.dart'; @@ -30,7 +29,6 @@ class GameCubit extends HydratedCubit<GameState> { // State isRunning: state.currentGame.isRunning, isStarted: state.currentGame.isStarted, - isFinished: state.currentGame.isFinished, animationInProgress: state.currentGame.animationInProgress, // Base data word: state.currentGame.word, @@ -73,7 +71,6 @@ class GameCubit extends HydratedCubit<GameState> { void deleteSavedGame() { state.currentGame.isRunning = false; - state.currentGame.isFinished = true; refresh(); } @@ -171,15 +168,6 @@ class GameCubit extends HydratedCubit<GameState> { return tips; } - bool isGameFinished() { - if (state.currentGame.foundWord || - (state.currentGame.guesses.length >= DefaultGameSettings.maxGuessesCount)) { - return true; - } - - return false; - } - @override GameState? fromJson(Map<String, dynamic> json) { final Game currentGame = json['currentGame'] as Game; diff --git a/lib/models/game/game.dart b/lib/models/game/game.dart index 3477022..aa36706 100644 --- a/lib/models/game/game.dart +++ b/lib/models/game/game.dart @@ -1,3 +1,4 @@ +import 'package:momomotus/config/default_game_settings.dart'; import 'package:momomotus/data/fetch_data_helper.dart'; import 'package:momomotus/models/settings/settings_game.dart'; import 'package:momomotus/models/settings/settings_global.dart'; @@ -12,7 +13,6 @@ class Game { // State this.isRunning = false, this.isStarted = false, - this.isFinished = false, this.animationInProgress = false, // Base data @@ -33,7 +33,6 @@ class Game { // State bool isRunning; bool isStarted; - bool isFinished; bool animationInProgress; // Base data @@ -97,6 +96,13 @@ class Game { bool get canBeResumed => isStarted && !isFinished; bool get gameWon => isRunning && isStarted && isFinished; + bool get isFinished { + if (foundWord || (guesses.length >= DefaultGameSettings.maxGuessesCount)) { + return true; + } + + return false; + } bool checkWordIsValid(String candidate) { final int length = int.parse(gameSettings.length); diff --git a/lib/ui/game/game_end.dart b/lib/ui/game/game_end.dart index eb53af9..6c1c8b5 100644 --- a/lib/ui/game/game_end.dart +++ b/lib/ui/game/game_end.dart @@ -20,31 +20,27 @@ class GameEndWidget extends StatelessWidget { fit: BoxFit.fill, ); - return Container( - margin: const EdgeInsets.all(2), - padding: const EdgeInsets.all(2), - child: Table( - defaultColumnWidth: const IntrinsicColumnWidth(), - children: [ - TableRow( - children: [ - Column( - children: [decorationImage], - ), - Column( - children: [ - currentGame.animationInProgress == true - ? decorationImage - : const QuitGameButton() - ], - ), - Column( - children: [decorationImage], - ), - ], - ), - ], - ), + return Table( + defaultColumnWidth: const IntrinsicColumnWidth(), + children: [ + TableRow( + children: [ + Column( + children: [decorationImage], + ), + Column( + children: [ + currentGame.animationInProgress == true + ? decorationImage + : const QuitGameButton() + ], + ), + Column( + children: [decorationImage], + ), + ], + ), + ], ); }, ); diff --git a/lib/ui/widgets/actions/button_game_quit.dart b/lib/ui/widgets/actions/button_game_quit.dart index 3c018f0..c2da533 100644 --- a/lib/ui/widgets/actions/button_game_quit.dart +++ b/lib/ui/widgets/actions/button_game_quit.dart @@ -8,7 +8,7 @@ class QuitGameButton extends StatelessWidget { @override Widget build(BuildContext context) { - return TextButton( + return ElevatedButton( child: const Image( image: AssetImage('assets/ui/button_back.png'), fit: BoxFit.fill, diff --git a/lib/ui/widgets/game/game_board.dart b/lib/ui/widgets/game/game_board.dart index 859cbb0..81defff 100644 --- a/lib/ui/widgets/game/game_board.dart +++ b/lib/ui/widgets/game/game_board.dart @@ -44,12 +44,12 @@ class GameBoardWidget extends StatelessWidget { cellTip = tips[colIndex]; } - final bool hasFocus = (!currentGame.gameWon) && + final bool hasFocus = (!currentGame.foundWord) && (lineIndex == guesses.length) && (colIndex == word.length); final String foundLetter = - ((!currentGame.gameWon) && (lineIndex == guesses.length)) + ((!currentGame.foundWord) && (lineIndex == guesses.length)) ? currentGame.foundLetters.substring(colIndex, colIndex + 1) : ' '; @@ -85,7 +85,8 @@ class GameBoardWidget extends StatelessWidget { } } - if (gameCubit.isGameFinished() && !currentGame.gameWon) { + // Failed -> show word + if (currentGame.isFinished && !currentGame.gameWon) { gameBoard.add(Text( currentGame.word, style: const TextStyle( diff --git a/pubspec.yaml b/pubspec.yaml index 1196902..45a416a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A motus-like game application. publish_to: "none" -version: 0.1.0+30 +version: 0.1.1+31 environment: sdk: "^3.0.0" -- GitLab