Skip to content
Snippets Groups Projects
Commit 147a86da authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Fix game end

parent 49fff117
Branches
Tags
1 merge request!34Resolve "Fix end game"
Pipeline #5752 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.1.0 app.versionName=0.1.1
app.versionCode=30 app.versionCode=31
Fix game end.
Corrections sur fin de partie.
...@@ -2,7 +2,6 @@ import 'package:equatable/equatable.dart'; ...@@ -2,7 +2,6 @@ import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.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/game/game.dart';
import 'package:momomotus/models/settings/settings_game.dart'; import 'package:momomotus/models/settings/settings_game.dart';
import 'package:momomotus/models/settings/settings_global.dart'; import 'package:momomotus/models/settings/settings_global.dart';
...@@ -30,7 +29,6 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -30,7 +29,6 @@ class GameCubit extends HydratedCubit<GameState> {
// State // State
isRunning: state.currentGame.isRunning, isRunning: state.currentGame.isRunning,
isStarted: state.currentGame.isStarted, isStarted: state.currentGame.isStarted,
isFinished: state.currentGame.isFinished,
animationInProgress: state.currentGame.animationInProgress, animationInProgress: state.currentGame.animationInProgress,
// Base data // Base data
word: state.currentGame.word, word: state.currentGame.word,
...@@ -73,7 +71,6 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -73,7 +71,6 @@ class GameCubit extends HydratedCubit<GameState> {
void deleteSavedGame() { void deleteSavedGame() {
state.currentGame.isRunning = false; state.currentGame.isRunning = false;
state.currentGame.isFinished = true;
refresh(); refresh();
} }
...@@ -171,15 +168,6 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -171,15 +168,6 @@ class GameCubit extends HydratedCubit<GameState> {
return tips; return tips;
} }
bool isGameFinished() {
if (state.currentGame.foundWord ||
(state.currentGame.guesses.length >= DefaultGameSettings.maxGuessesCount)) {
return true;
}
return false;
}
@override @override
GameState? fromJson(Map<String, dynamic> json) { GameState? fromJson(Map<String, dynamic> json) {
final Game currentGame = json['currentGame'] as Game; final Game currentGame = json['currentGame'] as Game;
......
import 'package:momomotus/config/default_game_settings.dart';
import 'package:momomotus/data/fetch_data_helper.dart'; import 'package:momomotus/data/fetch_data_helper.dart';
import 'package:momomotus/models/settings/settings_game.dart'; import 'package:momomotus/models/settings/settings_game.dart';
import 'package:momomotus/models/settings/settings_global.dart'; import 'package:momomotus/models/settings/settings_global.dart';
...@@ -12,7 +13,6 @@ class Game { ...@@ -12,7 +13,6 @@ class Game {
// State // State
this.isRunning = false, this.isRunning = false,
this.isStarted = false, this.isStarted = false,
this.isFinished = false,
this.animationInProgress = false, this.animationInProgress = false,
// Base data // Base data
...@@ -33,7 +33,6 @@ class Game { ...@@ -33,7 +33,6 @@ class Game {
// State // State
bool isRunning; bool isRunning;
bool isStarted; bool isStarted;
bool isFinished;
bool animationInProgress; bool animationInProgress;
// Base data // Base data
...@@ -97,6 +96,13 @@ class Game { ...@@ -97,6 +96,13 @@ class Game {
bool get canBeResumed => isStarted && !isFinished; bool get canBeResumed => isStarted && !isFinished;
bool get gameWon => isRunning && 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) { bool checkWordIsValid(String candidate) {
final int length = int.parse(gameSettings.length); final int length = int.parse(gameSettings.length);
......
...@@ -20,10 +20,7 @@ class GameEndWidget extends StatelessWidget { ...@@ -20,10 +20,7 @@ class GameEndWidget extends StatelessWidget {
fit: BoxFit.fill, fit: BoxFit.fill,
); );
return Container( return Table(
margin: const EdgeInsets.all(2),
padding: const EdgeInsets.all(2),
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(), defaultColumnWidth: const IntrinsicColumnWidth(),
children: [ children: [
TableRow( TableRow(
...@@ -44,7 +41,6 @@ class GameEndWidget extends StatelessWidget { ...@@ -44,7 +41,6 @@ class GameEndWidget extends StatelessWidget {
], ],
), ),
], ],
),
); );
}, },
); );
......
...@@ -8,7 +8,7 @@ class QuitGameButton extends StatelessWidget { ...@@ -8,7 +8,7 @@ class QuitGameButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextButton( return ElevatedButton(
child: const Image( child: const Image(
image: AssetImage('assets/ui/button_back.png'), image: AssetImage('assets/ui/button_back.png'),
fit: BoxFit.fill, fit: BoxFit.fill,
......
...@@ -44,12 +44,12 @@ class GameBoardWidget extends StatelessWidget { ...@@ -44,12 +44,12 @@ class GameBoardWidget extends StatelessWidget {
cellTip = tips[colIndex]; cellTip = tips[colIndex];
} }
final bool hasFocus = (!currentGame.gameWon) && final bool hasFocus = (!currentGame.foundWord) &&
(lineIndex == guesses.length) && (lineIndex == guesses.length) &&
(colIndex == word.length); (colIndex == word.length);
final String foundLetter = final String foundLetter =
((!currentGame.gameWon) && (lineIndex == guesses.length)) ((!currentGame.foundWord) && (lineIndex == guesses.length))
? currentGame.foundLetters.substring(colIndex, colIndex + 1) ? currentGame.foundLetters.substring(colIndex, colIndex + 1)
: ' '; : ' ';
...@@ -85,7 +85,8 @@ class GameBoardWidget extends StatelessWidget { ...@@ -85,7 +85,8 @@ class GameBoardWidget extends StatelessWidget {
} }
} }
if (gameCubit.isGameFinished() && !currentGame.gameWon) { // Failed -> show word
if (currentGame.isFinished && !currentGame.gameWon) {
gameBoard.add(Text( gameBoard.add(Text(
currentGame.word, currentGame.word,
style: const TextStyle( style: const TextStyle(
......
...@@ -3,7 +3,7 @@ description: A motus-like game application. ...@@ -3,7 +3,7 @@ description: A motus-like game application.
publish_to: "none" publish_to: "none"
version: 0.1.0+30 version: 0.1.1+31
environment: environment:
sdk: "^3.0.0" sdk: "^3.0.0"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment