Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: client/samples/dartcombat/player.dart

Issue 9303020: Move all samples but swarm from client/samples/ to samples/ . (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/samples/dartcombat/player.dart
===================================================================
--- client/samples/dartcombat/player.dart (revision 3705)
+++ client/samples/dartcombat/player.dart (working copy)
@@ -1,115 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-/** A local player (API known to the main isolate when creating players). */
-interface Player default PlayerImpl {
-
- Player();
-
- final Future<SendPort> portToPlayer;
-
- void setup(Window window, int player);
-
- void set enemy(SendPort portToEnemy);
-
- void set _portForTest(SendPort testPort);
-}
-
-/** A remote enemy (API visible to a player to communicate with the enemy). */
-interface Enemy default EnemyImpl {
- Enemy(SendPort port);
-
- /** tell the enemy that we are ready, receive confirmation asynchronously. */
- Future<int> ready();
-
- /** shoot asynchronously. */
- Future<int> shoot(int x, int y);
-}
-
-
-/**
- * A default implementation for player that sends messages to an isolate, which
- * contains the actual player state.
- */
-class PlayerImpl implements Player {
- final Future<SendPort> portToPlayer;
-
- PlayerImpl() : portToPlayer = new PlayerState().spawn();
-
- void setup(Window window, int player) {
- portToPlayer.then((SendPort port) => port.call(
- { "action" : MessageIds.SETUP,
- "args" : [player] }));
- }
-
- void set enemy(SendPort portToEnemy) {
- portToPlayer.then((port) => port.call(
- { "action" : MessageIds.SET_ENEMY,
- "args" : [portToEnemy]}));
- }
-
- void set _portForTest(SendPort testPort) {
- portToPlayer.then((port) => port.call(
- { "action" : MessageIds.SET_PORT_FOR_TEST,
- "args" : [testPort]}));
- }
-}
-
-/**
- * A default implementation for an enemy that sends messages to an isolate,
- * which contains the actual enemy state.
- */
-class EnemyImpl implements Enemy {
- SendPort portToEnemy;
-
- EnemyImpl(this.portToEnemy) {}
-
- Future<int> ready() {
- Completer<int> res = new Completer<int>();
- ReceivePort port = portToEnemy.call(
- { "action" : MessageIds.ENEMY_IS_READY });
- port.receive((var message, SendPort replyTo) {
- bool success = message[0];
- if (success) {
- res.complete(0);
- } else {
- res.completeException(message[1]);
- }
- });
- return res.future;
- }
-
- Future<int> shoot(int x, int y) {
- Completer<int> res = new Completer<int>();
- ReceivePort port = portToEnemy.call(
- { "action" : MessageIds.SHOOT, "args" : [x, y] });
- port.receive((var message, SendPort replyTo) {
- bool success = message[0];
- if (success) {
- res.complete(message[1][0]);
- } else {
- res.completeException(message[1]);
- }
- });
- return res.future;
- }
-}
-
-/** Collection of message IDs used to communicate with player isolates. */
-class MessageIds {
- /** message to set up a new player. */
- static final SETUP = 1;
-
- /** message to initialize the enemy of a player. */
- static final SET_ENEMY = 2;
-
- /** message indicating that the enemy is ready to play. */
- static final ENEMY_IS_READY = 3;
-
- /** message describing a shoot action. */
- static final SHOOT = 4;
-
- /** message to set up a test port, used to make tests non-flaky. */
- static final SET_PORT_FOR_TEST = 5;
-}

Powered by Google App Engine
This is Rietveld 408576698