예제 #1
0
        public CompetitorLobby(
            ISelectableSet <IActorRef> competitors
            , ICompetitionInfo lobbyConfiguration)
        {
            Receive <RequestLobbyJoin>(obj =>
            {
                if (competitors.Contains(Sender))
                {
                    return;
                }

                competitors.Add(Sender);

                Context.WatchWith(
                    Sender
                    , new CompetitorTerminated(Sender));
            });

            Receive <RequestLobbyQuit>(obj =>
            {
                Context.Unwatch(Sender);
                competitors.Remove(Sender);
            });

            Receive <OrderCompetitorsSelection>(msg =>
            {
                try
                {
                    Sender.Tell(competitors.Select(lobbyConfiguration.PlayerCount).ToList());
                }
                catch (NotEnoughPlayersException e)
                {
                    Sender.Tell(NotEnoughPlayers.Instance);
                }
            });

            Receive <OrderAgents>(obj =>
            {
                var orderProps = LobbyOrder.Props(Sender, Self);
                Context.ActorOf(orderProps);
            });

            Receive <CompetitorTerminated>(obj => { competitors.Remove(obj.ActorRef); });
        }
예제 #2
0
 public static Props Props(ISelectableSet <IActorRef> playerSet, ICompetitionInfo lobbyConfiguration)
 {
     return(Akka.Actor.Props.Create(() => new CompetitorLobby(playerSet, lobbyConfiguration)));
 }