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

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

Resolve "Add animations"

Closes #13

See merge request !16
parents 26a2a3f9 5545c7f4
No related branches found
No related tags found
1 merge request!16Resolve "Add animations"
Pipeline #4819 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.14 app.versionName=0.0.15
app.versionCode=14 app.versionCode=15
Animate while picking next move.
Animation pendant la sélection du prochain mouvement.
import 'dart:async';
import 'dart:math';
import 'package:audioplayers/audioplayers.dart'; import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
...@@ -15,14 +18,43 @@ class Game extends StatefulWidget { ...@@ -15,14 +18,43 @@ class Game extends StatefulWidget {
class _GameState extends State<Game> { class _GameState extends State<Game> {
final player = AudioPlayer(); final player = AudioPlayer();
bool shuffling = false;
Move? shuffledMove;
@override void animate() {
Widget build(BuildContext context) { const interval = const Duration(milliseconds: 200);
return BlocBuilder<GameCubit, GameState>( int iterationsLeft = 10;
builder: (BuildContext context, GameState gameState) {
return GestureDetector( shuffling = true;
child: ShowMove(move: gameState.move ?? Move.createNull()), shuffledMove = null;
onTap: () {
setState(() {});
Timer.periodic(
interval,
(Timer timer) {
if (iterationsLeft > 1) {
shuffledMove = Move.pickRandom();
}
if (iterationsLeft == 1) {
shuffledMove = null;
}
if (iterationsLeft == 0) {
shuffledMove = null;
pickNewMove();
timer.cancel();
shuffling = false;
}
setState(() {});
iterationsLeft--;
},
);
}
void pickNewMove() {
Move newMove = Move.pickRandom(); Move newMove = Move.pickRandom();
BlocProvider.of<GameCubit>(context).setValues( BlocProvider.of<GameCubit>(context).setValues(
...@@ -30,6 +62,21 @@ class _GameState extends State<Game> { ...@@ -30,6 +62,21 @@ class _GameState extends State<Game> {
); );
player.play(AssetSource(newMove.toSoundAsset())); player.play(AssetSource(newMove.toSoundAsset()));
}
@override
Widget build(BuildContext context) {
return BlocBuilder<GameCubit, GameState>(
builder: (BuildContext context, GameState gameState) {
return GestureDetector(
child: shuffling
? Transform.rotate(
angle: 2 * pi * Random().nextDouble(),
child: ShowMove(move: shuffledMove ?? Move.createNull()),
)
: ShowMove(move: gameState.move ?? Move.createNull()),
onTap: () {
animate();
}, },
); );
}, },
......
...@@ -3,7 +3,7 @@ description: twister game companion ...@@ -3,7 +3,7 @@ description: twister game companion
publish_to: 'none' publish_to: 'none'
version: 0.0.14+14 version: 0.0.15+15
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