Select Git revision
-
Benoît Harrault authoredBenoît Harrault authored
cell.dart 4.26 KiB
import 'package:flutter/material.dart';
import 'package:minehunter/provider/data.dart';
import 'package:minehunter/utils/board_animate.dart';
import 'package:minehunter/utils/board_utils.dart';
class Cell {
bool isMined = false;
bool isExplored = false;
bool isMarked = false;
bool isExploded = false;
int minesCountAround = 0;
bool isAnimated = false;
Cell(
this.isMined,
);
/*
* Build widget for board cell, with interactions
*/
Container widget(Data myProvider, int row, int col) {
String imageAsset = getImageAssetName(myProvider);
return Container(
decoration: BoxDecoration(
color: getBackgroundColor(myProvider),
border: getCellBorders(myProvider, row, col),
),
child: GestureDetector(
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 100),
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(scale: animation, child: child);
},
child: Image(
image: AssetImage(imageAsset),
fit: BoxFit.fill,
key: ValueKey<int>(imageAsset.hashCode),
),
),
onTap: () {
// Set mines on board after first player try
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);
}
if (BoardUtils.checkGameIsFinished(myProvider)) {
myProvider.updateReportMode(false);
BoardAnimate.startAnimation(myProvider, myProvider.gameWin ? 'win' : 'fail');
}
}
},
),
);
}
/*
* Compute image asset name, from skin and cell value/state
*/
String getImageAssetName(Data myProvider) {
String imageAsset = 'assets/skins/${myProvider.parameterSkin}_tile_unknown.png';