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

Merge branch '39-fix-end-game' into 'master'

Resolve "Fix end game"

Closes #39

See merge request !34
parents 49fff117 147a86da
No related branches found
No related tags found
1 merge request!34Resolve "Fix end game"
Pipeline #5818 passed
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
Fix game end.
Corrections sur fin de partie.
......@@ -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;
......
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);
......
......@@ -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],
),
],
),
],
);
},
);
......
......@@ -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,
......
......@@ -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(
......
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment