mirror of
https://github.com/flutter/samples.git
synced 2026-04-23 23:42:57 +00:00
More state cleanup
This commit is contained in:
@@ -7,32 +7,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();
|
||||
@@ -61,13 +36,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;
|
||||
@@ -97,7 +69,7 @@ class PuzzleAnimator implements PuzzleProxy {
|
||||
_puzzle = _puzzle.clickRandom(vertical: _nextRandomVertical);
|
||||
_nextRandomVertical = !_nextRandomVertical;
|
||||
_clickCount++;
|
||||
_controller.add(PuzzleEvent.click);
|
||||
_controller.add(PuzzleEvent.random);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
25
web/slide_puzzle/lib/src/core/puzzle_proxy.dart
Normal file
25
web/slide_puzzle/lib/src/core/puzzle_proxy.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' show Point;
|
||||
|
||||
enum PuzzleEvent { click, random, reset, noop }
|
||||
|
||||
abstract class PuzzleProxy {
|
||||
int get width;
|
||||
|
||||
int get height;
|
||||
|
||||
int get length;
|
||||
|
||||
bool get solved;
|
||||
|
||||
void clickOrShake(int tileValue);
|
||||
|
||||
int get tileCount;
|
||||
|
||||
Point<double> location(int index);
|
||||
|
||||
bool isCorrectPosition(int value);
|
||||
}
|
||||
Reference in New Issue
Block a user