Esempio n. 1
0
        //public async Task<Result> TurnCardAsync(string gameId, string playerId, string cardId)
        //{
        //    var game = await _gameStore.GetAsync(gameId);
        //    if (game == null)
        //    {
        //        return Result.Failure("Unable to find game for id");
        //    }
        //    var player = game.Players.Single(p => p.Id == playerId);
        //    var card = player.CurrentCard;
        //    card.IsTurned = true;
        //    return Result.Success();
        //}

        public async Task <Result <GameDto> > GetGameAsync(string id, string forPlayerId)
        {
            var game = await _gameStore.GetAsync(id);

            if (game == null)
            {
                return(Result <GameDto> .Failure("Unable to find a game with the id"));
            }
            else
            {
                var gameDto = DtoMapper.ToDto(game, forPlayerId);
                return(Result <GameDto> .Success(gameDto));
            }
        }
Esempio n. 2
0
        public async Task <GameDto> HandleGameEvent(GameEventDto gameEventDto)
        {
            var game = await _gameStore.GetAsync(gameEventDto.GameId);

            if (game == null)
            {
                return(null);
            }

            var initiatingPlayer = game.Players.Single(p => p.Id == gameEventDto.PlayerId);

            switch (gameEventDto.EventType)
            {
            case GameEventType.Nothing:
                break;

            case GameEventType.Join:
                break;

            case GameEventType.ShuffleDeck:
                game.CardDeck.Shuffle();
                game.AddGameAction($"{initiatingPlayer.Name} shuffled the deck");
                break;

            case GameEventType.Deal:
            {
                foreach (var player in game.Players)
                {
                    player.CurrentCard          = game.CardDeck.First();
                    player.CurrentCard.IsTurned = false;
                    game.CardDeck.RemoveAt(0);
                }
                game.AddGameAction($"{initiatingPlayer.Name} dealt cards");
            }
            break;

            case GameEventType.TurnCard:
                game.AddGameAction($"{initiatingPlayer.Name} turned his card");
                HandleTurnCardEvent(gameEventDto, game);
                break;

            default:
                throw new Exception("Unknown gameeventtype?");
                break;
            }

            return(DtoMapper.ToDto(game, gameEventDto.PlayerId));
        }
Esempio n. 3
0
        public async Task <Result <StartNewGameResponse> > StartNewGameAsync(string initiatingPlayerName)
        {
            var newGame = _gameStore.CreateNew();

            newGame.AddGameAction($"{initiatingPlayerName} started the game");

            newGame.CardDeck = new CardDeck();

            var newPlayerId = AddPlayer(newGame, initiatingPlayerName);

            newGame.DealerPlayerId = newPlayerId;  //Player that starts the game is dealer

            var response = new StartNewGameResponse();

            response.NewPlayerId = newPlayerId;
            response.Game        = DtoMapper.ToDto(newGame, newPlayerId);


            return(Result <StartNewGameResponse> .Success(response));
        }