| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** Entrypoint to set up the dartcombat sample. */ | 5 /** Entrypoint to set up the dartcombat sample. */ |
| 6 void setUpGame() { | 6 void setUpGame() { |
| 7 setupUI(); | 7 setupUI(); |
| 8 createPlayers(); | 8 createPlayers(); |
| 9 } | 9 } |
| 10 | 10 |
| 11 /** Sets up the UI creating the board for each player. */ | 11 /** Sets up the UI creating the board for each player. */ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 /** Create and connect players. */ | 35 /** Create and connect players. */ |
| 36 void createPlayers() { | 36 void createPlayers() { |
| 37 Player player1 = new Player(); | 37 Player player1 = new Player(); |
| 38 player1.setup(window, 1); | 38 player1.setup(window, 1); |
| 39 | 39 |
| 40 Player player2 = new Player(); | 40 Player player2 = new Player(); |
| 41 player2.setup(window, 2); | 41 player2.setup(window, 2); |
| 42 | 42 |
| 43 player2.portToPlayer.then((SendPort port) { | 43 player1.enemy = new FlakyProxy(player2.portToPlayer).sendPort; |
| 44 player1.enemy = new FlakyProxy(port).sendPort; | |
| 45 }); | |
| 46 | 44 |
| 47 player1.portToPlayer.then((SendPort port) { | 45 player2.enemy = new FlakyProxy(player1.portToPlayer).sendPort; |
| 48 player2.enemy = new FlakyProxy(port).sendPort; | |
| 49 }); | |
| 50 } | 46 } |
| 51 | 47 |
| 52 /** | 48 /** |
| 53 * Create and connect players, providing a port for communicating progress to | 49 * Create and connect players, providing a port for communicating progress to |
| 54 * the test. | 50 * the test. |
| 55 */ | 51 */ |
| 56 void createPlayersForTest(SendPort testPort) { | 52 void createPlayersForTest(SendPort testPort) { |
| 57 Player player1 = new Player(); | 53 Player player1 = new Player(); |
| 58 Player player2 = new Player(); | 54 Player player2 = new Player(); |
| 59 | 55 |
| 60 player1._portForTest = testPort; | 56 player1._portForTest = testPort; |
| 61 player2._portForTest = testPort; | 57 player2._portForTest = testPort; |
| 62 | 58 |
| 63 player1.setup(window, 1); | 59 player1.setup(window, 1); |
| 64 player2.setup(window, 2); | 60 player2.setup(window, 2); |
| 65 | 61 |
| 66 player2.portToPlayer.then((SendPort port) { player1.enemy = port; }); | 62 player1.enemy = player2.portToPlayer; |
| 67 player1.portToPlayer.then((SendPort port) { player2.enemy = port; }); | 63 player2.enemy = player1.portToPlayer; |
| 68 } | 64 } |
| 69 | 65 |
| 70 /** | 66 /** |
| 71 * A proxy between ports that randomly drops messages to simulate isolates | 67 * A proxy between ports that randomly drops messages to simulate isolates |
| 72 * across the network. | 68 * across the network. |
| 73 */ | 69 */ |
| 74 class FlakyProxy { | 70 class FlakyProxy { |
| 75 ReceivePort proxy; | 71 ReceivePort proxy; |
| 76 | 72 |
| 77 SendPort _target; | 73 SendPort _target; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 89 _target.send(message, reply); | 85 _target.send(message, reply); |
| 90 } | 86 } |
| 91 }, 200); | 87 }, 200); |
| 92 }); | 88 }); |
| 93 } | 89 } |
| 94 | 90 |
| 95 // TODO(sigmund): introduce UI to control flakiness, then do: | 91 // TODO(sigmund): introduce UI to control flakiness, then do: |
| 96 // => Math.random() > 0.9; | 92 // => Math.random() > 0.9; |
| 97 bool randomlyFail() => false; | 93 bool randomlyFail() => false; |
| 98 } | 94 } |
| OLD | NEW |