| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import 'package:gobang/flyweight/position.dart';
- import 'package:gobang/memorandum/care_taker.dart';
- import 'package:gobang/memorandum/memo.dart';
- class Checkerboard {
- Checkerboard._();
- static final Checkerboard instance = Checkerboard._();
- static Checkerboard getInstance() => instance;
- List<Position> _state = [];
- List<Position> get state => _state;
- final CareTaker _careTaker = CareTaker();
- void add(Position position) {
- _state.add(position);
- _careTaker.add(_save());
- }
- void _from(Memo memo) {
- _state = List.of(memo.state);
- }
- Memo _save() => Memo(_state);
- void clean() {
- _state = [];
- _careTaker.clear();
- }
- void undo() {
- final memo = _careTaker.getLast();
- _from(memo);
- }
- }
|