Ejemplo n.º 1
0
    void MakeQuiz()
    {
        int count = possibleQuestions.Count;

        int[] order = new int[count];

        for (int i = 0; i < count; i++)
        {
            order[i] = i;
        }

        // shuffle the order
        order = Shuffle(order);

        // create quiz
        quiz = new List <TantanganQuiz>();

        for (int i = 0; i < count; i++)
        {
            TantanganQuestion q      = possibleQuestions[order[i]];
            TantanganAnswer   answer = q.answer;

            // this logic is still wronggg
            int wrongOneId = 0;
            int wrongTwoId = 0;

            do
            {
                wrongOneId = rand.Next(0, count);
            } while(answer.id == wrongOneId);

            do
            {
                wrongTwoId = rand.Next(0, count);
            } while(answer.id == wrongTwoId || wrongOneId == wrongTwoId);

            TantanganAnswer wrongOne = possibleAnswers.Find(x => x.id == wrongOneId);
            TantanganAnswer wrongTwo = possibleAnswers.Find(x => x.id == wrongTwoId);

            TantanganAnswer[] answerArray = Shuffle <TantanganAnswer>(
                new TantanganAnswer[] {
                answer,
                wrongOne,
                wrongTwo
            }
                );

            List <TantanganAnswer> answerList = new List <TantanganAnswer>(answerArray);
            quiz.Add(new TantanganQuiz(q, answerList));
        }
    }
Ejemplo n.º 2
0
    public void Setup()
    {
        rand = new System.Random();
        possibleQuestions = new List <TantanganQuestion>();
        possibleAnswers   = new List <TantanganAnswer>();

        for (int i = 0; i < clips.Count; i++)
        {
            TantanganAnswer   answer   = new TantanganAnswer(i, answers[i], buttonImages[i]);
            TantanganQuestion question = new TantanganQuestion(clips[i], answer);
            possibleQuestions.Add(question);
            possibleAnswers.Add(answer);
        }

        MakeQuiz();
    }
Ejemplo n.º 3
0
    void OnClickAnswer(int id)
    {
        TantanganAnswer answer         = currentQuiz.question.answer;
        TantanganAnswer selectedAnswer = currentQuiz.choices[id];

        if (selectedAnswer.id == answer.id)
        {
            // correct
            _winText.text = answer.answer;
            SwitchCanvas(TantanganScreen.Win);
            musicPlayer.clip = winSound;
            musicPlayer.Play();
        }
        else
        {
            // wrong
            _loseText.text = answer.answer;
            SwitchCanvas(TantanganScreen.Lose);
            musicPlayer.clip = loseSound;
            musicPlayer.Play();
        }
    }
Ejemplo n.º 4
0
 public TantanganQuestion(AudioClip v, TantanganAnswer a)
 {
     _voice  = v;
     _answer = a;
 }