Peasant can finish the quiz

This commit is contained in:
Samir Badi 2024-11-11 14:33:31 -05:00
parent 1a34a1c036
commit f2b39a9dad
5 changed files with 31 additions and 24 deletions

View File

@ -46,9 +46,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
answers: []
initTime: 20
minTimePerQuestion: 5
maxTimePerQuestion: 18
initTime: 2
minTimePerQuestion: 0.5
maxTimePerQuestion: 1
successRate: 0.75
--- !u!1 &5739709613417327085
GameObject:
m_ObjectHideFlags: 0

View File

@ -764,21 +764,6 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 54002814}
m_Modifications:
- target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: initTime
value: 2
objectReference: {fileID: 0}
- target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: maxTimePerQuestion
value: 1
objectReference: {fileID: 0}
- target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: minTimePerQuestion
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_Name
@ -3952,6 +3937,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
questionAmount: 20
quizTakerAmount: 8
questionVisual:
- {fileID: -959586227, guid: 19a8aecd158cac04fb8bb6de1e21ffaa, type: 3}
- {fileID: -1923230478, guid: 19a8aecd158cac04fb8bb6de1e21ffaa, type: 3}
@ -3960,7 +3946,6 @@ MonoBehaviour:
- {fileID: 233852084, guid: 19a8aecd158cac04fb8bb6de1e21ffaa, type: 3}
seed: 0
randomGeneration: 1
correctAnswer: []
--- !u!1 &1839156921
GameObject:
m_ObjectHideFlags: 0

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using GameOff.Peasant;
using GameOff.Quiz;
using UnityEngine;
using Random = System.Random;
@ -12,10 +13,10 @@ namespace GameOff.Core
public static QuizHandler Instance { get; private set; }
[SerializeField] private int questionAmount = 20;
[SerializeField] private int quizTakerAmount = 8;
[SerializeField] private List<Sprite> questionVisual;
[SerializeField] private int seed;
[SerializeField] private bool randomGeneration;
[SerializeField] private string[] correctAnswer;
private readonly List<string> ChoicePossibles = new List<string>() { "a", "b", "c", "d", "e", "f" };
@ -46,7 +47,6 @@ namespace GameOff.Core
private void GenerateQuiz()
{
_questionInfos = new List<QuestionInfo>();
correctAnswer = new string[questionAmount];
for (int i = 0; i < questionAmount; i++)
{
@ -58,11 +58,25 @@ namespace GameOff.Core
tmp.Add(ChoicePossibles[x]);
_questionInfos.Add(new QuestionInfo(i + 1, questionVisual[_random.Next(questionVisual.Count)], tmp, answer));
correctAnswer[i] = tmp[_random.Next(amount)];
}
}
public string GetAnswerAtIndex(int index) => correctAnswer[index];
public string GetAnswerAtIndex(int index, float successRate) {
if(_random.Next(100) <= successRate * 100)
return _questionInfos[index].Answer;
return _questionInfos[index].Choices[_random.Next(_questionInfos[index].Count)];
}
public float GetResultPercent(string[] answer)
{
float succeed = 0;
for (int i = 0; i < answer.Length; i++)
if (answer[i] == _questionInfos[i].Answer)
succeed++;
return succeed / questionAmount * 100;
}
public List<QuestionInfo> QuestionInfos => _questionInfos;
public int QuestionAmount => questionAmount;

View File

@ -11,6 +11,8 @@ namespace GameOff.Peasant
[SerializeField] private float initTime = 20f;
[SerializeField] private float minTimePerQuestion = 5f;
[SerializeField] private float maxTimePerQuestion = 18f;
[Range(0, 1)]
[SerializeField] private float successRate = 0.75f;
private int _indexQuestion;
private float _answerTimer;
@ -29,14 +31,17 @@ namespace GameOff.Peasant
if (_answerTimer <= 0)
{
answers[_indexQuestion] = QuizHandler.Instance.GetAnswerAtIndex(_indexQuestion);
answers[_indexQuestion] = QuizHandler.Instance.GetAnswerAtIndex(_indexQuestion, successRate);
_answerTimer = RandomQuestionTimer();
_indexQuestion++;
if (_indexQuestion >= answers.Length)
{
Debug.Log($"{name}: {QuizHandler.Instance.GetResultPercent(answers)}%");
enabled = false;
}
}
}
private float RandomQuestionTimer()
{

View File

@ -17,5 +17,7 @@ namespace GameOff.Quiz
Choices = choices;
Answer = answer;
}
public int Count => Choices.Count;
}
}