mirror of
https://github.com/ConjureETS/GameOff2024.git
synced 2026-03-24 05:00:59 +00:00
65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Random = System.Random;
|
|
|
|
namespace GameOff.Quiz
|
|
{
|
|
[DefaultExecutionOrder(-60)]
|
|
public class QuizHandler : MonoBehaviour
|
|
{
|
|
public static QuizHandler Instance { get; private set; }
|
|
|
|
[SerializeField] private int questionAmount = 20;
|
|
[SerializeField] private List<Sprite> questionVisual;
|
|
[SerializeField] private int seed;
|
|
[SerializeField] private bool randomGeneration;
|
|
|
|
private readonly List<string> ChoicePossibles = new List<string>() { "a", "b", "c", "d", "e", "f" };
|
|
|
|
private Random _random;
|
|
private List<QuestionInfo> _questionInfos;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance)
|
|
{
|
|
Debug.LogError($"QuizManager already exist! {transform}");
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (randomGeneration)
|
|
seed = UnityEngine.Random.Range(0, Int32.MaxValue);
|
|
_random = new Random(seed);
|
|
|
|
GenerateQuiz();
|
|
}
|
|
|
|
private void GenerateQuiz()
|
|
{
|
|
_questionInfos = new List<QuestionInfo>();
|
|
|
|
for (int i = 1; i <= questionAmount; i++)
|
|
{
|
|
int amount = _random.Next(2, ChoicePossibles.Count);
|
|
string answer = ChoicePossibles[_random.Next(amount)];
|
|
List<string> tmp = new List<string>();
|
|
|
|
for (int x = 0; x < amount; x++)
|
|
tmp.Add(ChoicePossibles[x]);
|
|
_questionInfos.Add(new QuestionInfo(i, questionVisual[_random.Next(questionVisual.Count)], tmp, answer));
|
|
}
|
|
}
|
|
|
|
public List<QuestionInfo> QuestionInfos => _questionInfos;
|
|
|
|
public int QuestionAmount => questionAmount;
|
|
}
|
|
}
|