/// <summary>
        /// Setup all the view elements for a given question
        /// </summary>
        /// <param name="q">Q.</param>
        private void UpdateViewWithQuestion(Question q)
        {
            Logger.I ( "Setting up view for current question " + q);

              // Image
              string imgPath = ImageDatabase.Instance.Getimage(q.CorrectAnswer);
              mCurrentImage = UIImage.FromFile(imgPath);
              ImageGame.Image = mCurrentImage;

              setImageAnimation();

              // Answers
              SetButtonsTitle(q);

              // Score
              LabelScore.Text = mQuizz.Score.ToString("000000");

              // Combo
              var width = 0f;
              switch (mQuizz.Combo)
              {
            case 2:
              LabelCombo.Text = "x2";
              width = 82f;
              break;
            case 3:
              LabelCombo.Text = "x3";
              width = 41f;
              break;
            case 4:
              LabelCombo.Text = "x4";
              width = 0f;
              break;
            default:
              LabelCombo.Text = "x1";
              width = 123f;
              break;
              }

              UIView.Animate(1f, 0.1f, UIViewAnimationOptions.CurveEaseIn, () =>
              {
            ConstraintCombo.Constant = width;
            //ViewEmitter.SetNeedsLayout();
            ViewEmitter.LayoutIfNeeded();
              }, null);

              /*
               * Joker
               */

              // Enable the joker if enough questions has been answered correctly
              ButtonJoker.Enabled = mQuizz.IsJokerAvailable;

              // Animate the joker bottom space constraints to reflect the current state
              UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseOut, () => {
            switch (mQuizz.JokerPartCount)
            {
              case 0:
            ConstraintJoker.Constant = -60;
            break;
              case 1:
            ConstraintJoker.Constant = -40;
            break;
              case 2:
            ConstraintJoker.Constant = -20;
            break;
              default:
            ConstraintJoker.Constant = 0;
            break;
            }

            ButtonJoker.LayoutIfNeeded();
              }, null);

              // Joker content
              if (Constants.DEBUG_MODE)
              {
            ButtonJoker.SetTitle("Joker (" + mQuizz.JokerPartCount + ")", UIControlState.Normal);
              }
              else
              {
            ButtonJoker.SetTitle("Joker", UIControlState.Normal);
              }

              /*
               * Questions
               */

              // Question count
              LabelCount.Text = mQuizz.QuestionNumber.ToString();

              /*
               * Lives
               */

              // Display the correct number of lives
              if (mQuizz.Mode == GameMode.SURVIVAL)
              {
            //        switch (mQuizz.Lives)
            //        {
            //          case 1:
            //            livesImage.Image = new UIImage("lives_1.png");
            //            break;
            //          case 2:
            //            livesImage.Image = new UIImage("lives_2.png");
            //            break;
            //          case 3:
            //            livesImage.Image = new UIImage("lives_3.png");
            //            break;
            //          default:
            //          // TODO 0 state if needed
            //            break;
            //        }
              }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a new question for a multiplayer match, not the first turn
        /// </summary>
        /// <returns>The question.</returns>
        public Question GetMatchQuestion()
        {
            if (RequiredGameIds != null && RequiredGameIds.Count > 0) {

                if (mCurrentRequiredGameIdsIndex < RequiredGameIds.Count) {

                    Question q = new Question ();

                    KeyValuePair<int, int[]> questionInfo = RequiredGameIds.ElementAt (mCurrentRequiredGameIdsIndex);

                    for (int i=0; i < questionInfo.Value.Length; i++) {

                        int answerId = questionInfo.Value[i];
                        GameEntry game = mMatchingGames.Where (g => g.GameId == answerId).FirstOrDefault ();

                        if (game == null) {
                            Logger.E( "The game with id " + answerId + " wasn't loaded by the filter!");
                            // HACK : The game is missing, let's not crash.
                            return null;
                        } else {
                            q.Answers.Add (game);

                            if (answerId == questionInfo.Key) {
                                q.CorrectAnswer = game;
                            }
                        }
                    }

                    mCurrentRequiredGameIdsIndex++;

                    return q;
                }
            }

            return null;
        }
        private void SetButtonsTitle(Question q)
        {
            // Disable buttons
              if (q == null)
              {

            ButtonJoker.Enabled = false;

            ButtonGame1.Enabled = false;
            ButtonGame2.Enabled = false;
            ButtonGame3.Enabled = false;
            ButtonGame4.Enabled = false;
            ButtonGame1.SetTitle("", UIControlState.Normal);
            ButtonGame2.SetTitle("", UIControlState.Normal);
            ButtonGame3.SetTitle("", UIControlState.Normal);
            ButtonGame4.SetTitle("", UIControlState.Normal);
              }
              // Buttons for current question
              else
              {

            if (mQuizz.IsJokerAvailable)
            {
              ButtonJoker.Enabled = true;
            }

            ButtonGame1.Enabled = true;
            ButtonGame2.Enabled = true;
            ButtonGame3.Enabled = true;
            ButtonGame4.Enabled = true;

            // TODO PAL
            ButtonGame1.SetTitle(q.GetGameTitle(0, GameZone.PAL, mQuizz.TextTransformation), UIControlState.Normal);
            ButtonGame2.SetTitle(q.GetGameTitle(1, GameZone.PAL, mQuizz.TextTransformation), UIControlState.Normal);
            ButtonGame3.SetTitle(q.GetGameTitle(2, GameZone.PAL, mQuizz.TextTransformation), UIControlState.Normal);
            ButtonGame4.SetTitle(q.GetGameTitle(3, GameZone.PAL, mQuizz.TextTransformation), UIControlState.Normal);
              }
        }
Ejemplo n.º 4
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;
        }