示例#1
0
        public IEnumerable <ResponseJson> NewMove(int idGame, int idMove, int idPlayer, int idRound)
        {
            ResponseJson     response = null;
            InitializeClient client   = new InitializeClient(new InitializeClient.EndpointConfiguration());

            try
            {
                var task = client.NewMoveAsync(idGame, idMove, idPlayer, idRound);
                task.Wait();
                if (task.IsCompletedSuccessfully)
                {
                    response = task.Result;
                }
                else
                {
                    response = new ResponseJson {
                        Code = -1, Message = "Cannot insert move"
                    }
                };
            }
            catch (Exception e)
            {
                client.LogErrorAsync(e.StackTrace);
                response = new ResponseJson {
                    Code = -10, Message = "An error has ocurred, please try it later"
                };
            }
            finally
            {
                client.LogsAsync("NewMove", "{'idGame':'" + idGame + "','idMove':'" + idMove + "','idPlayer':'" + idPlayer + "','idRound','" + idRound + "'}", ParseObjectToJson(response));
            }
            return(ToEnumerable <ResponseJson>(response));
        }
示例#2
0
        public IEnumerable <ResponseJson> GetMoves()
        {
            ResponseJson     response = null;
            InitializeClient client   = new InitializeClient(new InitializeClient.EndpointConfiguration());

            try
            {
                var task = client.GetMovesAsync();
                task.Wait();
                if (task.IsCompletedSuccessfully)
                {
                    response = task.Result;
                }
                else
                {
                    response = new ResponseJson {
                        Code = -1, Message = "Cannot get move´s list"
                    }
                };
            }
            catch (Exception e)
            {
                client.LogErrorAsync(e.StackTrace);
                response = new ResponseJson {
                    Code = -10, Message = "An error has ocurred, please try it later"
                };
            }
            finally
            {
                client.LogsAsync("GetMoves", "", ParseObjectToJson(response));
            }
            return(ToEnumerable <ResponseJson>(response));
        }
示例#3
0
        private GameControllerModel InsertPlayer(string player, InitializeClient client, int idGame = 0)
        {
            GameControllerModel response = null;

            try
            {
                var task = client.NewPlayerAsync(player, idGame);
                task.Wait();
                if (task.IsCompletedSuccessfully)
                {
                    ResponseJson responseJson = task.Result;
                    response = ParseJsonToObject <GameControllerModel>(responseJson.Json);
                }
                else
                {
                    response = new GameControllerModel {
                        Code = -1, Message = "Cannot get move´s list"
                    }
                };
            }
            catch (Exception e)
            {
                client.LogErrorAsync(e.StackTrace);
                response = new GameControllerModel {
                    Code = -10, Message = "An error has ocurred, please try it later"
                };
            }
            return(response);
        }
示例#4
0
        public IEnumerable <ResponseJson> GetDetailsScore(int idPlayer)
        {
            ResponseJson     response = null;
            InitializeClient client   = new InitializeClient(new InitializeClient.EndpointConfiguration());

            try
            {
                var task = client.GetGameDetailScoreAsync(idPlayer);
                task.Wait();
                if (task.IsCompletedSuccessfully)
                {
                    response = task.Result;
                }
                else
                {
                    response = new ResponseJson {
                        Code = -1, Message = "Cannot get game´s detail"
                    }
                };
            }
            catch (Exception e)
            {
                client.LogErrorAsync(e.StackTrace);
                response = new ResponseJson {
                    Code = -10, Message = "An error has ocurred, please try it later"
                };
            }
            finally
            {
                client.LogsAsync("GetDetailsScore", "{'idPlayer':'" + idPlayer + "'}", ParseObjectToJson(response));
            }
            return(ToEnumerable <ResponseJson>(response));
        }
示例#5
0
        public IEnumerable <ResponseJson> StartGame(string playerOne, string playerTwo)
        {
            ResponseJson           responseJson      = null;
            GameControllerModel    responsePlayerOne = null;
            GameControllerModel    responsePlayerTwo = null;
            GameControllerResponse response          = null;
            InitializeClient       client            = new InitializeClient(new InitializeClient.EndpointConfiguration());

            try
            {
                responsePlayerOne = InsertPlayer(playerOne, client);
                if (responsePlayerOne.Code == 0)
                {
                    responsePlayerTwo = InsertPlayer(playerTwo, client, responsePlayerOne.IdGame);
                    responseJson      = new ResponseJson {
                        Code = responsePlayerTwo.Code, Message = responsePlayerTwo.Message
                    };
                }
                response = new GameControllerResponse {
                    IdGame = responsePlayerOne.IdGame, PlayerOne = responsePlayerOne.IdPlayer, PlayerTwo = responsePlayerTwo.IdPlayer, IdRound = responsePlayerOne.IdRound
                };
                responseJson.Json = ParseObjectToJson(response);
            }
            catch (Exception e)
            {
                client.LogErrorAsync(e.StackTrace);
                responseJson = new ResponseJson {
                    Code = -10, Message = "An error has ocurred, please try it later"
                };
            }
            finally
            {
                client.LogsAsync("StartGame", "{'playerOne':'" + playerOne + "','playerTwo':'" + playerTwo + "'}", ParseObjectToJson(response));
            }
            return(ToEnumerable <ResponseJson>(responseJson));
        }