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

Display mines count indicator

parent de524c14
No related branches found
No related tags found
1 merge request!8Resolve "Display mines count indicator"
Pipeline #1828 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
Display mines count indicator
Affichage d'un compteur de mines
import 'package:flutter/material.dart';
import '../provider/data.dart';
import '../utils/board_utils.dart';
class Board {
......@@ -18,7 +19,12 @@ class Board {
width: 2,
),
),
child: buildGameTileset(myProvider),
child: Column(
children: [
buildGameTileset(myProvider),
buildMinesCounterWidget(myProvider),
],
),
);
}
......@@ -79,4 +85,19 @@ class Board {
);
}
static Container buildMinesCounterWidget(Data myProvider) {
String markedMinesCount = BoardUtils.countFlaggedCells(myProvider.cells).toString();
String placedMinesCount = myProvider.minesCount.toString();
return Container(
child: Text(
markedMinesCount + ' / ' + placedMinesCount,
style: TextStyle(
fontSize: 20,
color: Colors.white
),
),
);
}
}
......@@ -17,6 +17,7 @@ class Data extends ChangeNotifier {
// Game data
bool _gameRunning = false;
bool _isBoardMined = false;
int _minesCount = 0;
bool _gameWin = false;
bool _gameFail = false;
bool _reportMode = false;
......@@ -109,6 +110,11 @@ class Data extends ChangeNotifier {
notifyListeners();
}
int get minesCount => _minesCount;
void updateMinesCount(int minesCount) {
_minesCount = minesCount;
}
bool get gameWin => _gameWin;
void updateGameWin(bool gameWin) {
_gameWin = gameWin;
......
......@@ -108,8 +108,7 @@ class BoardUtils {
allowedCells.shuffle();
// Put random mines on board
int minesCount = getMinesCount(sizeHorizontal, sizeVertical, level);
for (var mineIndex = 0; mineIndex < minesCount; mineIndex++) {
for (var mineIndex = 0; mineIndex < myProvider.minesCount; mineIndex++) {
cells[allowedCells[mineIndex][0]][allowedCells[mineIndex][1]].isMined = true;
}
......@@ -234,4 +233,20 @@ class BoardUtils {
return true;
}
static int countFlaggedCells(List cells) {
int count = 0;
int sizeHorizontal = cells.length;
int sizeVertical = cells[0].length;
for (var row = 0; row < sizeVertical; row++) {
for (var col = 0; col < sizeHorizontal; col++) {
if (cells[row][col].isMarked == true) {
count++;
}
}
}
return count;
}
}
......@@ -10,6 +10,7 @@ class GameUtils {
static void startGame(Data myProvider) {
print('Starting game: ' + myProvider.size + ' - ' + myProvider.level);
myProvider.updateSize(myProvider.size);
myProvider.updateMinesCount(BoardUtils.getMinesCount(myProvider.sizeHorizontal, myProvider.sizeVertical, myProvider.level));
myProvider.updateGameRunning(true);
BoardUtils.createInitialEmptyBoard(myProvider);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment