diff --git a/android/gradle.properties b/android/gradle.properties index 6bf54a6ed821c19f76d860d4a24e7c85d440b575..f0be9fb67d6fe0b36ce90df03ff2f3f1551d738c 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ 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 diff --git a/fastlane/metadata/android/en-US/changelogs/11.txt b/fastlane/metadata/android/en-US/changelogs/11.txt new file mode 100644 index 0000000000000000000000000000000000000000..e95f8222c7d3cd7dbc30356ab9f3cf7b82edd7b1 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/11.txt @@ -0,0 +1 @@ +Add animation on game end diff --git a/fastlane/metadata/android/fr-FR/changelogs/11.txt b/fastlane/metadata/android/fr-FR/changelogs/11.txt new file mode 100644 index 0000000000000000000000000000000000000000..6a3b13ca2153899cbac4411d24b134b8f4299947 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/11.txt @@ -0,0 +1 @@ +Ajout d'animation en fin de partie diff --git a/lib/entities/cell.dart b/lib/entities/cell.dart index 8a0984d17e68f5f5d589eff97bdc8af14b06cd91..106091c2777045ccd943e9ff8567253c0a395fc9 100644 --- a/lib/entities/cell.dart +++ b/lib/entities/cell.dart @@ -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]; } } diff --git a/lib/layout/game.dart b/lib/layout/game.dart index 5b226c80aa6378a47e5e0ef8802940d94ad2b1dc..a3cca39cb6df4c2c809d2bc66a30e594007e17f4 100644 --- a/lib/layout/game.dart +++ b/lib/layout/game.dart @@ -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 ]), ], ), diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 9316efb25b41a09b214d0d71f601c496a88dc138..2256bd2f76f0a783a9e50284413ab91904e5cf75 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -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; + } + } + } } diff --git a/lib/utils/board_animate.dart b/lib/utils/board_animate.dart new file mode 100644 index 0000000000000000000000000000000000000000..d4aae4616d61e740f023a6f4fb9a2b65f49e96e5 --- /dev/null +++ b/lib/utils/board_animate.dart @@ -0,0 +1,52 @@ +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]); + } + }, + ); + } +} diff --git a/lib/utils/board_utils.dart b/lib/utils/board_utils.dart index e7e7bb3f7b3d88809b3ae3974246924fa5459e2e..f4bf5b8b323c7a0db3512463b3ea4e3176b3f0a9 100644 --- a/lib/utils/board_utils.dart +++ b/lib/utils/board_utils.dart @@ -209,7 +209,7 @@ class BoardUtils { // Walked on a mine if (cells[row][col].isExploded == true) { myProvider.updateGameFail(true); - return false; + return true; } } }