1
0
mirror of https://github.com/flutter/samples.git synced 2026-04-25 17:06:44 +00:00

update slide_puzzle for beta channel (#419)

includes PR: https://github.com/kevmoo/slide_puzzle/pull/5
This commit is contained in:
John Ryan
2020-04-23 09:33:43 -07:00
committed by GitHub
parent ed284c78bd
commit ef0114c210
17 changed files with 421 additions and 513 deletions

View File

@@ -123,8 +123,7 @@ abstract class Puzzle {
value += delta * delta;
}
}
value *= incorrectTiles;
return value;
return value * incorrectTiles;
}
Puzzle clickRandom({bool vertical}) {
@@ -137,8 +136,8 @@ abstract class Puzzle {
List<int> clickableValues({bool vertical}) {
final open = openPosition();
final doRow = (vertical == null || vertical == false);
final doColumn = (vertical == null || vertical);
final doRow = vertical == null || vertical == false;
final doColumn = vertical == null || vertical;
final values =
Uint8List((doRow ? (width - 1) : 0) + (doColumn ? (height - 1) : 0));

View File

@@ -3,32 +3,7 @@ import 'dart:math' show Point, Random;
import 'body.dart';
import 'puzzle.dart';
enum PuzzleEvent { click, reset, noop }
abstract class PuzzleProxy {
int get width;
int get height;
int get length;
bool get solved;
void reset();
void clickOrShake(int tileValue);
int get tileCount;
int get clickCount;
int get incorrectTiles;
Point<double> location(int index);
bool isCorrectPosition(int value);
}
import 'puzzle_proxy.dart';
class PuzzleAnimator implements PuzzleProxy {
final _rnd = Random();
@@ -57,13 +32,10 @@ class PuzzleAnimator implements PuzzleProxy {
@override
int get tileCount => _puzzle.tileCount;
@override
int get incorrectTiles => _puzzle.incorrectTiles;
@override
int get clickCount => _clickCount;
@override
void reset() => _resetCore();
Stream<PuzzleEvent> get onEvent => _controller.stream;
@@ -93,7 +65,7 @@ class PuzzleAnimator implements PuzzleProxy {
_puzzle = _puzzle.clickRandom(vertical: _nextRandomVertical);
_nextRandomVertical = !_nextRandomVertical;
_clickCount++;
_controller.add(PuzzleEvent.click);
_controller.add(PuzzleEvent.random);
}
@override
@@ -165,7 +137,7 @@ class PuzzleAnimator implements PuzzleProxy {
final delta = _puzzle.openPosition() - _puzzle.coordinatesOf(tileValue);
deltaDouble = Point(delta.x.toDouble(), delta.y.toDouble());
}
deltaDouble *= (0.5 / deltaDouble.magnitude);
deltaDouble *= 0.5 / deltaDouble.magnitude;
_locations[tileValue].kick(deltaDouble);
}