I'm trying to create a simple maths quiz game that has a level system. im using sqlite database. I just want to know how to shuffle the first 5 entry question in my database when I click the level 1 and the 6-10 entry question if i click the level 2
Here is my code for MainmenuActivity.java
:
public class MainmenuActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void submit(View v)
{
DatabaseHelper entry = new DatabaseHelper(MainmenuActivity.this);
entry.open();
entry.createEntry(1,"1+1=?","2","3","4","5");
entry.close();
entry.open();
entry.createEntry(2,"3+1","4","5","6","7");
entry.close();
entry.open();
entry.createEntry(3,"6+4=?","10","20","30","40");
entry.close();
entry.open();
entry.createEntry(4,"1+4?","5","11","10","9");
entry.close();
Intent i = new Intent(MainmenuActivity.this, game.class);
startActivity(i);
}
public void level2(View v){
DatabaseHelper entry = new DatabaseHelper(MainmenuActivity.this);
entry.open();
entry.createEntry(5,"7+1?","8","2","5","4");
entry.close();
entry.open();
entry.createEntry(6,"9+3?","12","13","11","10");
entry.close();
entry.open();
entry.createEntry(7,"10+1?","11"," 2","13","5");
entry.close();
entry.open();
entry.createEntry(8,"7+5=?","12","13","14","15");
entry.close();
entry.open();
entry.createEntry(9,"15+1?","16","18","6","17");
entry.close();
entry.open();
entry.createEntry(10,"6+12?","18","12","22","15");
entry.close();
Intent i = new Intent(MainmenuActivity.this, game.class);
startActivity(i);
}
}
My code in the game.java
:
//this is for displaying the questions
public class game extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
b[1] = (Button)findViewById(R.id.button1);
b[2] = (Button)findViewById(R.id.button2);
b[3] = (Button)findViewById(R.id.button3);
b[4] = (Button)findViewById(R.id.button4);
t=(TextView)findViewById(R.id.textView1);
Questions();
}
public void Questions()
{
DatabaseHelper mDbHelper = new DatabaseHelper(game.this);
mDbHelper.open();
Cursor CR = mDbHelper.getInformation(mDbHelper);
CR.moveToFirst();
x=rand.nextInt(101-1)+1;
y=rand.nextInt(5-1)+1;
for (z=0;z<76;z++)
{
if (x==finishedquestions[z])
{
x=rand.nextInt(101-1)+1;
z=0;
}
}
do{
if (x.equals(CR.getInt(0)))
{
question = CR.getString(1);
t.setText(CR.getString(1));
right=CR.getString(2);
wrong1=CR.getString(3);
wrong2=CR.getString(4);
wrong3=CR.getString(5);
b[y].setText(right);
if (y==1)
{
b[2].setText(wrong1);
b[3].setText(wrong2);
b[4].setText(wrong3);
}else if (y==2)
{
b[1].setText(wrong1);
b[3].setText(wrong2);
b[4].setText(wrong3);
}else if (y==3)
{
b[2].setText(wrong1);
b[1].setText(wrong2);
b[4].setText(wrong3);
}else if (y==4)
{
b[2].setText(wrong1);
b[3].setText(wrong2);
b[1].setText(wrong3);
}
}
}while(CR.moveToNext());
finishedquestions[ctrquestions]=x;
ctrquestions++;
}
}
Aucun commentaire:
Enregistrer un commentaire