[英]Android random activites without repetition
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
我已经通过使用
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. 这会带来随机的单击按钮活动,但是我想禁用以前访问的问题,这意味着,如果一个人回答了Question002类的问题,那么他一定不能(永远也永远不会)再次遇到这个问题,因为这将导致他从先前的问题中获得了加分。 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) 每个问题都存储在其自己的类中(Question001,Question002 .... Question009)
Follow these steps: 跟着这些步骤:
Let me know if it is unclear. 让我知道是否不清楚。
use 采用
ArrayList<Integer> number = new ArrayList<Integer>();
for (int i = 1; i <= 10; ++i) number.add(i);
Collections.shuffle(number);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.