예제 #1
0
        public async Task <bool> AutoPlayTurn(Guid gameSessionId)
        {
            var gameSessions = await gameSessionAccess.FindGameSessions(i => i.Id == gameSessionId);

            var gameSession = gameSessions.FirstOrDefault();

            gameSession.NotNull();

            var currentPlayers = await playerAccess.FindPlayers(i => i.Id == gameSession.CurrentPlayerId);

            var currentPlayer = currentPlayers.FirstOrDefault();

            currentPlayer.NotNull();

            var tiles = await tileAccess.FindTiles(i => i.Id == gameSessionId);

            var tile = autoPlayer.PlayTurn(tiles);

            tile.PlayerId = currentPlayer.Id;
            var result = await tileAccess.UpdateTile(tile);

            result = result && await IncrementPlayer(gameSessionId);

            return(result);
        }
예제 #2
0
        public async Task <PlayTurnResponse> PlayTurnAsync(PlayTurnRequest request)
        {
            var response = ServiceMessageFactory <PlayTurnResponse> .CreateFrom(request);

            var playerRequest = ServiceMessageFactory <GetPlayerRequest> .CreateFrom(request);

            playerRequest.PlayerId = request.PlayerId;
            var playerResponse = await playerAccess.GetPlayerAsync(playerRequest);

            var player = playerResponse.Player.Convert();

            var gameSessionRequest = ServiceMessageFactory <GetGameSessionRequest> .CreateFrom(request);

            gameSessionRequest.GameSessionId = request.GameSessionId;
            var gameSessionResponse = await gameSessionAccess.GetGameSessionAsync(gameSessionRequest);

            var gameSession = gameSessionResponse.GameSession.Convert();

            var tilesRequest = ServiceMessageFactory <FindTilesRequest> .CreateFrom(request);

            tilesRequest.Filter = tile => tile.GameSessionId == request.GameSessionId;
            var tilesResponse = await tileAccess.FindTilesAsync(tilesRequest);

            var tiles = tilesResponse.Tiles;

            Access.Tile.Interface.Tile tile;

            if (player.IsMachine)
            {
                tile          = autoPlayer.PlayTurn(tiles);
                tile.PlayerId = player.Id;
            }
            else
            {
                var address = request.Address.ToUpperInvariant();
                tile          = tiles.First(i => i.Address == address);
                tile.PlayerId = player.Id;
            }

            var updateTileRequest = ServiceMessageFactory <UpdateTileRequest> .CreateFrom(request);

            updateTileRequest.Tile = tile;
            var updateTileResponse = await tileAccess.UpdateTileAsync(updateTileRequest);

            if (updateTileResponse.HasErrors)
            {
                response.Errors += "Tile update error.";
            }
            IncrementPlayer(gameSession);

            return(response);
        }
예제 #3
0
        public async Task AutoPlayTurn(Guid gameSessionId)
        {
            var gameSession = await gameSessionAccess.GetGameSession(gameSessionId);

            var currentPlayer = await playerAccess.GetPlayer(gameSession.CurrentPlayerId);

            var tiles = await tileAccess.FindTiles(gameSessionId);

            var tile = autoPlayer.PlayTurn(tiles);

            tile.PlayerId = currentPlayer.Id;
            await tileAccess.UpdateTile(tile);

            await IncrementPlayer(gameSessionId);
        }