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:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user