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

Merge branch '4-add-animations' into 'master'

Resolve "Add animations"

Closes #4

See merge request !4
parents 0793e54b 12cb90a6
No related branches found
No related tags found
1 merge request!4Resolve "Add animations"
Pipeline #5927 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.3 app.versionName=0.0.4
app.versionCode=3 app.versionCode=4
Add animations.
Ajout d'animations.
import 'dart:async';
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';
...@@ -36,6 +38,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -36,6 +38,7 @@ class GameCubit extends HydratedCubit<GameState> {
// Game data // Game data
currentPlayer: state.currentGame.currentPlayer, currentPlayer: state.currentGame.currentPlayer,
scores: state.currentGame.scores, scores: state.currentGame.scores,
currentHand: state.currentGame.currentHand,
); );
// game.dump(); // game.dump();
...@@ -79,7 +82,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -79,7 +82,7 @@ class GameCubit extends HydratedCubit<GameState> {
refresh(); refresh();
} }
void tapOnCell(int cellIndex) { void tapOnCell(int cellIndex) async {
printlog('tapOnCell: $cellIndex'); printlog('tapOnCell: $cellIndex');
if (!state.currentGame.isCurrentPlayerHouse(cellIndex)) { if (!state.currentGame.isCurrentPlayerHouse(cellIndex)) {
...@@ -103,7 +106,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -103,7 +106,7 @@ class GameCubit extends HydratedCubit<GameState> {
state.currentGame.animationInProgress = true; state.currentGame.animationInProgress = true;
refresh(); refresh();
final int lastCellIndex = animateSeedsDistribution(cellIndex); final int lastCellIndex = await animateSeedsDistribution(cellIndex);
animateSeedsEarning(lastCellIndex); animateSeedsEarning(lastCellIndex);
toggleCurrentPlayer(); toggleCurrentPlayer();
...@@ -118,21 +121,26 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -118,21 +121,26 @@ class GameCubit extends HydratedCubit<GameState> {
refresh(); refresh();
} }
int animateSeedsDistribution(int sourceCellIndex) { Future<int> animateSeedsDistribution(int sourceCellIndex) async {
printlog('animateSeedsDistribution / sourceCellIndex: $sourceCellIndex'); printlog('animateSeedsDistribution / sourceCellIndex: $sourceCellIndex');
final int seedsCount = state.currentGame.board.cells[sourceCellIndex]; final int seedsCount = state.currentGame.board.cells[sourceCellIndex];
// empty source cell // empty source cell
state.currentGame.board.cells[sourceCellIndex] = 0;
printlog('animateSeedsDistribution / empty source cell'); printlog('animateSeedsDistribution / empty source cell');
state.currentGame.board.cells[sourceCellIndex] = 0;
state.currentGame.currentHand = seedsCount;
refresh(); refresh();
await Future.delayed(const Duration(milliseconds: 500));
int cellIndex = sourceCellIndex; int cellIndex = sourceCellIndex;
for (int i = 0; i < seedsCount; i++) { for (int i = 0; i < seedsCount; i++) {
cellIndex = state.currentGame.getNextCellIndex(cellIndex, sourceCellIndex); cellIndex = state.currentGame.getNextCellIndex(cellIndex, sourceCellIndex);
state.currentGame.currentHand--;
state.currentGame.board.cells[cellIndex] += 1; state.currentGame.board.cells[cellIndex] += 1;
refresh(); refresh();
await Future.delayed(const Duration(milliseconds: 500));
} }
refresh(); refresh();
...@@ -140,7 +148,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -140,7 +148,7 @@ class GameCubit extends HydratedCubit<GameState> {
return cellIndex; return cellIndex;
} }
void animateSeedsEarning(int lastCellIndex) { void animateSeedsEarning(int lastCellIndex) async {
printlog('animateSeedsEarning / lastCellIndex: $lastCellIndex'); printlog('animateSeedsEarning / lastCellIndex: $lastCellIndex');
if (state.currentGame.isOpponentHouse(lastCellIndex)) { if (state.currentGame.isOpponentHouse(lastCellIndex)) {
...@@ -154,6 +162,8 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -154,6 +162,8 @@ class GameCubit extends HydratedCubit<GameState> {
state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount; state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount;
refresh(); refresh();
await Future.delayed(const Duration(milliseconds: 500));
// (recursively) check previous cells // (recursively) check previous cells
printlog('-> dispatch to previous cell'); printlog('-> dispatch to previous cell');
animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex)); animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex));
......
...@@ -21,6 +21,7 @@ class Game { ...@@ -21,6 +21,7 @@ class Game {
// Game data // Game data
required this.currentPlayer, required this.currentPlayer,
required this.scores, required this.scores,
required this.currentHand,
}); });
// Settings // Settings
...@@ -39,6 +40,7 @@ class Game { ...@@ -39,6 +40,7 @@ class Game {
// Game data // Game data
int currentPlayer; int currentPlayer;
List<int> scores; List<int> scores;
int currentHand;
factory Game.createNull() { factory Game.createNull() {
return Game( return Game(
...@@ -50,6 +52,7 @@ class Game { ...@@ -50,6 +52,7 @@ class Game {
// Game data // Game data
currentPlayer: 0, currentPlayer: 0,
scores: [0, 0], scores: [0, 0],
currentHand: 0,
); );
} }
...@@ -78,6 +81,7 @@ class Game { ...@@ -78,6 +81,7 @@ class Game {
// Game data // Game data
currentPlayer: 0, currentPlayer: 0,
scores: [0, 0], scores: [0, 0],
currentHand: 0,
); );
} }
......
...@@ -40,6 +40,7 @@ class GameBoardWidget extends StatelessWidget { ...@@ -40,6 +40,7 @@ class GameBoardWidget extends StatelessWidget {
children: [ children: [
GamePlayerWidget( GamePlayerWidget(
active: !currentGame.isFinished && currentGame.currentPlayer == 0, active: !currentGame.isFinished && currentGame.currentPlayer == 0,
seeds: currentGame.currentPlayer == 0 ? currentGame.currentHand : 0,
), ),
Container( Container(
margin: const EdgeInsets.all(2), margin: const EdgeInsets.all(2),
...@@ -96,6 +97,7 @@ class GameBoardWidget extends StatelessWidget { ...@@ -96,6 +97,7 @@ class GameBoardWidget extends StatelessWidget {
), ),
GamePlayerWidget( GamePlayerWidget(
active: !currentGame.isFinished && currentGame.currentPlayer == 1, active: !currentGame.isFinished && currentGame.currentPlayer == 1,
seeds: currentGame.currentPlayer == 1 ? currentGame.currentHand : 0,
), ),
], ],
); );
......
...@@ -4,9 +4,11 @@ class GamePlayerWidget extends StatelessWidget { ...@@ -4,9 +4,11 @@ class GamePlayerWidget extends StatelessWidget {
const GamePlayerWidget({ const GamePlayerWidget({
super.key, super.key,
required this.active, required this.active,
required this.seeds,
}); });
final bool active; final bool active;
final int seeds;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -25,7 +27,15 @@ class GamePlayerWidget extends StatelessWidget { ...@@ -25,7 +27,15 @@ class GamePlayerWidget extends StatelessWidget {
), ),
width: 100, width: 100,
height: 100, height: 100,
child: const SizedBox.shrink(), child: Text(
seeds == 0 ? '' : seeds.toString(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
); );
} }
} }
...@@ -3,7 +3,7 @@ description: Awale game ...@@ -3,7 +3,7 @@ description: Awale game
publish_to: "none" publish_to: "none"
version: 0.0.3+3 version: 0.0.4+4
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