Exemplo n.º 1
0
        private CreateGameInstanceResponse CreateGame(CreateGameInstance request)
        {
            var result = new CreateGameInstanceResponse();
            var game = new CardGame();
            game.Id = Guid.NewGuid().ToString();
            game.Deck = CardFactory.CardDealersDeck();
            game.Events = new List<CardGameEvent>();
            game.Events.Add(new CardGameEvent
            {
                ClientId = "SERVER",
                GameId = game.Id,
                Message = "Game Created at " + DateTime.UtcNow.ToString("F"),
                Type = "SYSTEM"
            });

            Cache.Set(game.Id, game,TimeSpan.FromHours(1));
            var allGames = Cache.Get<AllGames>(AllGamesSummaries);
            if (allGames == null)
            {
                allGames = new AllGames { Games = new List<GameSummary>() };
            }
            if(allGames.Games == null) allGames.Games = new List<GameSummary>();

            allGames.Games.Add(new GameSummary { GameId = game.Id });
            Cache.Set(AllGamesSummaries, allGames);
            JoinGame(new PlayerJoinGame
            {
                GameId = game.Id,
                PlayerId = request.PlayerOneId,
                PlayerDisplayerName = request.PlayerDisplayName
            });

            result.GameId = game.Id;
            return result;
        }
Exemplo n.º 2
0
        private CreateGameInstanceResponse CreateGame(CreateGameInstance request)
        {
            var result = new CreateGameInstanceResponse();
            var game   = new CardGame();

            game.Id     = Guid.NewGuid().ToString();
            game.Deck   = CardFactory.CardDealersDeck();
            game.Events = new List <CardGameEvent>();
            game.Events.Add(new CardGameEvent
            {
                ClientId = "SERVER",
                GameId   = game.Id,
                Message  = "Game Created at " + DateTime.UtcNow.ToString("F"),
                Type     = "SYSTEM"
            });

            Cache.Set(game.Id, game, TimeSpan.FromHours(1));
            var allGames = Cache.Get <AllGames>(AllGamesSummaries);

            if (allGames == null)
            {
                allGames = new AllGames {
                    Games = new List <GameSummary>()
                };
            }
            if (allGames.Games == null)
            {
                allGames.Games = new List <GameSummary>();
            }

            allGames.Games.Add(new GameSummary {
                GameId = game.Id
            });
            Cache.Set(AllGamesSummaries, allGames);
            JoinGame(new PlayerJoinGame
            {
                GameId              = game.Id,
                PlayerId            = request.PlayerOneId,
                PlayerDisplayerName = request.PlayerDisplayName
            });

            result.GameId = game.Id;
            return(result);
        }