c# - 不知道如何加载 50 个问题而不是 500 个
问题描述
引擎:统一
我正在使用这个名为 QuizGame 的游戏(它在Github上是免费的)
问题是,我的 QuizGame 上有超过 500 个问题(是的,这很重要)。当我开始游戏时,我必须通过每一个问题。有没有其他方法可以从这 500 个问题中只得到 50 个问题并开始游戏?然后在游戏结束后,从 500 中随机再随机选择 50 并一遍又一遍?
我认为这是问题所在:
Question GetRandomQuestion()
{
var randomIndex = GetRandomQuestionIndex();
currentQuestion = randomIndex;
return Questions[currentQuestion];
}
int GetRandomQuestionIndex()
{
var random = 0;
if (FinishedQuestions.Count < Questions.Length)
{
do
{
random = UnityEngine.Random.Range(0, Questions.Length);
} while (FinishedQuestions.Contains(10) || random == currentQuestion);
}
return random;
}
#endregion
}
解决方案
// Call GetQuestions(50) to get random 50 questions
Question[] GetQuestions(int maxQuestions)
{
System.Random random = new System.Random();
// first, we shuffle your questions array
// then, we take whatever amount you want
return questions.OrderBy(_ => random.Next()).Take(maxQuestions).ToArray();
}
推荐阅读
- javascript - 如何在断点处重新排序 div/更改标记
- python - 如何编写代码来读取输出文件以找出它在抓取网站中的距离,然后从它停止的地方开始
- flutter - 当用户在颤动中转到下一个文本文件时,我如何获得文本字段的值
- javascript - 用两个动作提交相同的表格?
- python - 在 Raspberry Pi Stretch 上安装 opencv 3.3.0 时 cv2 文件中出现无效转换错误
- excel - Excel 将执行相同操作的公式或 vba 函数的下拉列表
- elasticsearch - 如何在弹性搜索的突出显示部分应用布尔值(必须,应该)?
- react-native - get-stream 是否也适用于不基于博览会的常规 react-native 项目?
- outlook - EWS订阅在什么情况下会失效?
- javascript - 如何使 CodeMirror 从一定数量的行开始,并根据用户类型展开尽可能多的行?