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

Add animations.

parent 0793e54b
No related branches found
No related tags found
1 merge request!4Resolve "Add animations"
Pipeline #5924 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.3
app.versionCode=3
app.versionName=0.0.4
app.versionCode=4
Add animations.
Ajout d'animations.
import 'dart:async';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
......@@ -36,6 +38,7 @@ class GameCubit extends HydratedCubit<GameState> {
// Game data
currentPlayer: state.currentGame.currentPlayer,
scores: state.currentGame.scores,
currentHand: state.currentGame.currentHand,
);
// game.dump();
......@@ -79,7 +82,7 @@ class GameCubit extends HydratedCubit<GameState> {
refresh();
}
void tapOnCell(int cellIndex) {
void tapOnCell(int cellIndex) async {
printlog('tapOnCell: $cellIndex');
if (!state.currentGame.isCurrentPlayerHouse(cellIndex)) {
......@@ -103,7 +106,7 @@ class GameCubit extends HydratedCubit<GameState> {
state.currentGame.animationInProgress = true;
refresh();
final int lastCellIndex = animateSeedsDistribution(cellIndex);
final int lastCellIndex = await animateSeedsDistribution(cellIndex);
animateSeedsEarning(lastCellIndex);
toggleCurrentPlayer();
......@@ -118,21 +121,26 @@ class GameCubit extends HydratedCubit<GameState> {
refresh();
}
int animateSeedsDistribution(int sourceCellIndex) {
Future<int> animateSeedsDistribution(int sourceCellIndex) async {
printlog('animateSeedsDistribution / sourceCellIndex: $sourceCellIndex');
final int seedsCount = state.currentGame.board.cells[sourceCellIndex];
// empty source cell
state.currentGame.board.cells[sourceCellIndex] = 0;
printlog('animateSeedsDistribution / empty source cell');
state.currentGame.board.cells[sourceCellIndex] = 0;
state.currentGame.currentHand = seedsCount;
refresh();
await Future.delayed(const Duration(milliseconds: 500));
int cellIndex = sourceCellIndex;
for (int i = 0; i < seedsCount; i++) {
cellIndex = state.currentGame.getNextCellIndex(cellIndex, sourceCellIndex);
state.currentGame.currentHand--;
state.currentGame.board.cells[cellIndex] += 1;
refresh();
await Future.delayed(const Duration(milliseconds: 500));
}
refresh();
......@@ -140,7 +148,7 @@ class GameCubit extends HydratedCubit<GameState> {
return cellIndex;
}
void animateSeedsEarning(int lastCellIndex) {
void animateSeedsEarning(int lastCellIndex) async {
printlog('animateSeedsEarning / lastCellIndex: $lastCellIndex');
if (state.currentGame.isOpponentHouse(lastCellIndex)) {
......@@ -154,6 +162,8 @@ class GameCubit extends HydratedCubit<GameState> {
state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount;
refresh();
await Future.delayed(const Duration(milliseconds: 500));
// (recursively) check previous cells
printlog('-> dispatch to previous cell');
animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex));
......
......@@ -21,6 +21,7 @@ class Game {
// Game data
required this.currentPlayer,
required this.scores,
required this.currentHand,
});
// Settings
......@@ -39,6 +40,7 @@ class Game {
// Game data
int currentPlayer;
List<int> scores;
int currentHand;
factory Game.createNull() {
return Game(
......@@ -50,6 +52,7 @@ class Game {
// Game data
currentPlayer: 0,
scores: [0, 0],
currentHand: 0,
);
}
......@@ -78,6 +81,7 @@ class Game {
// Game data
currentPlayer: 0,
scores: [0, 0],
currentHand: 0,
);
}
......
......@@ -40,6 +40,7 @@ class GameBoardWidget extends StatelessWidget {
children: [
GamePlayerWidget(
active: !currentGame.isFinished && currentGame.currentPlayer == 0,
seeds: currentGame.currentPlayer == 0 ? currentGame.currentHand : 0,
),
Container(
margin: const EdgeInsets.all(2),
......@@ -96,6 +97,7 @@ class GameBoardWidget extends StatelessWidget {
),
GamePlayerWidget(
active: !currentGame.isFinished && currentGame.currentPlayer == 1,
seeds: currentGame.currentPlayer == 1 ? currentGame.currentHand : 0,
),
],
);
......
......@@ -4,9 +4,11 @@ class GamePlayerWidget extends StatelessWidget {
const GamePlayerWidget({
super.key,
required this.active,
required this.seeds,
});
final bool active;
final int seeds;
@override
Widget build(BuildContext context) {
......@@ -25,7 +27,15 @@ class GamePlayerWidget extends StatelessWidget {
),
width: 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
publish_to: "none"
version: 0.0.3+3
version: 0.0.4+4
environment:
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