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

Merge branch '13-improve-winning-game-screen' into 'master'

Resolve "Improve winning game screen"

Closes #13

See merge request !12
parents ab08cc73 a6e245bd
No related branches found
No related tags found
1 merge request!12Resolve "Improve winning game screen"
Pipeline #1882 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.10
app.versionCode=10
app.versionName=0.0.11
app.versionCode=11
Add animation on game end
Ajout d'animation en fin de partie
......@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../provider/data.dart';
import '../utils/board_utils.dart';
import '../utils/board_animate.dart';
class Cell {
bool isMined = false;
......@@ -9,6 +10,7 @@ class Cell {
bool isMarked = false;
bool isExploded = false;
int minesCountAround = 0;
bool isAnimated = false;
Cell(
@required this.isMined,
......@@ -18,13 +20,14 @@ class Cell {
bool showSolution = myProvider.gameWin || myProvider.gameFail;
Color backgroundColor = this.getBackgroundColor(myProvider);
Color borderColor = this.getBorderColor(myProvider);
String imageAsset = this.getImageAssetName(myProvider.skin, showSolution);
return Container(
decoration: BoxDecoration(
color: backgroundColor,
border: Border.all(
color: Colors.grey,
color: borderColor,
width: 1,
),
),
......@@ -45,8 +48,11 @@ class Cell {
} else {
BoardUtils.walkOnCell(myProvider, row, col);
}
if (BoardUtils.checkGameIsFinished(myProvider)) {
myProvider.updateReportMode(false);
BoardAnimate.startAnimation(myProvider);
}
}
BoardUtils.checkGameIsFinished(myProvider);
},
),
);
......@@ -92,11 +98,21 @@ class Cell {
Color getBackgroundColor(Data myProvider) {
if (myProvider.gameWin) {
return Colors.green[300];
return this.isAnimated ? Colors.green[400] : Colors.green[500];
} else if (myProvider.gameFail) {
return this.isAnimated ? Colors.pink[300] : Colors.pink[400];
}
return this.isAnimated ? Colors.white : Colors.grey[200];
}
Color getBorderColor(Data myProvider) {
if (myProvider.gameWin) {
return Colors.green[700];
} else if (myProvider.gameFail) {
return Colors.pink[200];
return Colors.pink[300];
}
return Colors.white;
return Colors.grey[500];
}
}
......@@ -56,7 +56,7 @@ class Game {
TableRow(
children: [
Column(children: [ decorationImage ]),
Column(children: [ buildRestartGameButton(myProvider) ]),
Column(children: [ myProvider.animationInProgress ? decorationImage : buildRestartGameButton(myProvider) ]),
Column(children: [ decorationImage ]),
],
),
......
......@@ -27,6 +27,7 @@ class Data extends ChangeNotifier {
int _minesCount = 0;
bool _gameWin = false;
bool _gameFail = false;
bool _animationInProgress = false;
bool _reportMode = false;
int _sizeVertical = null;
int _sizeHorizontal = null;
......@@ -127,6 +128,7 @@ class Data extends ChangeNotifier {
_gameRunning = gameRunning;
updateGameWin(false);
updateGameFail(false);
updateReportMode(false);
notifyListeners();
}
......@@ -158,4 +160,26 @@ class Data extends ChangeNotifier {
_reportMode = reportMode;
notifyListeners();
}
bool get animationInProgress => _animationInProgress;
void updateAnimationInProgress(bool animationInProgress) {
_animationInProgress = animationInProgress;
notifyListeners();
}
void setAnimatedBackground(List animatedCellsPattern) {
for (var row = 0; row < _sizeVertical; row++) {
for (var col = 0; col < _sizeHorizontal; col++) {
_cells[row][col].isAnimated = animatedCellsPattern[row][col];
}
}
notifyListeners();
}
void resetAnimatedBackground() {
for (var row = 0; row < _sizeVertical; row++) {
for (var col = 0; col < _sizeHorizontal; col++) {
_cells[row][col].isAnimated = false;
}
}
}
}
import 'dart:async';
import '../entities/cell.dart';
import '../provider/data.dart';
class BoardAnimate {
static List createPatterns(Data myProvider) {
List<List> patterns = [];
int patternsCount = 16;
int sizeHorizontal = myProvider.sizeHorizontal;
int sizeVertical = myProvider.sizeVertical;
for (var patternIndex = 0; patternIndex < patternsCount; patternIndex++) {
List<List> pattern = [];
for (var row = 0; row < sizeVertical; row++) {
List<bool> patternRow = [];
for (var col = 0; col < sizeHorizontal; col++) {
patternRow.add(((patternIndex + row + col) % 4 == 0));
}
pattern.add(patternRow);
}
patterns.add(pattern);
}
return patterns;
}
static void startAnimation(Data myProvider) {
List patterns = createPatterns(myProvider);
int _patternIndex = patterns.length;
myProvider.updateAnimationInProgress(true);
Timer _timerAnimateBoard;
const interval = const Duration(milliseconds: 200);
_timerAnimateBoard = new Timer.periodic(
interval,
(Timer timer) {
if (_patternIndex == 0) {
timer.cancel();
myProvider.resetAnimatedBackground();
myProvider.updateAnimationInProgress(false);
} else {
_patternIndex--;
myProvider.setAnimatedBackground(patterns[_patternIndex]);
}
},
);
}
}
......@@ -209,7 +209,7 @@ class BoardUtils {
// Walked on a mine
if (cells[row][col].isExploded == true) {
myProvider.updateGameFail(true);
return false;
return true;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment