jeudi 2 juin 2016

shuffle between activities without repetition Android game

I have a game that has many different activities. It starts from a Main Menu and then Q1, Q2 and Q3 are 3 separate activities containing content. I know how to shuffle between activities but there is always repetition because I have about 30 activities. I've been searching and searching and finally decided to ask you guys. Read about bundles but couldn't figure it out on my own. I'm such a noob. Unless I can see the code i'm stuck. I tried by myself in many different ways but all of it is just nonsense I think. So basically when it shuffles it should go Q1 then Q3 then Q4. Instead because It repeats it has the possibility of going Q1 then Q3 then Q1 again, which is disastrous for my game. Please help if possible with a little more detailed coding. I know i'm annoying, but I don't know any other programmers in my village.

MainMenu.java

    public class MainMenu extends AppCompatActivity {

final ArrayList<Class> activities = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mainmenu);

    activities.add(Q1.class);
    activities.add(Q2.class);
    activities.add(Q3.class);
}
public void onHintClick(View view) {

    Toast toasty = Toast.makeText(getApplicationContext(), getString(R.string.H1), Toast.LENGTH_SHORT);
    toasty.show();

}






public void onAnswerClick(View v){


    if (activities.size()==0){
        activities.add(Q1.class);
        activities.add(Q2.class);
        activities.add(Q3.class);

    }
    Collections.shuffle(activities);

    Class activityToShow = activities.get(0);

    Intent intent = new Intent(MainMenu.this, activityToShow);
    activities.remove(0);
    startActivity(intent);
       }
    }

Q1.java

    public class Q1 extends AppCompatActivity {

final ArrayList<Class> activities = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_q1);

    final ArrayList<Class> activities = new ArrayList<>();

    activities.add(Q2.class);
    activities.add(Q3.class);

}
    public void button(View view){


if (activities.size()==0){

    activities.add(Q2.class);
    activities.add(Q3.class);

}
Collections.shuffle(activities);

Class activityToShow = activities.get(0);

Intent intent = new Intent(Q1.this, activityToShow);
activities.remove(0);
startActivity(intent);
    }
    }

and similar code for Q2 and Q3.....what I need to know is, how to now make these pages repeat. Please tell me in the simplest way as I really am I noob. Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire