diff --git a/android/gradle.properties b/android/gradle.properties index 30298b3b3f04073678e48519b8c043edba635df8..6c1d873456149a8611e43a05ae56e4f50c73274f 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.18 -app.versionCode=18 +app.versionName=0.0.19 +app.versionCode=19 diff --git a/fastlane/metadata/android/en-US/changelogs/19.txt b/fastlane/metadata/android/en-US/changelogs/19.txt new file mode 100644 index 0000000000000000000000000000000000000000..a19cc98b326b6969a029f71e6e03908d50fd25cf --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/19.txt @@ -0,0 +1 @@ +Fix/clean some code, add minor improvements diff --git a/fastlane/metadata/android/fr-FR/changelogs/19.txt b/fastlane/metadata/android/fr-FR/changelogs/19.txt new file mode 100644 index 0000000000000000000000000000000000000000..4292026da5cb052a196e64b5b4e22b17df6e6cd7 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/19.txt @@ -0,0 +1 @@ +Nettoyage du code, améliorations mineures diff --git a/lib/entities/cell.dart b/lib/entities/cell.dart index a228b8a8f0ce70f024d7b504ea861adc61636ec9..394ea51f348e7e37ecd84cfe9c9e1ece33d82e03 100644 --- a/lib/entities/cell.dart +++ b/lib/entities/cell.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import '../provider/data.dart'; -import '../utils/board_utils.dart'; import '../utils/board_animate.dart'; +import '../utils/board_utils.dart'; class Cell { bool isMined = false; @@ -10,26 +10,23 @@ class Cell { bool isMarked = false; bool isExploded = false; int minesCountAround = 0; + bool isAnimated = false; Cell( @required this.isMined, ); + /* + * Build widget for board cell, with interactions + */ Container widget(Data myProvider, int row, int col) { - bool showSolution = myProvider.gameWin || myProvider.gameFail; - - Color backgroundColor = this.getBackgroundColor(myProvider); - Color borderColor = this.getBorderColor(myProvider); - String imageAsset = this.getImageAssetName(myProvider.skin, showSolution); + String imageAsset = this.getImageAssetName(myProvider); return Container( decoration: BoxDecoration( - color: backgroundColor, - border: Border.all( - color: borderColor, - width: 1, - ), + color: this.getBackgroundColor(myProvider), + border: this.getCellBorders(myProvider, row, col), ), child: GestureDetector( child: AnimatedSwitcher( @@ -44,6 +41,7 @@ class Cell { ), ), onTap: () { + // Set mines on board after first player try if (!myProvider.isBoardMined) { myProvider.updateCells(BoardUtils.createBoard(myProvider, row, col)); myProvider.updateIsBoardMined(true); @@ -61,27 +59,31 @@ class Cell { } } }, - ), + ) ); } - String getImageAssetName(String skin, bool showSolution) { - String imageAsset = 'assets/skins/' + skin + '_tile_unknown.png'; + /* + * Compute image asset name, from skin and cell value/state + */ + String getImageAssetName(Data myProvider) { + String imageAsset = 'assets/skins/' + myProvider.skin + '_tile_unknown.png'; + bool showSolution = myProvider.gameWin || myProvider.gameFail; if (!showSolution) { // Running game if (this.isExplored) { if (this.isMined) { // Boom - imageAsset = 'assets/skins/' + skin + '_tile_mine.png'; + imageAsset = 'assets/skins/' + myProvider.skin + '_tile_mine.png'; } else { // Show mines count around - imageAsset = 'assets/skins/' + skin + '_tile_' + this.minesCountAround.toString() + '.png'; + imageAsset = 'assets/skins/' + myProvider.skin + '_tile_' + this.minesCountAround.toString() + '.png'; } } else { if (this.isMarked) { // Danger! - imageAsset = 'assets/skins/' + skin + '_tile_flag.png'; + imageAsset = 'assets/skins/' + myProvider.skin + '_tile_flag.png'; } } } else { @@ -89,37 +91,57 @@ class Cell { if (this.isMined) { if (this.isExploded) { // Mine exploded - imageAsset = 'assets/skins/' + skin + '_tile_mine.png'; + imageAsset = 'assets/skins/' + myProvider.skin + '_tile_mine.png'; } else { // Mine not found - imageAsset = 'assets/skins/' + skin + '_tile_mine_not_found.png'; + imageAsset = 'assets/skins/' + myProvider.skin + '_tile_mine_not_found.png'; } } else { // Show all mines counts - imageAsset = 'assets/skins/' + skin + '_tile_' + this.minesCountAround.toString() + '.png'; + imageAsset = 'assets/skins/' + myProvider.skin + '_tile_' + this.minesCountAround.toString() + '.png'; } } return imageAsset; } + // Compute cell background color, from cell state Color getBackgroundColor(Data myProvider) { if (myProvider.gameWin) { return this.isAnimated ? Colors.green[400] : Colors.green[500]; - } else if (myProvider.gameFail) { + } + if (myProvider.gameFail) { return this.isAnimated ? Colors.pink[200] : Colors.pink[400]; } return this.isAnimated ? Colors.white : Colors.grey[200]; } - Color getBorderColor(Data myProvider) { + // Compute cell borders, from board size and cell state + Border getCellBorders(Data myProvider, int row, int col) { + Color cellBorderColor = Colors.grey[500]; + double cellBorderWidth = 4; + + // Reduce cell border width on big boards + int boardSize = myProvider.sizeHorizontal; + if (boardSize > 8) { + cellBorderWidth = 2; + if (boardSize > 10) { + cellBorderWidth = 1; + } + } + if (myProvider.gameWin) { - return Colors.green[700]; + cellBorderColor = Colors.green[700]; } else if (myProvider.gameFail) { - return Colors.pink[300]; + cellBorderColor = Colors.pink[300]; } - return Colors.grey[500]; + Border borders = Border.all( + color: cellBorderColor, + width: cellBorderWidth, + ); + + return borders; } } diff --git a/lib/layout/game.dart b/lib/layout/game.dart index a37bd50e889d91726fd39a4f41d4628c7f91a576..38e0c67aaa86bc8b3ecd12dc7ded54f273efd1c8 100644 --- a/lib/layout/game.dart +++ b/lib/layout/game.dart @@ -7,6 +7,8 @@ import '../utils/game_utils.dart'; class Game { static Container buildGameWidget(Data myProvider) { + bool gameIsFinished = myProvider.gameWin || myProvider.gameFail; + return Container( child: Column( mainAxisAlignment: MainAxisAlignment.start, @@ -14,7 +16,7 @@ class Game { children: [ Board.buildGameBoard(myProvider), SizedBox(height: 2), - (myProvider.gameWin || myProvider.gameFail) + gameIsFinished ? Game.buildEndGameMessage(myProvider) : Board.buildToggleFlagModeLayout(myProvider) ], @@ -43,7 +45,7 @@ class Game { ? 'assets/icons/game_fail.png' : '' ), - fit: BoxFit.fill, + fit: BoxFit.fill ); return Container( diff --git a/lib/layout/parameters.dart b/lib/layout/parameters.dart index c15d8a1c89663a75cbcd32e19047484eed3632c5..847290bf96fbb85e03833f45314e217a8c58489e 100644 --- a/lib/layout/parameters.dart +++ b/lib/layout/parameters.dart @@ -25,6 +25,15 @@ class Parameters { } static Container buildStartGameButton(Data myProvider) { + Column decorationImage = Column( + children: [ + Image( + image: AssetImage('assets/icons/game_win.png'), + fit: BoxFit.fill + ), + ] + ); + return Container( margin: EdgeInsets.all(2), padding: EdgeInsets.all(2), @@ -34,14 +43,7 @@ class Parameters { children: [ TableRow( children: [ - Column( - children: [ - Image( - image: AssetImage('assets/skins/empty.png'), - fit: BoxFit.fill, - ), - ] - ), + decorationImage, Column( children: [ FlatButton( @@ -55,14 +57,7 @@ class Parameters { ), ] ), - Column( - children: [ - Image( - image: AssetImage('assets/skins/empty.png'), - fit: BoxFit.fill, - ), - ] - ), + decorationImage, ], ), ] diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 2256bd2f76f0a783a9e50284413ab91904e5cf75..55e77659f9d39b1361647a8e7c144720bec9d0fe 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -22,16 +22,16 @@ class Data extends ChangeNotifier { // Game data bool _assetsPreloaded = false; - bool _gameRunning = false; - bool _isBoardMined = false; - int _minesCount = 0; - bool _gameWin = false; - bool _gameFail = false; + bool _gameIsRunning = false; bool _animationInProgress = false; - bool _reportMode = false; int _sizeVertical = null; int _sizeHorizontal = null; List _cells = []; + bool _isBoardMined = false; + int _minesCount = 0; + bool _reportMode = false; + bool _gameWin = false; + bool _gameFail = false; String get level => _level; void updateLevel(String level) { @@ -97,6 +97,27 @@ class Data extends ChangeNotifier { setParameterValue('skin', prefs.getString('skin') ?? _skinDefault); } + bool get gameIsRunning => _gameIsRunning; + void updateGameIsRunning(bool gameIsRunning) { + _gameIsRunning = gameIsRunning; + updateGameWin(false); + updateGameFail(false); + updateReportMode(false); + notifyListeners(); + } + + bool get gameWin => _gameWin; + void updateGameWin(bool gameWin) { + _gameWin = gameWin; + notifyListeners(); + } + + bool get gameFail => _gameFail; + void updateGameFail(bool gameFail) { + _gameFail = gameFail; + notifyListeners(); + } + List get cells => _cells; void updateCells(List cells) { _cells = cells; @@ -123,14 +144,6 @@ class Data extends ChangeNotifier { _assetsPreloaded = assetsPreloaded; } - bool get gameRunning => _gameRunning; - void updateGameRunning(bool gameRunning) { - _gameRunning = gameRunning; - updateGameWin(false); - updateGameFail(false); - updateReportMode(false); - notifyListeners(); - } bool get isBoardMined => _isBoardMined; void updateIsBoardMined(bool isBoardMined) { @@ -143,17 +156,6 @@ class Data extends ChangeNotifier { _minesCount = minesCount; } - bool get gameWin => _gameWin; - void updateGameWin(bool gameWin) { - _gameWin = gameWin; - notifyListeners(); - } - - bool get gameFail => _gameFail; - void updateGameFail(bool gameFail) { - _gameFail = gameFail; - notifyListeners(); - } bool get reportMode => _reportMode; void updateReportMode(bool reportMode) { diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 0b92834bdc4dd412e4502559cf088919417908bf..25e8bf694a4a30901174c47d82feda0eb9d62225 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -79,7 +79,7 @@ class _HomeState extends State<Home> { List<Widget> menuActions = []; - if (myProvider.gameRunning) { + if (myProvider.gameIsRunning) { menuActions = [ FlatButton( child: Container( @@ -107,7 +107,7 @@ class _HomeState extends State<Home> { ), body: SafeArea( child: Center( - child: myProvider.gameRunning + child: myProvider.gameIsRunning ? Game.buildGameWidget(myProvider) : Parameters.buildParametersSelector(myProvider) ), diff --git a/lib/utils/board_animate.dart b/lib/utils/board_animate.dart index 8fcecfe1a5f32ffe83e7da55133bb2400368a975..7e16e73a3f5373fc09fa815c874af43dd8b16a8f 100644 --- a/lib/utils/board_animate.dart +++ b/lib/utils/board_animate.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:math'; -import '../entities/cell.dart'; import '../provider/data.dart'; class BoardAnimate { diff --git a/lib/utils/game_utils.dart b/lib/utils/game_utils.dart index 4e87a3084d55462cdb36f8b3a3ec8a848b841b6e..b83966f4a270fc5d9b1d2f88ad04916999a1fb2a 100644 --- a/lib/utils/game_utils.dart +++ b/lib/utils/game_utils.dart @@ -5,14 +5,14 @@ import '../utils/board_utils.dart'; class GameUtils { static void resetGame(Data myProvider) { - myProvider.updateGameRunning(false); + myProvider.updateGameIsRunning(false); } 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); + myProvider.updateGameIsRunning(true); BoardUtils.createInitialEmptyBoard(myProvider); BoardAnimate.startAnimation(myProvider, 'start'); }