Reputation: 13
I am developing a quiz game, where I have to get random activities on answering the questions as to avoid the questions in same order. I have fixed this by using switch
However, the problem is that I may return to questions which I've already answered, so I now have to code something that avoids the player to go to previous questions by the random generator.
I've done this so far;
Random rand = new Random();
int number = rand.nextInt(10);
Intent intent = null;
switch(number){
case 0: intent = new Intent(MainActivity.this, Question001.class);
break;
case 1: intent = new Intent(MainActivity.this, Question002.class);
break;
//etc....
}
startActivity(intent);
This brings randomly activities on button click, however I want to disable previously visited questions meaning, if a person has answered the question from class Question002, he must not be able to (never and never) get this question once more, as this will result in his gaining of extra points from earlier questions. How do I randomly get questions on button click only ONCE, so they won't appear again? I hope my question is understood.
Every question is stored in its own class (Question001, Question002.... Question009)
Upvotes: 0
Views: 535
Reputation: 6792
Follow these steps:
Let me know if it is unclear.
Upvotes: 1
Reputation: 1265
use
ArrayList<Integer> number = new ArrayList<Integer>();
for (int i = 1; i <= 10; ++i) number.add(i);
Collections.shuffle(number);
Upvotes: 0