Пример #1
0
        /// <summary>
        /// Get a random question
        /// </summary>
        /// <returns>The random question.</returns>
        internal Question GetRandomQuestion()
        {
            int currentAnswersCount = 0;

            Question q = null;

            // Multiplayer and not the first turn?
            // We must play exactly the same game as the other players
            if (Mode == GameMode.VERSUS) {
                if (PlayerCache.Instance.AuthenticatedPlayer.CurrentMatch.IsFirstTurn == false) {
                    q = Filter.GetMatchQuestion ();
                }
            }

            // Not multiplayer or no more registered quesiton?
            // Let's go random
            if (q == null) {

                q = new Question ();
                bool isFirstAndCorrectAnswer = true;

                while (currentAnswersCount < mAnswerCount) {

                    // If we have a given game questions list (versus mode), we can randomize all answers except the correct one
                    GameEntry game = Filter.GetRandomGame ();

                    if (q.Answers.Contains (game) == false && mCorrectAnswerIds.Contains (game.GameId) == false) {

                        q.Answers.Add (game);
                        currentAnswersCount++;

                        // Decide that the first will be the correct answer
                        if (isFirstAndCorrectAnswer) {

                            q.CorrectAnswer = game;
                            mCorrectAnswerIds.Add (q.CorrectAnswer.GameId);

                            isFirstAndCorrectAnswer = false;
                        }
                    }
                }
                // Randomize answers
                q.ShuffleAnswers ();
            }
            return q;
        }