Пример #1
0
    void Start()
    {
        // Initialize the Actor
        base.Start(this.name);
        uiManager = getActorRef(UIManagerPath, system);
        UnityEngine.Debug.Log("PingPong Starting ....");

        // Create the ping and the pong actor
        var ponger = system.ActorOf(PingPongActor.Props(new Messages.Ping(), new Messages.Pong(), UIManagerPath), "ponger");
        var pinger = system.ActorOf(PingPongActor.Props(new Messages.Pong(), new Messages.Ping(), UIManagerPath), "pinger");

        // Create a scheduler to make sure we can send messages to this MonoBehavior
        system.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(2), internalActor,
                                                "2 sec Scheduler triggered", internalActor);

        // Start the game ....
        pinger.Tell(new Messages.Pong(), ponger);
    }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                var rng = new Random();

                var hello = new HelloWorldActor();
                hello.Start();
                hello.Post("Hello World!");

                Ask();

                var hello2 = new ReactHelloWorldActor();
                hello2.Start();
                hello2.Post("Hello World!");

                Ask();

                var loop = new SimpleLoopActor();
                loop.Start();
                loop.Post(rng.Next(42));

                Ask();

                var ping = new SimplePingPong();
                var pong = new SimplePingPong();
                ping.Start();
                pong.Start();
                ping.Post(PingPongMessage.Ping, pong);

                Ask();

                PingPongActor[] pp = new PingPongActor[2];
                pp[0] = new ReceivePingPongActor(rng.Next(3, 10));
                pp[1] = new ReactPingPongActor(rng.Next(3, 10));
                pp[0].Start();
                pp[1].Start();
                int idx = rng.Next(2);
                pp[idx].Post(PingPongMessage.Ping, pp[1 - idx]);

                Ask();

                pp[0] = new ReceivePingPongActor(rng.Next(3, 10));
                pp[1] = new YReactPingPongActor(rng.Next(3, 10));
                pp[0].Start();
                pp[1].Start();
                idx = rng.Next(2);
                pp[idx].Post(PingPongMessage.Ping, pp[1 - idx]);

                Ask();

                var player1 = new RPSPlayer("Player 1");
                player1.Start();
                var player2 = new RPSPlayer("Player 2");
                player2.Start();
                var referee = new RPSCoordinator();
                referee.Start();

                player1.Post(new RPSMessage() { Order = RPSMessage.RPS.Go }, referee);
                player2.Post(new RPSMessage() { Order = RPSMessage.RPS.Go }, referee);

                System.Threading.Thread.Sleep(7456);
                player1.Post(new RPSMessage() { Order = RPSMessage.RPS.End });
                player2.Post(new RPSMessage() { Order = RPSMessage.RPS.End });
                referee.Post(new RPSMessage() { Order = RPSMessage.RPS.End });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Press [ENTER] to quit");
            Console.ReadLine();
        }