コード例 #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
        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);
        }
コード例 #3
0
        /// <summary>
        /// Gera duas respostas falsas para serem apresentadas juntamente da correta
        /// </summary>
        private void CreateAnswers()
        {
            chanceToSpawnCorrectAnswer = 0.1;
            correctAnswerSpawned       = false;
            correctAnswer = null;
            this.answers  = new Answer[3];

            for (int i = 0; i < 3; i++)
            {
                if (PublicRandom.NextDouble() > chanceToSpawnCorrectAnswer || correctAnswerSpawned)
                {
                    this.answers[i] = AnswerFactory.CreateAnswer((Renderer3D)Renderer, CollidableObjects, question, currentAnswerIndex, false, answers);
                }
                else
                {
                    correctAnswerSpawned = true;
                    this.answers[i]      = AnswerFactory.CreateAnswer((Renderer3D)Renderer, CollidableObjects, question, currentAnswerIndex, true, answers);
                    correctAnswer        = this.answers[i];
                }
            }

            //se o jogador não recebeu 1 ponto de graça, então somamos 1 ao valor da questão atual
            if (!pityPoint)
            {
                currentAnswerValue += 1;
            }
            pityPoint = false;
        }
コード例 #4
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);
                }
            }
        }
コード例 #5
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;
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        public Answer(Renderer3D renderer, IEnumerable <CollidableGameObject> collidableObjects, string text)
            : base(renderer, collidableObjects)
        {
            this.text = text;
            //"gravidade"
            VariableMovementComponent vmc =
                new VariableMovementComponent(this, 30,
                                              Vector3.Down / 1000 * (float)PublicRandom.NextDouble(0.01f),
                                              Vector3.Down / 100);

            vmc.LowerVelocityThreshold = Vector3.Down / 4;
            addComponent(vmc);
        }
コード例 #11
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);
        }
コード例 #12
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)]);
     }
 }
コード例 #13
0
        /// <summary>
        /// Altera o texto de uma resposta.
        /// </summary>
        /// <param name="a">A resposta que terá seu texto alterado.</param>
        private void ChangeAnswer(Answer a)
        {
            string text;
            double bonusLottery = PublicRandom.NextDouble();

            if (correctAnswerSpawned || (PublicRandom.NextDouble() > chanceToSpawnCorrectAnswer && fakeSpawnCount < maxFakeSpawnCount || (bonusLottery > bonusChance && !bonusSpawned)))  //alterar a resposta para alguma outra incorreta
            {
                if (!bonusSpawned && bonusLottery <= bonusChance && !correctAnswerSpawned && bonusCount < 3)
                {
                    text         = "+1";
                    a.IsBonus    = true;
                    bonusSpawned = true;
                    bonusCount++;
                }
                else
                {
                    text         = IncorrectAnswer();
                    a.IsBonus    = false;
                    bonusSpawned = false;
                }

                //se a resposta sendo alterada for a correta, avisar o sistema para que uma nova resposta correta possa ser gerada futuramente
                if (correctAnswer != null && a.Equals(correctAnswer))
                {
                    correctAnswerSpawned = false;
                    correctAnswer        = null;
                }
                chanceToSpawnCorrectAnswer *= 3; //triplica a chance de "spawnar" a resposta correta na próxima vez
                fakeSpawnCount++;
            }
            else //alterar a resposta para a resposta correta
            {
                a.IsBonus    = false;
                bonusSpawned = false;
                text         = CorrectAnswer();
                chanceToSpawnCorrectAnswer = 0.1;
                fakeSpawnCount             = 0;
                bonusCount           = 0;
                correctAnswerSpawned = true;
                this.correctAnswer   = a;
            }

            a.Text = text;
        }
コード例 #14
0
        private PropType GetRandomPropType(double max = 1.0)
        {
            double   rdn  = PublicRandom.NextDouble(0, max);
            PropType type = PropType.NONE;

            if (rdn < propsWeight[0])
            {
                type = PropType.TREE;
            }
            else if (rdn < propsWeight[1])
            {
                type = PropType.CACTUS;
            }
            else if (rdn < propsWeight[2])
            {
                type = PropType.GRASS;
            }
            else if (rdn < propsWeight[3])
            {
                type = PropType.ROCK;
            }
            return(type);
        }
コード例 #15
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);
        }
コード例 #16
0
        private void KickBall()
        {
            Vector3 kickDeviation = Vector3.Zero;

            if (!makeGoal)
            {
                kickDeviation.Y = (float)PublicRandom.NextDouble(0, 0.2);
                if (PublicRandom.NextDouble() > 0.5)
                {
                    kickDeviation.Y *= -1;
                }

                kickDeviation.Z = -(float)PublicRandom.NextDouble(0.15, 0.25);

                kickDeviation.X = -(float)PublicRandom.NextDouble(0, 0.1);
                if (PublicRandom.NextDouble() > 0.5)
                {
                    kickDeviation.X *= -1;
                }
            }

            ball.Position = ball.Position * (Vector3.UnitX + Vector3.UnitZ);
            ball.Kick2(new Vector3(0, 0.4f, 0.3f) + kickDeviation, new Vector3(-kickDeviation.X / 1000, -0.05f, -0.0005f), Vector3.Zero);
        }