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 org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.6 app.versionName=0.0.7
app.versionCode=6 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'; ...@@ -5,7 +5,7 @@ import 'package:solitaire_game/utils/game_utils.dart';
class Game { class Game {
static Container buildGameWidget(Data myProvider) { static Container buildGameWidget(Data myProvider) {
bool gameIsFinished = myProvider.isGameFinished; bool gameIsFinished = myProvider.gameIsFinished;
return Container( return Container(
child: Column( child: Column(
...@@ -28,6 +28,8 @@ class Game { ...@@ -28,6 +28,8 @@ class Game {
} }
static Widget buildTopIndicatorWidget(Data myProvider) { static Widget buildTopIndicatorWidget(Data myProvider) {
int allowedMovesCount = myProvider.allowedMovesCount;
return Table( return Table(
children: [ children: [
TableRow( TableRow(
...@@ -47,7 +49,7 @@ class Game { ...@@ -47,7 +49,7 @@ class Game {
Column( Column(
children: [ children: [
Text( Text(
GameUtils.countAllowedMoves(myProvider).toString(), allowedMovesCount.toString(),
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
...@@ -79,7 +81,7 @@ class Game { ...@@ -79,7 +81,7 @@ class Game {
if (myProvider.gameWon()) { if (myProvider.gameWon()) {
decorationImageAssetName = 'assets/icons/game_win.png'; decorationImageAssetName = 'assets/icons/game_win.png';
} else { } else {
decorationImageAssetName = 'assets/icons/game_fail.png'; decorationImageAssetName = 'assets/icons/placeholder.png';
} }
Image decorationImage = Image( Image decorationImage = Image(
......
...@@ -24,11 +24,13 @@ class Data extends ChangeNotifier { ...@@ -24,11 +24,13 @@ class Data extends ChangeNotifier {
// Game data // Game data
bool _assetsPreloaded = false; bool _assetsPreloaded = false;
bool _gameIsRunning = false; bool _gameIsRunning = false;
bool _gameIsFinished = false;
List<List<Tile?>> _board = []; List<List<Tile?>> _board = [];
int _boardSize = 0; int _boardSize = 0;
double _tileSize = 0; double _tileSize = 0;
int _movesCount = 0; int _movesCount = 0;
int _remainingPegsCount = 0; int _remainingPegsCount = 0;
int _allowedMovesCount = 0;
String _currentState = ''; String _currentState = '';
void updateParameterSkin(String parameterSkin) { void updateParameterSkin(String parameterSkin) {
...@@ -152,6 +154,7 @@ class Data extends ChangeNotifier { ...@@ -152,6 +154,7 @@ class Data extends ChangeNotifier {
_board = board; _board = board;
updateBoardSize(board.length); updateBoardSize(board.length);
updateRemainingPegsCount(GameUtils.countRemainingPegs(this)); updateRemainingPegsCount(GameUtils.countRemainingPegs(this));
updateAllowedMovesCount(GameUtils.countAllowedMoves(this));
notifyListeners(); notifyListeners();
} }
...@@ -180,19 +183,34 @@ class Data extends ChangeNotifier { ...@@ -180,19 +183,34 @@ class Data extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
int get allowedMovesCount => _allowedMovesCount;
void updateAllowedMovesCount(int allowedMovesCount) {
_allowedMovesCount = allowedMovesCount;
if (allowedMovesCount == 0) {
updateGameIsFinished(true);
}
notifyListeners();
}
bool get gameIsRunning => _gameIsRunning; bool get gameIsRunning => _gameIsRunning;
bool get isGameFinished => !_gameIsRunning; bool get gameIsFinished => _gameIsFinished;
void updateGameIsRunning(bool gameIsRunning) { void updateGameIsRunning(bool gameIsRunning) {
_gameIsRunning = gameIsRunning; _gameIsRunning = gameIsRunning;
notifyListeners(); notifyListeners();
} }
void updateGameIsFinished(bool gameIsFinished) {
_gameIsFinished = gameIsFinished;
notifyListeners();
}
bool gameWon() { bool gameWon() {
return isGameFinished; return gameIsFinished && (remainingPegsCount == 1);
} }
void resetGame() { void resetGame() {
_gameIsRunning = false; _gameIsRunning = false;
_gameIsFinished = false;
_movesCount = 0; _movesCount = 0;
_remainingPegsCount = 0; _remainingPegsCount = 0;
notifyListeners(); notifyListeners();
......
...@@ -124,6 +124,8 @@ class GameUtils { ...@@ -124,6 +124,8 @@ class GameUtils {
myProvider.incrementMovesCount(); myProvider.incrementMovesCount();
// update remaining pegs count // update remaining pegs count
myProvider.updateRemainingPegsCount(GameUtils.countRemainingPegs(myProvider)); myProvider.updateRemainingPegsCount(GameUtils.countRemainingPegs(myProvider));
// update allowed moves count
myProvider.updateAllowedMovesCount(GameUtils.countAllowedMoves(myProvider));
} }
static List<Tile> listRemainingPegs(Data myProvider) { static List<Tile> listRemainingPegs(Data myProvider) {
...@@ -165,6 +167,7 @@ class GameUtils { ...@@ -165,6 +167,7 @@ class GameUtils {
} }
}); });
}); });
return allowedMovesCount; return allowedMovesCount;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment