Select Git revision
game_utils.dart
-
Benoît Harrault authoredBenoît Harrault authored
cell.dart 2.74 KiB
import 'package:flutter/material.dart';
import '../provider/data.dart';
import '../utils/board_utils.dart';
class Cell {
bool isMined = false;
bool isExplored = false;
bool isMarked = false;
bool isExploded = false;
int minesCountAround = 0;
Cell(
@required this.isMined,
);
Container widget(Data myProvider, int row, int col) {
bool showSolution = myProvider.gameWin || myProvider.gameFail;
Color backgroundColor = this.getBackgroundColor(myProvider);
String imageAsset = this.getImageAssetName(myProvider.skin, showSolution);
return Container(
decoration: BoxDecoration(
color: backgroundColor,
border: Border.all(
color: Colors.grey,
width: 1,
),
),
child: GestureDetector(
child: Image(
image: AssetImage(imageAsset),
fit: BoxFit.fill,
),
onTap: () {
if (!myProvider.isBoardMined) {
myProvider.updateCells(BoardUtils.createBoard(myProvider, row, col));
myProvider.updateIsBoardMined(true);
}
if (!(myProvider.gameWin || myProvider.gameFail)) {
if (myProvider.reportMode) {
BoardUtils.reportCell(myProvider, row, col);
} else {
BoardUtils.walkOnCell(myProvider, row, col);
}
}
BoardUtils.checkGameIsFinished(myProvider);
},
),
);
}
String getImageAssetName(String skin, bool showSolution) {
String imageAsset = 'assets/skins/' + skin + '_tile_unknown.png';
if (!showSolution) {
// Running game
if (this.isExplored) {
if (this.isMined) {
// Boom
imageAsset = 'assets/skins/' + skin + '_tile_mine.png';
} else {
// Show mines count around
imageAsset = 'assets/skins/' + skin + '_tile_' + this.minesCountAround.toString() + '.png';
}
} else {
if (this.isMarked) {
// Danger!