示例#1
0
        /// <summary>
        /// News the game.
        /// </summary>
        /// <param name="playerAId">The player a identifier.</param>
        /// <param name="playerBId">The player b identifier.</param>
        /// <returns>The GameDetails object</returns>
        internal GameDetails NewGame(string playerAId, string playerBId)
        {
            // Gets the playerA user credential.
            var playerA = _connections.Values.FirstOrDefault <UserCredential>
                              (c => c.Sessions.FirstOrDefault <ConnectionSession>
                                  (s => s.ConnectionId == playerAId) != null);

            // Gets the playerB user credential.
            var playerB = _connections.Values.FirstOrDefault <UserCredential>
                              (c => c.Sessions.FirstOrDefault <ConnectionSession>
                                  (s => s.ConnectionId == playerBId) != null);

            // When the game started, created a game instance.
            var newGame = new GameDetails
            {
                GameId   = Guid.NewGuid(),
                User1Id  = playerA,
                User2Id  = playerB,
                NextTurn = playerA.UserId
            };

            // Stores the game instance into cache.
            _games[newGame.GameId] = newGame;
            return(newGame);
        }
示例#2
0
 /// <summary>
 /// When the challenge started, create a game instance.
 /// </summary>
 /// <param name="gameId">The game identifier.</param>
 /// <returns>a game instance</returns>
 public GameDetails Game(Guid gameId)
 {
     if (!_games.ContainsKey(gameId))
     {
         _games[gameId] = new GameDetails { GameId = gameId };
     }
     return _games[gameId];
 }
示例#3
0
 /// <summary>
 /// When the challenge started, create a game instance.
 /// </summary>
 /// <param name="gameId">The game identifier.</param>
 /// <returns>a game instance</returns>
 public GameDetails Game(Guid gameId)
 {
     if (!_games.ContainsKey(gameId))
     {
         _games[gameId] = new GameDetails {
             GameId = gameId
         };
     }
     return(_games[gameId]);
 }
示例#4
0
        /// <summary>
        /// News the game.
        /// </summary>
        /// <param name="playerAId">The player a identifier.</param>
        /// <param name="playerBId">The player b identifier.</param>
        /// <returns>The GameDetails object</returns>
        internal GameDetails NewGame(string playerAId, string playerBId)
        {
            // Gets the playerA user credential.
            var playerA = _connections.Values.FirstOrDefault<UserCredential>
                (c => c.Sessions.FirstOrDefault<ConnectionSession>
                    (s => s.ConnectionId == playerAId) != null);

            // Gets the playerB user credential.
            var playerB = _connections.Values.FirstOrDefault<UserCredential>
                (c => c.Sessions.FirstOrDefault<ConnectionSession>
                    (s => s.ConnectionId == playerBId) != null);

            // When the game started, created a game instance.
            var newGame = new GameDetails
                {
                    GameId = Guid.NewGuid(),
                    User1Id = playerA,
                    User2Id = playerB,
                    NextTurn = playerA.UserId
                };

            // Stores the game instance into cache.
            _games[newGame.GameId] = newGame;
            return newGame;
        }