public GameDetails Game(Guid gameId)
 {
     GameDetails game;
     if (!_games.ContainsKey(gameId))
     {
         _games[gameId] = new GameDetails { GameId = gameId };
     }
     game = _games[gameId];
     return game;
 }
예제 #2
0
        public GameDetails Game(Guid gameId)
        {
            GameDetails game;

            if (!_games.ContainsKey(gameId))
            {
                _games[gameId] = new GameDetails {
                    GameId = gameId
                };
            }
            game = _games[gameId];
            return(game);
        }
예제 #3
0
        internal GameDetails UpdateCache(string userId,
                                         string connectionId, ConnectionStatus status)
        {
            if (_connections.ContainsKey(userId) &&
                !string.IsNullOrEmpty(userId))
            {
                UpdateUserSession(userId, connectionId, status);
            }
            else
            {
                CreateNewUserSession(userId, connectionId);
            }
            GameDetails gd = _games.Values.LastOrDefault <GameDetails>(g => g.User1Id.UserId == userId || g.User2Id.UserId == userId);

            return(gd);
        }
예제 #4
0
        internal GameDetails NewGame(string player1Id, string player2Id)
        {
            UserCredential player1 = _connections.Values.FirstOrDefault <UserCredential>
                                         (c => c.Sessions.FirstOrDefault <ConnectionSession>
                                             (s => s.ConnectionId == player1Id) != null);
            UserCredential player2 = _connections.Values.FirstOrDefault <UserCredential>
                                         (c => c.Sessions.FirstOrDefault <ConnectionSession>
                                             (s => s.ConnectionId == player2Id) != null);
            GameDetails newGame = new GameDetails
            {
                GameId   = Guid.NewGuid(),
                User1Id  = player1,
                User2Id  = player2,
                NextTurn = player1.UserId
            };

            _games[newGame.GameId] = newGame;
            return(newGame);
        }
 internal GameDetails NewGame(string player1Id, string player2Id)
 {
     UserCredential player1 = _connections.Values.FirstOrDefault<UserCredential>
         (c => c.Sessions.FirstOrDefault<ConnectionSession>
             (s => s.ConnectionId == player1Id) != null);
     UserCredential player2 = _connections.Values.FirstOrDefault<UserCredential>
         (c => c.Sessions.FirstOrDefault<ConnectionSession>
             (s => s.ConnectionId == player2Id) != null);
     GameDetails newGame = new GameDetails
     {
         GameId = Guid.NewGuid(),
         User1Id = player1,
         User2Id = player2,
         NextTurn = player1.UserId
     };
     _games[newGame.GameId] = newGame;
     return newGame;
 }