OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Stores the actual data on a player's boat grid, the UI representation for its | 6 * Stores the actual data on a player's boat grid, the UI representation for its |
7 * grid and the status of each shot. Acts as a controller handling isolate | 7 * grid and the status of each shot. Acts as a controller handling isolate |
8 * messages (from the main isolate message and shots from the enemy), and UI | 8 * messages (from the main isolate message and shots from the enemy), and UI |
9 * events. | 9 * events. |
10 */ | 10 */ |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 }); | 176 }); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 static final LEFT_DIR = const [-1, 0]; | 180 static final LEFT_DIR = const [-1, 0]; |
181 static final RIGHT_DIR = const [1, 0]; | 181 static final RIGHT_DIR = const [1, 0]; |
182 static final UP_DIR = const [0, -1]; | 182 static final UP_DIR = const [0, -1]; |
183 static final DOWN_DIR = const [0, 1]; | 183 static final DOWN_DIR = const [0, 1]; |
184 | 184 |
185 Future<bool> _exploreAllDirections(int x, int y, bool parallel) { | 185 Future<bool> _exploreAllDirections(int x, int y, bool parallel) { |
186 Completer<bool> superShot = new Completer<bool>(); | 186 Completer<bool> superShot_ = new Completer<bool>(); |
187 if (parallel) { | 187 if (parallel) { |
188 final arr = new List<Future<bool>>(); | 188 final arr = new List<Future<bool>>(); |
189 arr.add(_exploreDirectionHelper(LEFT_DIR, x, y)); | 189 arr.add(_exploreDirectionHelper(LEFT_DIR, x, y)); |
190 arr.add(_exploreDirectionHelper(RIGHT_DIR, x, y)); | 190 arr.add(_exploreDirectionHelper(RIGHT_DIR, x, y)); |
191 arr.add(_exploreDirectionHelper(UP_DIR, x, y)); | 191 arr.add(_exploreDirectionHelper(UP_DIR, x, y)); |
192 arr.add(_exploreDirectionHelper(DOWN_DIR, x, y)); | 192 arr.add(_exploreDirectionHelper(DOWN_DIR, x, y)); |
193 Futures.wait(arr).then((arrValues) { | 193 Futures.wait(arr).then((arrValues) { |
194 superShot.complete(true); | 194 superShot_.complete(true); |
195 }); | 195 }); |
196 } else { | 196 } else { |
197 _seqExploreDirectionHelper(LEFT_DIR, x, y, superShot, | 197 _seqExploreDirectionHelper(LEFT_DIR, x, y, superShot_, |
198 _seqExploreDirectionHelper(RIGHT_DIR, x, y, superShot, | 198 _seqExploreDirectionHelper(RIGHT_DIR, x, y, superShot_, |
199 _seqExploreDirectionHelper(UP_DIR, x, y, superShot, | 199 _seqExploreDirectionHelper(UP_DIR, x, y, superShot_, |
200 _seqExploreDirectionHelper(DOWN_DIR, x, y, superShot, null))))(fal
se); | 200 _seqExploreDirectionHelper(DOWN_DIR, x, y, superShot_, null))))(fa
lse); |
201 } | 201 } |
202 return superShot.future; | 202 return superShot_.future; |
203 } | 203 } |
204 Function _seqExploreDirectionHelper(List<int> dir, int x, int y, | 204 Function _seqExploreDirectionHelper(List<int> dir, int x, int y, |
205 Completer<bool> seq, void _next(bool res)) { | 205 Completer<bool> seq, void _next(bool res)) { |
206 return (bool res) { | 206 return (bool res) { |
207 if (res) { | 207 if (res) { |
208 seq.complete(true); | 208 seq.complete(true); |
209 } else { | 209 } else { |
210 _exploreDirectionHelper(dir, x, y).then( | 210 _exploreDirectionHelper(dir, x, y).then( |
211 (_next != null) ? _next : (void _(v) {seq.complete(false);})); | 211 (_next != null) ? _next : (void _(v) {seq.complete(false);})); |
212 } | 212 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 case Constants.SUNK: | 298 case Constants.SUNK: |
299 totalHits++; | 299 totalHits++; |
300 boatsSunk++; | 300 boatsSunk++; |
301 _enemyView.addHit(x, y); | 301 _enemyView.addHit(x, y); |
302 enemyGrid.hit(x, y); | 302 enemyGrid.hit(x, y); |
303 break; | 303 break; |
304 } | 304 } |
305 _enemyView.statusBar.updateStatus(); | 305 _enemyView.statusBar.updateStatus(); |
306 } | 306 } |
307 } | 307 } |
OLD | NEW |