Beispiel #1
0
        public PlayerDTO CreatePlayer(string playerName, int gameId, string connectionId)
        {
            PlayerDTO returnObj = null;

            JoinRequestModel request = new JoinRequestModel();

            request.PlayerName   = playerName;
            request.GameId       = gameId;
            request.ConnectionId = connectionId;
            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/JoinGame", request);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <PlayerDTO>(result.Data.ToString());
                        if (returnObj != null)
                        {
                            var tempAccount = CreateBankAccount(returnObj);
                            if (tempAccount != null)
                            {
                                returnObj.BankAccount = tempAccount;
                            }
                            else
                            {
                                returnObj = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Beispiel #2
0
        public GameDTO StartGame(int gameId)
        {
            GameDTO game = null;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/StartGame", gameId);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        game = JsonConvert.DeserializeObject <GameDTO>(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }
            return(game);
        }
Beispiel #3
0
        public List <SectorDTO> GetSectors()
        {
            List <SectorDTO> returnObj = new List <SectorDTO>();

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakeGetRequest("api/game/sectors");
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <List <SectorDTO> >(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Beispiel #4
0
        public List <AIBuySellDetails> GetPlayerAIData(GameDTO gameobj)
        {
            List <AIBuySellDetails> list = null;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/PlayerAi/GetPlayerAIData", gameobj);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result != null && result.Success)
                    {
                        list = JsonConvert.DeserializeObject <List <AIBuySellDetails> >(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(list);
        }
Beispiel #5
0
        public GameDetailDTO GetGameData(int gameId)
        {
            GameDetailDTO returnObj = new GameDetailDTO();

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakeGetRequest("api/trend?gameId=" + gameId.ToString());
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <GameDetailDTO>(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Beispiel #6
0
        public BankAccountDTO CreateBankAccount(PlayerDTO player)
        {
            BankAccountDTO returnObj = null;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Bank/CreateAccount", player);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <BankAccountDTO>(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Beispiel #7
0
        public bool GameEnded(PlayerDTO winner)
        {
            bool success = true;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/GameOver", winner);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (!result.Success)
                    {
                        success = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(success);
        }
Beispiel #8
0
        public bool DisconnectGame(int gameId)
        {
            bool success = true;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/EndGame", gameId);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (!result.Success)
                    {
                        success = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(success);
        }