Beispiel #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            if (!(value is GameStatusType))
            {
                return(null);
            }

            GameStatusType d = (GameStatusType)value;

            switch (d)
            {
            case GameStatusType.GameStatus_Created:
                return("Created");

            case GameStatusType.GameStatus_Playing:
                return("Playing");

            case GameStatusType.GameStatus_Won:
                return("Won");

            case GameStatusType.GameStatus_Lost:
                return("Lost");

            default:
                return("Created");
            }
        }
Beispiel #2
0
 public GameStatusModel(GameStatusType gameStatusType, Player winner = null)
 {
     Winner         = winner;
     GameStatusType = gameStatusType;
 }
Beispiel #3
0
        public GameLMSSummaryReturn GetGameLMSSummaryData(long gameid, string code)
        {
            /*
             * the gameid and code passed must correlate or they may be something malicious going on. so we stop
             * the response ASAP and throw an exception AND WE DO NOT CATCH IT, which should be picked up by Elmah. Exception handling here
             * have to be improved big-time
             */
            ProbeValidate.ValidateGameCodeVersusId(gameid, code);

            try
            {
                DateTime dateTimeNowUTC = DateTime.UtcNow;

                var       db        = new ProbeDataContext();
                Game      game      = db.Game.Find(gameid);
                ProbeGame probeGame = new ProbeGame(game);

                //update player statuses for a game.
                ProbeGame.UpdateAllGamePlayerStatuses(game, dateTimeNowUTC);


                //Get information about question that most recently passed the deadline and the next question after that
                long questionIdForMostRecentQuestion = probeGame.GetMostRecentQuestionPassedDeadline(dateTimeNowUTC);
                if (questionIdForMostRecentQuestion != ProbeConstants.NoPrimaryKeyId)
                {
                    int      mostRecentQuestionNbrPassed          = probeGame.GetProbeGameQuestionDeadline(questionIdForMostRecentQuestion).QuestionNumber;
                    DateTime mostRecentQuestionDeadlinePassed     = probeGame.GetProbeGameQuestionDeadline(questionIdForMostRecentQuestion).QuestionDeadlineDT;
                    string   mostRecentQuestionNameDeadlinePassed = db.Question.Find(questionIdForMostRecentQuestion).Name;

                    int nextQuestionNbr = (mostRecentQuestionNbrPassed + 1 <= probeGame.ProbeGameQuestionDeadlines.Count) ? mostRecentQuestionNbrPassed + 1 : mostRecentQuestionNbrPassed;
                    ProbeGameQuestionDeadline nextpgqd =
                        probeGame.ProbeGameQuestionDeadlines.Where(pgqd => pgqd.QuestionNumber == nextQuestionNbr).FirstOrDefault();
                    DateTime nextQuestionDeadline = nextpgqd.QuestionDeadlineDT;
                    string   nextQuestionName     = db.Question.Find(nextpgqd.QuestionId).Name;

                    int gameNbrQuestions = probeGame.Game.GameQuestions.Count();
                    mostRecentQuestionNbrPassed--; //calibrate to element 0 base. it was at element 1 base
                    nextQuestionNbr--;             //calibrate to element 0 base. it was at element 1 base

                    //Will return -1 if there are no questions submitted yet
                    int maxQuestionNbrSubmitted = probeGame.GetMaxQuestionNbrSubmitted();

                    GameStatusType gameStatusType = GameStatusType.UNKNOWN;
                    if (ProbeValidate.IsGameStartPassed(game) && (mostRecentQuestionNbrPassed < probeGame.ProbeGameQuestionDeadlines.Count - 1))
                    {
                        gameStatusType = GameStatusType.ACTIVE;
                    }
                    else
                    {
                        gameStatusType = GameStatusType.COMPLETED;
                    }

                    GameLMSSummaryReturn gsdr = new GameLMSSummaryReturn
                    {
                        GameStatus         = gameStatusType,
                        GameNbrQuestions   = gameNbrQuestions,
                        NbrPlayers         = probeGame.NbrPlayers,
                        NbrPlayersActive   = probeGame.NbrPlayersActive,
                        NbrPlayersInactive = probeGame.NbrPlayers - probeGame.NbrPlayersActive,
                        MostRecentQuestionNbrDeadlinePassed  = mostRecentQuestionNbrPassed,
                        MostRecentQuestionNameDeadlinePassed = mostRecentQuestionNameDeadlinePassed,
                        MostRecentQuestionDeadlinePassed     = mostRecentQuestionDeadlinePassed,
                        NextQuestionNbr         = nextQuestionNbr,
                        NextQuestionName        = nextQuestionName,
                        NextQuestionDeadline    = nextQuestionDeadline,
                        MaxQuestionNbrSubmitted = maxQuestionNbrSubmitted
                    };

                    return(gsdr);
                }
                else
                {
                    //IF WE ARE HERE THAT MEANS THAT THE FIRST QUESTION DEADLINE OF THE GAME HAS NOT PASSED.

                    //We send back a reduced set of information when the game is not active and it hasn't even started
                    int            gameNbrQuestions                     = probeGame.Game.GameQuestions.Count();
                    GameStatusType gameStatusType                       = GameStatusType.UNKNOWN;
                    int            mostRecentQuestionNbrPassed          = ProbeConstants.ValueIntNone;
                    string         mostRecentQuestionNameDeadlinePassed = ProbeConstants.ValueStringNone;
                    DateTime       mostRecentQuestionDeadlinePassed     = DateTime.MinValue;
                    int            nextQuestionNbr                      = ProbeConstants.ValueIntNone;
                    string         nextQuestionName                     = ProbeConstants.ValueStringNone;
                    DateTime       nextQuestionDeadline                 = DateTime.MinValue;

                    if (ProbeValidate.IsGameStartPassed(game))
                    {
                        //no most recent question deadline passed. However there is a next question deadline (first question
                        //of the game
                        gameStatusType       = GameStatusType.STARTEDNOQUESTIONPASSED;
                        nextQuestionNbr      = 0;
                        nextQuestionDeadline = probeGame.ProbeGameQuestionDeadlines[0].QuestionDeadlineDT;
                        nextQuestionName     = db.Question.Find(probeGame.ProbeGameQuestionDeadlines[0].QuestionId).Name;
                    }
                    else
                    {
                        gameStatusType = GameStatusType.NOTSTARTED;
                    }

                    int maxQuestionNbrSubmitted = probeGame.GetMaxQuestionNbrSubmitted();

                    GameLMSSummaryReturn gsdr = new GameLMSSummaryReturn
                    {
                        //We will provide information about any players that have submitted already even if the first question's deadline hasn't been reached.
                        GameStatus         = gameStatusType,
                        GameNbrQuestions   = gameNbrQuestions,
                        NbrPlayers         = probeGame.NbrPlayers,
                        NbrPlayersActive   = probeGame.NbrPlayersActive,
                        NbrPlayersInactive = probeGame.NbrPlayers - probeGame.NbrPlayersActive,
                        MostRecentQuestionNbrDeadlinePassed  = mostRecentQuestionNbrPassed,
                        MostRecentQuestionNameDeadlinePassed = mostRecentQuestionNameDeadlinePassed,
                        MostRecentQuestionDeadlinePassed     = mostRecentQuestionDeadlinePassed,
                        NextQuestionNbr         = nextQuestionNbr,
                        NextQuestionName        = nextQuestionName,
                        NextQuestionDeadline    = nextQuestionDeadline,
                        MaxQuestionNbrSubmitted = maxQuestionNbrSubmitted
                    };

                    return(gsdr);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }//public GameLMSSummaryReturn