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

Merge branch '8-check-end-game' into 'master'

Resolve "Check end game"

Closes #8

See merge request !7
parents 773e64d8 54fb2799
No related branches found
No related tags found
1 merge request!7Resolve "Check end game"
Pipeline #3402 passed
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
Add check end game
\ No newline at end of file
Ajout du test de fin de partie
\ No newline at end of file
......@@ -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(
......
......@@ -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();
......
......@@ -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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment