Advertisement
Guest User

Java

a guest
Nov 28th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package com.example.randomgalandnoam;
  2.  
  3. import java.util.Random;
  4.  
  5. import android.support.v7.app.ActionBarActivity;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.ImageButton;
  11. import android.widget.TextView;
  12.  
  13.  
  14. public class RandomMainActivity extends ActionBarActivity {
  15.     /*ImageButton ib00,ib01,ib02,ib03,ib04,ib05,ib06,ib07,ib08,ib09,
  16.     ib10,ib11,ib12,ib13,ib14,ib15,ib16,ib17,ib18,ib19,
  17.     ib20,ib21,ib22,ib23,ib24,ib25,ib26,ib27,ib28,ib29,
  18.     ib30,ib31,ib32,ib33,ib34,ib35,ib36,ib37,ib38,ib39,
  19.     ib40,ib41,ib42,ib43,ib44,ib45,ib46,ib47,ib48;*/
  20.     TextView tv00;
  21.      Boolean flag=true;
  22.      Random ran;
  23.      int count=0;
  24.      ImageButton picx[];
  25.      
  26.       @Override
  27.         protected void onCreate(Bundle savedInstanceState) {
  28.             super.onCreate(savedInstanceState);
  29.             setContentView(R.layout.activity_random_main);
  30.             picx=new ImageButton[49];
  31.             for (int j=0;j<49;j++)
  32.             {
  33.              int index=getResources().getIdentifier("ib"+j+1, "ib", getPackageName());
  34.              picx[j]=(ImageButton)findViewById(index);
  35.              picx[j].setTag("0");
  36.             }
  37.            
  38.             ran=new Random();
  39.             initGame();
  40.         }
  41.       public void initGame()
  42.        {
  43.               for (int j=0;j<49;j++)
  44.                  {
  45.                  
  46.                   picx[j].setImageResource(R.drawable.pic);
  47.                   picx[j].setTag("0");
  48.                  }
  49.               int y=ran.nextInt(49);
  50.              picx[y].setTag("1");
  51.              picx[y].setImageResource(R.drawable.pic1);
  52.              tv00.setText("   "+count);
  53.             }
  54.            
  55.             public void onClick (View V)
  56.             {
  57.              ImageButton z=(ImageButton) findViewById(V.getId());
  58.              if(z.getTag()=="1")
  59.               count++;
  60.              else
  61.               count--;
  62.              initGame();
  63.              
  64.              
  65.             }
  66.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement