Now it doesn't show the same CChar pinyin in selection

This commit is contained in:
BOT Alex 2023-06-29 13:13:04 +02:00
parent dab3cb47b7
commit 2a49117995
1 changed files with 8 additions and 2 deletions

View File

@ -125,14 +125,20 @@
void GenerateQuestion() void GenerateQuestion()
{ {
if (DontSkipTheseCChar.Count < 3) throw new Exception("Finished this chunk of CChars"); if (DontSkipTheseCChar.Count < 5) throw new Exception("Finished this chunk of CChars");
int correctIndex = Random.Shared.Next(0, Answers.Length); int correctIndex = Random.Shared.Next(0, Answers.Length);
for (int i = 0; i < Answers.Length; i++) for (int i = 0; i < Answers.Length; i++)
{ {
bool isCorrect = i == correctIndex; bool isCorrect = i == correctIndex;
Answers[i] = new Answer(DontSkipTheseCChar[Random.Shared.Next(0, DontSkipTheseCChar.Count)], isCorrect); CChar randomCChar;
repickRandomCChar:
randomCChar = DontSkipTheseCChar[Random.Shared.Next(0, DontSkipTheseCChar.Count)];
if (Answers.Any(x =>x != null && x.cchar == randomCChar)) goto repickRandomCChar;
Answers[i] = new Answer(randomCChar, isCorrect);
} }
} }