Android game 3 trials for user
<p>Hello it's my first time to develop android color game. However I'd like to put 3 trials in each question. I'm a bit confused how or where to put my while loop in my code. Please have a look on what I have tried so far:</p>

<pre><code>  int trial = 0;

  private void getCorrectObject() {

    List&lt;Integer&gt; objects = new ArrayList&lt;Integer&gt;();
    objects.add(1);
    objects.add(2);
    objects.add(3);
    objects.add(4);
    objects.add(5);
    objects.add(6);
    objects.add(7);
    objects.add(8);
    objects.add(9);

    Collections.shuffle(objects);
    int correctObject =  objects.get(0);
    Log.d("test", String.valueOf(correctObject));



    while(trial &lt;=3){
        trial++;


    switch(correctObject)
    {
    case 1:
        bObjectCorrect.setImageResource(R.drawable.stage1_1_object1);
        bObjectCorrect.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                Intent i = 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) {
                Intent i = 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) {
                Intent i = 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) {
                Intent i = 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) {
                Intent i = 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) {
                Intent i = 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) {
                Intent i = 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) {
                Intent i = 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) {
                Intent i = 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 you reached your 3rd trial")
        .setPositiveButton("Try Again?", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                Intent i = new Intent(Stage1_2.this, Stage1_1.class);
                startActivity(i);
            }
         })
        .setNegativeButton("Back to Menu", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                Intent i = new Intent(Stage1_2.this, ShapingColors.class);
                startActivity(i);
            }
         })
         .show();
    }

    } // end of while loop
</code></pre>

<p>I really like to finish this thing so I can continue with the game. Any help is truly appreciated. Thanks in advance.</p>

<p>I added a new method called <strong>guessedWrong()</strong></p>

<pre><code> private void guessedWrong(){
    trial++;

    if(trial == 3){
        new AlertDialog.Builder(this)
        .setTitle("Game Over")
        .setMessage("Sorry you reached your 3rd trial")
        .setPositiveButton("Try Again?", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                Intent i = new Intent(Stage1_1.this, Stage1_1.class);
                startActivity(i);
            }
         })
        .setNegativeButton("Back to Menu", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) { 
                Intent i = new Intent(Stage1_1.this, ShapingColors.class);
                startActivity(i);
            }
         })
         .show();
    }


}
</code></pre>
