Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class rear_gunner extends AppCompatActivity {
- int clickcount=0;
- CountDownTimer countDownTimer;
- int score = 0;
- int health2 = 100;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_rear_gunner);
- final TextView text = (TextView) findViewById(R.id.textView2);
- final TextView scoreText = (TextView) findViewById(R.id.score);
- final TextView health = (TextView) findViewById(R.id.Health);
- health.setText("Health:"+ health2);
- //Enemy ImageViews
- final ImageView enemy1 = (ImageView) findViewById(R.id.enemy1);
- final ImageView enemy2 = (ImageView) findViewById(R.id.enemy2);
- final ImageView enemy3 = (ImageView) findViewById(R.id.enemy3);
- final ImageView enemy4 = (ImageView) findViewById(R.id.enemy4);
- //sets screen orientation on created
- this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- //sets imageViews into array
- final ImageView[] enemies = new ImageView[4];
- enemies[0] = enemy1;
- enemies[1] = enemy2;
- enemies[2] = enemy3;
- enemies[3] = enemy4;
- boolean running = true;
- while (!running) {
- if (enemy1.getVisibility() == View.VISIBLE) {
- int damage = 1;
- health2 = health2 - damage;
- health.setText("Health:" + health2);
- } else {
- // Either gone or invisible
- }
- if (enemy2.getVisibility() == View.VISIBLE) {
- int damage = 1;
- health2 = health2 - damage;
- health.setText("Health:" + health2);
- } else {
- // Either gone or invisible
- }
- if (enemy3.getVisibility() == View.VISIBLE) {
- int damage = 1;
- health2 = health2 - damage;
- health.setText("Health:" + health2);
- } else {
- // Either gone or invisible
- }
- if (enemy4.getVisibility() == View.VISIBLE) {
- int damage = 1;
- health2 = health2 - damage;
- health.setText("Health:" + health2);
- } else {
- // Either gone or invisible
- }
- }
- //random number generator between 10-25
- Random r = new Random();
- int Low = 10000;
- int High = 25000;
- int Result = r.nextInt(High-Low) + Low;
- //count down timer for spawing enemies
- countDownTimer = new CountDownTimer(Result, 1000) {
- @Override
- public void onTick(long millisUntilFinished) {
- text.setText("seconds remaining: " + millisUntilFinished / 1000);
- if (score == 500)
- {
- countDownTimer.cancel();
- }
- }
- @Override
- public void onFinish() {
- Random r = new Random();
- int Low = 0;
- int High = 4;
- int Result = r.nextInt(High-Low) + Low;
- enemies[Result].setVisibility(View.VISIBLE);
- countDownTimer.start();
- if (score == 500)
- {
- countDownTimer.cancel();
- }
- }
- };
- countDownTimer.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement