Beispiel #1
0
        Tuple <int, GameInfo> IGameSync.Join(long userId, string userName, IGameObserver observer, IGameUserObserver observerForUserActor)
        {
            if (_state != GameState.WaitingForPlayers)
            {
                throw new ResultException(ResultCodeType.GameStarted);
            }

            if (_players.Count > 2)
            {
                throw new ResultException(ResultCodeType.GamePlayerFull);
            }

            var playerId = _players.Count + 1;

            NotifyToAllObservers((id, o) => o.Join(playerId, userId, userName));

            _players.Add(new Player
            {
                UserId               = userId,
                UserName             = userName,
                Observer             = (GameObserver)observer,
                ObserverForUserActor = (GameUserObserver)observerForUserActor,
            });

            if (_players.Count == 2)
            {
                RunTask(() => BeginGame());
            }

            return(Tuple.Create(playerId, GetGameInfo()));
        }
Beispiel #2
0
        Tuple<int, GameInfo> IGameSync.Join(long userId, string userName, IGameObserver observer, IGameUserObserver observerForUserActor)
        {
            if (_state != GameState.WaitingForPlayers)
                throw new ResultException(ResultCodeType.GameStarted);

            if (_players.Count > 2)
                throw new ResultException(ResultCodeType.GamePlayerFull);

            var playerId = _players.Count + 1;
            NotifyToAllObservers((id, o) => o.Join(playerId, userId, userName));

            _players.Add(new Player
            {
                UserId = userId,
                UserName = userName,
                Observer = (GameObserver)observer,
                ObserverForUserActor = (GameUserObserver)observerForUserActor,
            });

            if (_players.Count == 2)
                RunTask(() => BeginGame());

            return Tuple.Create(playerId, GetGameInfo());
        }
 public static SurrogateForIGameUserObserver Convert(IGameUserObserver value)
 {
     if (value == null) return null;
     var o = (GameUserObserver)value;
     return new SurrogateForIGameUserObserver { Channel = o.Channel, ObserverId = o.ObserverId };
 }