OLD | NEW |
1 part of pop_pop_win.html; | 1 library pop_pop_win.game_manager; |
2 | 2 |
| 3 import 'dart:async'; |
| 4 |
| 5 import 'game_storage.dart'; |
| 6 import 'game.dart'; |
| 7 |
3 abstract class GameManager { | 8 abstract class GameManager { |
4 final int _width, _height, _bombCount; | 9 final int _width, _height, _bombCount; |
5 final GameStorage _gameStorage = new GameStorage(); | 10 final GameStorage _gameStorage = new GameStorage(); |
6 | 11 |
7 Game _game; | 12 Game _game; |
8 StreamSubscription _updatedEventId; | 13 StreamSubscription _updatedEventId; |
9 StreamSubscription _gameStateChangedId; | 14 StreamSubscription _gameStateChangedId; |
10 Timer _clockTimer; | 15 Timer _clockTimer; |
11 | 16 |
12 GameManager(this._width, this._height, this._bombCount) { | 17 GameManager(this._width, this._height, this._bombCount) { |
13 newGame(); | 18 newGame(); |
14 } | 19 } |
15 | 20 |
16 Game get game => _game; | 21 Game get game => _game; |
17 | 22 |
18 Stream<EventArgs> get bestTimeUpdated => _gameStorage.bestTimeUpdated; | 23 Stream get bestTimeUpdated => _gameStorage.bestTimeUpdated; |
19 | 24 |
20 Future<int> get bestTimeMilliseconds => | 25 Future<int> get bestTimeMilliseconds => |
21 _gameStorage.getBestTimeMilliseconds(_width, _height, _bombCount); | 26 _gameStorage.getBestTimeMilliseconds(_width, _height, _bombCount); |
22 | 27 |
23 void newGame() { | 28 void newGame() { |
24 if (_updatedEventId != null) { | 29 if (_updatedEventId != null) { |
25 assert(_game != null); | 30 assert(_game != null); |
26 assert(_gameStateChangedId != null); | 31 assert(_gameStateChangedId != null); |
27 _updatedEventId.cancel(); | 32 _updatedEventId.cancel(); |
28 _gameStateChangedId.cancel(); | 33 _gameStateChangedId.cancel(); |
29 _gameStateChanged(GameState.reset); | 34 _gameStateChanged(GameState.reset); |
30 } | 35 } |
31 final f = new Field(_bombCount, _width, _height); | 36 final f = new Field(_bombCount, _width, _height); |
32 _game = new Game(f); | 37 _game = new Game(f); |
33 _updatedEventId = _game.updated.listen(gameUpdated); | 38 _updatedEventId = _game.updated.listen((_) => gameUpdated()); |
34 _gameStateChangedId = _game.stateChanged.listen(_gameStateChanged); | 39 _gameStateChangedId = _game.stateChanged.listen(_gameStateChanged); |
35 } | 40 } |
36 | 41 |
37 void gameUpdated(args); | 42 void gameUpdated() {} |
38 | 43 |
39 void resetScores() { | 44 void resetScores() { |
40 _gameStorage.reset(); | 45 _gameStorage.reset(); |
41 } | 46 } |
42 | 47 |
43 void _click(int x, int y, bool alt) { | 48 void _click(int x, int y, bool alt) { |
44 final ss = _game.getSquareState(x, y); | 49 final ss = _game.getSquareState(x, y); |
45 | 50 |
46 if (alt) { | 51 if (alt) { |
47 if (ss == SquareState.hidden) { | 52 if (ss == SquareState.hidden) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 bestTimeMilliseconds.then((int val) { | 88 bestTimeMilliseconds.then((int val) { |
84 onNewBestTime(val); | 89 onNewBestTime(val); |
85 }); | 90 }); |
86 } | 91 } |
87 }); | 92 }); |
88 } | 93 } |
89 updateClock(); | 94 updateClock(); |
90 onGameStateChanged(newState); | 95 onGameStateChanged(newState); |
91 } | 96 } |
92 } | 97 } |
OLD | NEW |