Пример #1
0
        public ActionResult <Response <Game> > BeginGame([FromHeader] int playerID)
        {
            try
            {
                //Create the player object and begin the game.
                Player          hostPlayer = new Player(playerID);
                Response <Game> response   = new GameDAL().BeginGame(hostPlayer);

                //If the response is successful schedule code to run to update the GameState after the time periods have passed
                if (response.IsSuccessful())
                {
                    HubInterface hubInterface = new HubInterface(_hubContext);
                    ScheduledTasks.ScheduleGameInPlayingState(response.Data, hubInterface);
                    ScheduledTasks.ScheduleCompleteGame(response.Data, hubInterface);

                    //Update all clients that the game is now in a starting state and the game will be playing soon
                    hubInterface.UpdateGameInStartingState(response.Data);
                }
                return(response);
            }
            //Catch any error associated with invalid model data
            catch (InvalidModelException e)
            {
                return(new Response <Game>(e.Msg, e.Code));
            }
            //Catch any unhandled / unexpected server errrors
            catch
            {
                return(StatusCode(500));
            }
        }