Пример #1
0
        /// <summary>
        /// Reposiciona as questões, deixando-as espaçadas aleatóriamente no eixo Z.
        /// </summary>
        private void PositionAnswers()
        {
            float zIncrement = 0;

            bool[] answersPositioned = new bool[answers.Length];
            int    max     = 3;
            bool   visible = true;

            while (max > 0)
            {
                int i = PublicRandom.Next(max);
                while (answersPositioned[i])
                {
                    i += (PublicRandom.Next(2) == 0 ? 1 : -1);
                    if (i >= answers.Length)
                    {
                        i -= answers.Length;
                    }
                    else if (i < 0)
                    {
                        i += answers.Length;
                    }
                }
                answersPositioned[i] = true;
                Vector3 offset = new Vector3(i - 1, PublicRandom.Next(3, 5), zIncrement);
                this.answers[i].Position = position + offset;
                this.answers[i].Visible  = visible;
                visible     = false;
                zIncrement += PublicRandom.Next(3, 6);
                max--;
            }
        }
Пример #2
0
 /// <summary>
 /// Atualiza a posição das respostas e muda o multiplicador do score caso o jogador tenha errado.
 /// </summary>
 private void UpdateScoreAndQuestion()
 {
     if (foundAnswer == 1)
     {
         AnswersGot++;
         if (!questions[questions.Count - 1].Next())
         {
             ChangeCurrentQuestion();
             AudioManager.GetCue("BB00" + PublicRandom.Next(6, 8)).Play();
         }
         else
         {
             questions[questions.Count - 1].Position = (new Vector3(0, 0, player.Position.Z + 5));
             AudioManager.GetCue("BB00" + PublicRandom.Next(3, 6)).Play();
         }
     }
     else
     {
         Answer answer = questions[questions.Count - 1].GetClosestAnswer();
         if (!answer.IsBonus)
         {
             perfectScoreMultiplier = 1;    //a partir do momento que o jogador errou uma questão, não ganha mais o dobro de pontos
             MistakesMade++;
             AudioManager.GetCue("wrong_answer_1").Play();
         }
         else
         {
             AudioManager.GetCue("decision17").Play();
         }
         questions[questions.Count - 1].MoveAnswer(answer);
     }
     foundAnswer = 0;
 }
Пример #3
0
        private static Question GenerateQuestion(int level, List <QuestionGameObject> existingQuestions, Question[][] questions)
        {
            Question q;

            bool[] usedIndexes  = new bool[questions[level].Length];
            int    testingIndex = PublicRandom.Next(questions[level].Length);

            q = questions[level][testingIndex];
            int tries = 0;

            for (int i = 0; i < existingQuestions.Count && tries < 100; i++)
            {
                if (q.Header.Equals(existingQuestions[i].Header))
                {
                    usedIndexes[testingIndex] = true;
                    i = 0;

                    while ((usedIndexes[testingIndex] || q.Equals(lastCreated)) && tries < 100)
                    {
                        testingIndex = PublicRandom.Next(questions[level].Length);
                        tries++;
                    }
                    q = questions[level][testingIndex];
                }
            }
            lastCreated = q;
            return(q);
        }
Пример #4
0
        private Texture2D GetRandomPropTexture(out float baseScale, double max = 1.0)
        {
            baseScale = 0;
            Texture2D tex;

            switch (GetRandomPropType(max))
            {
            case PropType.CACTUS:
                tex       = cactus[PublicRandom.Next(cactus.Length)];
                baseScale = (float)PublicRandom.NextDouble(0.5);
                break;

            case PropType.GRASS:
                tex       = grass[PublicRandom.Next(grass.Length)];
                baseScale = (float)PublicRandom.NextDouble(0.1, 0.4);
                break;

            case PropType.ROCK:
                tex       = rock[PublicRandom.Next(rock.Length)];
                baseScale = (float)PublicRandom.NextDouble(0.1, 0.75);
                break;

            case PropType.TREE:
                tex       = tree[PublicRandom.Next(tree.Length)];
                baseScale = (float)PublicRandom.NextDouble(0.5) + PublicRandom.Next(1, 3) + PublicRandom.Next(2);
                break;

            default:
                tex = null;
                break;
            }

            return(tex);
        }
Пример #5
0
        /// <summary>
        /// Verifica se o jogador colidiu ou passou por alguma resposta.
        /// </summary>
        private void CheckAnswer()
        {
            if (MistakesMade < AllowedMistakes)
            {
                if (foundAnswer != 0)
                {
                    UpdateScoreAndQuestion();
                }
                else if (!answeredAll)
                {
                    QuestionGameObject question = questions[questions.Count - 1];
                    Answer             a        = question.GetClosestAnswer();

                    if (cam.ViewFrustum.Contains(a.BoundingBox) == ContainmentType.Disjoint && a.Z < player.Z)
                    {
                        if (question.CheckAnswer(a, true))
                        {
                            perfectScoreMultiplier = 1;    //a partir do momento que o jogador errou uma questão, não ganha mais o dobro de pontos
                            MistakesMade++;
                            AudioManager.GetCue("miss_answer_" + (PublicRandom.Next(2) + 1)).Play();
                        }
                        question.MoveAnswer(a);
                    }
                }
            }
            else if (!answeredAll)
            {
                answeredAll = true;
                foreach (QuestionGameObject q in questions)
                {
                    goManager.RemoveObject(q);
                }
            }
        }
Пример #6
0
        public static string CreatePTAnswer(Question q, int answerIndex, Answer[] otherAnswers, bool correct)
        {
            string answer;
            string correctAnswer = q.GetAnswer(answerIndex);

            if (correct)
            {
                answer = correctAnswer;
            }
            else
            {
                int  attempts = 0;
                bool alreadyInUse;
                do
                {
                    alreadyInUse = false;
                    answer       = "";
                    int chance = 10;
                    do
                    {
                        answer += ((char)PublicRandom.Next((int)'A', (int)'Z')).ToString();
                        chance  = (int)(chance * 1.5);
                    } while (answer.Length < correctAnswer.Length && PublicRandom.Next(100) > chance);

                    alreadyInUse = SearchAnswer(answer, otherAnswers);

                    attempts++;
                } while (attempts < MAX_ATTEMPTS || answer.Equals(correctAnswer));
            }

            return(answer);
        }
Пример #7
0
        public static string CreateMathAnswer(Question q, int answerIndex, Answer[] otherAnswers, bool correct)
        {
            int min = 0;
            int max = 100;

            string answer;

            string currentModifier = q.GetModifier(answerIndex);

            string correctAnswer = q.GetAnswer(answerIndex);

            int numericAnswer = 0;

            if (Int32.TryParse(correctAnswer, out numericAnswer))
            {
                if (currentModifier.Equals((correct ? "<" : ">")))
                {
                    max = Int32.Parse(correctAnswer);
                    min = max - 10;
                }
                else if (currentModifier.Equals((correct ? ">" : "<")))
                {
                    min = Int32.Parse(correctAnswer) + 1;
                    max = min + 10;
                }
                else if (correct)
                {
                    min = max = numericAnswer;
                }
                else
                {
                    min = numericAnswer - 5;
                    max = min + 10;
                }

                if (min < 0)
                {
                    min = 0;
                }

                int  attempts = 0;
                bool alreadyInUse;
                do
                {
                    answer       = PublicRandom.Next(min, max).ToString();
                    alreadyInUse = false;

                    alreadyInUse = SearchAnswer(answer, otherAnswers);

                    attempts++;
                } while ((attempts < MAX_ATTEMPTS && alreadyInUse) || (!correct && answer.Equals(correctAnswer)));
            }
            else
            {
                answer = CreatePTAnswer(q, answerIndex, otherAnswers, correct);
            }

            return(answer);
        }
Пример #8
0
        private Vector3 GetRandomPropPosition(int min = 0)
        {
            float x = (float)(PublicRandom.Next(300, 800)) / 100;

            x *= PublicRandom.Next(2) == 0 ? 1 : -1;
            float z = (float)PublicRandom.Next(min, rows * 100) / 100;

            return(new Vector3(x, 0, z) + position);
        }
Пример #9
0
        private void LoadQuestions()
        {
            questions.Clear();
            for (int i = 0; i < numberOfQuestions; i++)
            {
                questions.Add(QuestionFactory.CreateQuestion(level, subjects[PublicRandom.Next(subjects.Length)], goManager.R3D, goManager.CollidableGameObjects, questions));
            }

            goManager.AddObject(questions[questions.Count - 1]);
            questionHeader.Text = questions[questions.Count - 1].Header;

            ResetAnswersDisplay();
            CreateAnswersSupports();

            questions[questions.Count - 1].Player   = player;
            questions[questions.Count - 1].Position = new Vector3(0, 0f, 5);
        }
Пример #10
0
 private void PlayBGM()
 {
     if (bgm != null && !bgm.IsStopped)
     {
         if (!bgm.IsPlaying && !bgm.IsStopping)
         {
             bgm.Play();
         }
         if (bgm.IsPaused)
         {
             bgm.Resume();
         }
     }
     else
     {
         ChangeBgm(bgmNames[PublicRandom.Next(3)]);
     }
 }
Пример #11
0
        /// <summary>
        /// Move uma resposta no eixo Z por um valor aleatório entre 3 e 5.
        /// </summary>
        /// <param name="a">A resposta a ser movida.</param>
        public void MoveAnswer(Answer a)
        {
            float newZ    = player.Position.Z + PublicRandom.Next(4, 7);
            bool  usableZ = false;
            int   tries   = 0;

            do
            {
                newZ += (float)PublicRandom.NextDouble(0.25);
                foreach (Answer answer in answers)
                {
                    usableZ = (answer.Position.Z >= newZ + minAnswerDistance || answer.Position.Z <= newZ - minAnswerDistance);
                    if (!usableZ)
                    {
                        break;
                    }
                }
                tries++;
            } while (!usableZ && tries < 50);

            a.Position = new Vector3(a.Position.X, PublicRandom.Next(3, 5), newZ);
            a.Visible  = false;
            ChangeAnswer(a);
        }