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

Fix delete cells on top line

parent ed890e3a
No related branches found
No related tags found
1 merge request!20Resolve "Fix delete cells on top line"
Pipeline #4959 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.16 app.versionName=0.0.17
app.versionCode=16 app.versionCode=17
Fix delete cells on top line.
Correction sur la suppression de cellules sur la première ligne.
...@@ -30,4 +30,6 @@ class DefaultGameSettings { ...@@ -30,4 +30,6 @@ class DefaultGameSettings {
return []; return [];
} }
static int blockMinimumCellsCount = 3;
} }
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart'; import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:jeweled/config/default_game_settings.dart';
import 'package:jeweled/models/game.dart'; import 'package:jeweled/models/game.dart';
import 'package:jeweled/models/cell_location.dart'; import 'package:jeweled/models/cell_location.dart';
...@@ -109,7 +110,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -109,7 +110,7 @@ class GameCubit extends HydratedCubit<GameState> {
if (cellValue != null) { if (cellValue != null) {
List<CellLocation> blockCells = currentGame.getSiblingCells(tappedCellLocation, []); List<CellLocation> blockCells = currentGame.getSiblingCells(tappedCellLocation, []);
if (blockCells.length >= 3) { if (blockCells.length >= DefaultGameSettings.blockMinimumCellsCount) {
this.deleteBlock(blockCells); this.deleteBlock(blockCells);
this.increaseMovesCount(); this.increaseMovesCount();
this.increaseScore(getScoreFromBlock(blockCells.length)); this.increaseScore(getScoreFromBlock(blockCells.length));
......
...@@ -79,14 +79,20 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin { ...@@ -79,14 +79,20 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin {
}); });
// Build animation for each cell to move // Build animation for each cell to move
bool needAnimation = false;
cellsToRemove.forEach((cellToRemove) { cellsToRemove.forEach((cellToRemove) {
for (int i = 0; i < cellToRemove.row; i++) { for (int i = 0; i < cellToRemove.row; i++) {
final int stepsCount = stepsDownCounts[(cellToRemove.row - i) - 1][cellToRemove.col]; final int stepsCount = stepsDownCounts[(cellToRemove.row - i) - 1][cellToRemove.col];
this.animations[(cellToRemove.row - i) - 1][cellToRemove.col] = animation(stepsCount); this.animations[(cellToRemove.row - i) - 1][cellToRemove.col] = animation(stepsCount);
needAnimation = true;
} }
}); });
controller.forward().orCancel; controller.forward().orCancel;
if (!needAnimation) {
gameCubit.postAnimate();
}
} }
@override @override
...@@ -104,16 +110,16 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin { ...@@ -104,16 +110,16 @@ class _GameBoard extends State<GameBoard> with TickerProviderStateMixin {
return GestureDetector( return GestureDetector(
onTapUp: (details) { onTapUp: (details) {
bool canRemoveCell = true; bool animationInProgress = false;
animations.forEach((row) { animations.forEach((row) {
row.forEach((cell) { row.forEach((cell) {
if (cell != null) { if (cell != null) {
canRemoveCell = false; animationInProgress = true;
} }
}); });
}); });
if (canRemoveCell) { if (!animationInProgress) {
final double xTap = details.localPosition.dx; final double xTap = details.localPosition.dx;
final double yTap = details.localPosition.dy; final double yTap = details.localPosition.dy;
final int col = xTap ~/ (displayWidth / currentGame.settings.boardSize); final int col = xTap ~/ (displayWidth / currentGame.settings.boardSize);
......
...@@ -3,7 +3,7 @@ description: Jeweled Game ...@@ -3,7 +3,7 @@ description: Jeweled Game
publish_to: 'none' publish_to: 'none'
version: 0.0.16+16 version: 0.0.17+17
environment: environment:
sdk: '^3.0.0' sdk: '^3.0.0'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment