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

Count and display moves during game

parent 8b033e15
No related branches found
No related tags found
1 merge request!4Resolve "Count moves"
Pipeline #2722 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.3 app.versionName=0.0.4
app.versionCode=3 app.versionCode=4
...@@ -17,6 +17,18 @@ class Game { ...@@ -17,6 +17,18 @@ class Game {
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
SizedBox(height: 8),
Container(
child: Text(
myProvider.movesCount.toString(),
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.w600,
color: Colors.black,
),
),
),
SizedBox(height: 2),
Expanded( Expanded(
child: Board.buildGameBoard(myProvider), child: Board.buildGameBoard(myProvider),
), ),
......
...@@ -21,6 +21,7 @@ class Data extends ChangeNotifier { ...@@ -21,6 +21,7 @@ class Data extends ChangeNotifier {
bool _gameWon = false; bool _gameWon = false;
int _boardSize = 0; int _boardSize = 0;
int _colorsCount = 0; int _colorsCount = 0;
int _movesCount = 0;
List _cells = []; List _cells = [];
String get level => _level; String get level => _level;
...@@ -125,6 +126,15 @@ class Data extends ChangeNotifier { ...@@ -125,6 +126,15 @@ class Data extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
int get movesCount => _movesCount;
void updateMovesCount(int movesCount) {
_movesCount = movesCount;
notifyListeners();
}
void incrementMovesCount() {
updateMovesCount(movesCount + 1);
}
bool get gameIsRunning => _gameIsRunning; bool get gameIsRunning => _gameIsRunning;
void updateGameIsRunning(bool gameIsRunning) { void updateGameIsRunning(bool gameIsRunning) {
_gameIsRunning = gameIsRunning; _gameIsRunning = gameIsRunning;
...@@ -144,6 +154,7 @@ class Data extends ChangeNotifier { ...@@ -144,6 +154,7 @@ class Data extends ChangeNotifier {
void resetGame() { void resetGame() {
_gameIsRunning = false; _gameIsRunning = false;
_gameWon = false; _gameWon = false;
_movesCount = 0;
notifyListeners(); notifyListeners();
} }
......
...@@ -47,6 +47,8 @@ class BoardUtils { ...@@ -47,6 +47,8 @@ class BoardUtils {
for (var cellIndex = 0; cellIndex < cellsToFill.length; cellIndex++) { for (var cellIndex = 0; cellIndex < cellsToFill.length; cellIndex++) {
myProvider.updateCellValue(cellsToFill[cellIndex][1], cellsToFill[cellIndex][0], value); myProvider.updateCellValue(cellsToFill[cellIndex][1], cellsToFill[cellIndex][0], value);
} }
myProvider.incrementMovesCount();
} }
static List getSiblingFillableCells(Data myProvider, row, col, siblingCells) { static List getSiblingFillableCells(Data myProvider, row, col, siblingCells) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment