Home > Software design >  Multiple choice quiz game
Multiple choice quiz game

Time:07-12

Im trying to create multiple choice quiz game for kids for my assignment purpose. This quiz has 30 questions all together. The questions are generated randomly. My problem here is the question are being repeated and the game doesn’t end once the questions is out of stock. What should i do now?

CodePudding user response:

It highly depends on what you need. The most straightforward solution (at least if I understood the problem correctly) will be like:

  • use two arrays (or lists, whatever) with all possible questions (lets call them _source and _current)
  • at the beginning of the game make sure that _current contains all the questions from the _source
  • select your random question from the _current and REMOVE it from the _current
  • if _current has no objects - your quiz is ended

In such a case, there will be no situation when questions can be repeated during a single session.

CodePudding user response:

what you could do is, have a variable storing the number of questions you have. You said you have 30, so we will work with that. Every time a question is displayed remove 1 from that count. Eg

public int Questions;
void Start()
{
Questions = 30;
}
public void GenerateQuestion()
{
if(Questions >= 1)
{
//Generate your question
}
else
{
//end game
}
  • Related