java - Logic flow for android game -


hi i'm new android game development , i'd ask guys regarding correct logic flow android game of mine. here's game. it's pretty simple game user has choose correct color. game has 3 stages. in each stage, has 10 questions. in each question, has 30 seconds timer. question , choices, of course needs randomized. if user chooses correct color, proceed next question. if user chooses wrong color, he/she has 3 trials choose, if he/she reaches 3rd trial, game over , display try again button.

here's piece of code tried:

    // created custom countdown timer c/o     counter = new mycount(30000,1000);      counter.start();      // call correct object     getcorrectobject();       @override public void onclick(view v) {     // todo auto-generated method stub     switch(v.getid()){     case r.id.pause:         if(mlastresourceid == r.drawable.pause){             pause.setimageresource(r.drawable.resume);             mlastresourceid = r.drawable.resume;             counter.cancel();         } else if (mlastresourceid == r.drawable.resume) {             pause.setimageresource(r.drawable.pause);             mlastresourceid = r.drawable.pause;             counter = new mycount(s1,1000);             counter.start();         }         break;   }   public class mycount extends countdowntimer  {     public mycount(long millisinfuture, long countdowninterval)     {         super(millisinfuture, countdowninterval);     }     @override          public void onfinish()     {         intent = new intent(getapplicationcontext(), stage1_2.class);         startactivity(i);     }      textview tx = (textview) findviewbyid(r.id.timer);     @override          public void ontick(long millisuntilfinished)     {         s1 = millisuntilfinished;         tx.settext("" + millisuntilfinished / 1000);     } } 

what i'm considering is, if user chooses correct answer without timer has ended, should put in ontick method force timer end? , 1 of tricky part face randomization of choices or objects.

here i've tried far:

 private void getcorrectobject() {     // todo auto-generated method stub      list<integer> objects = new arraylist<integer>();     objects.add(1);     objects.add(2);     objects.add(3);     objects.add(4);     objects.add(5);     objects.add(6);     objects.add(7);      collections.shuffle(objects);     int correctobject =  objects.get(0);     log.d("test", string.valueof(correctobject));      switch(correctobject)     {     case 1:         bobjectcorrect.setimageresource(r.drawable.tree1);         bobjectcorrect.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_1.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 2:         bobject1.setimageresource(r.drawable.tree1);         bobject1.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_1.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 3:         bobject2.setimageresource(r.drawable.tree1);         bobject2.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_1.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 4:         bobject3.setimageresource(r.drawable.tree1);         bobject3.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_1.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 5:         bobject4.setimageresource(r.drawable.tree1);         bobject4.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_1.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 6:         bobject5.setimageresource(r.drawable.tree1);         bobject5.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_1.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 7:         bobject6.setimageresource(r.drawable.tree1);         bobject6.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_1.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     } } 

updated: , thing is, i'm confused put while loop in here 3 trials.

 // put 3 trials logic here     while(trial <= 3){     trial++;   switch(correctobject)     {     case 1:         bobjectcorrect.setimageresource(r.drawable.stage1_1_object1);         bobjectcorrect.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 2:         bobject1.setimageresource(r.drawable.stage1_1_object1);         bobject1.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 3:         bobject2.setimageresource(r.drawable.stage1_1_object1);         bobject2.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 4:         bobject3.setimageresource(r.drawable.stage1_1_object1);         bobject3.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 5:         bobject4.setimageresource(r.drawable.stage1_1_object1);         bobject4.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 6:         bobject5.setimageresource(r.drawable.stage1_1_object1);         bobject5.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 7:         bobject6.setimageresource(r.drawable.stage1_1_object1);         bobject6.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 8:         bobject7.setimageresource(r.drawable.stage1_1_object1);         bobject7.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     case 9:         bobject8.setimageresource(r.drawable.stage1_1_object1);         bobject8.setonclicklistener(new view.onclicklistener() {              public void onclick(view view) {                 // todo auto-generated method stub                 intent = new intent(getapplicationcontext(), stage1_2.class);                 startactivity(i);                 new thread(){                     public void run(){                         mediaplayer mp = mediaplayer.create(stage1_2.this, r.raw.brown);                         mp.start();                     }                 }.start();                 finish();             }         });         break;     } // last of switch statement      if(trial == 3){         new alertdialog.builder(this)         .settitle("game over")         .setmessage("sorry reached 3rd trial")         .setpositivebutton("try again?", new dialoginterface.onclicklistener() {             public void onclick(dialoginterface dialog, int which) {                  intent = new intent(stage1_2.this, stage1_1.class);                 startactivity(i);             }          })         .setnegativebutton("back menu", new dialoginterface.onclicklistener() {             public void onclick(dialoginterface dialog, int which) {                  intent = new intent(stage1_2.this, shapingcolors.class);                 startactivity(i);             }          })          .show();     }      } // last of while loop 

i'd love hear suggestions. appreciated. in advance!

you don't need put in ontick handle case. after you've called cancel() (which in click handler), ontick() won't called again.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -