Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. public class rear_gunner extends AppCompatActivity {
  2.  
  3. int clickcount=0;
  4. CountDownTimer countDownTimer;
  5. int score = 0;
  6. int health2 = 100;
  7.  
  8.  
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.activity_rear_gunner);
  13.  
  14. final TextView text = (TextView) findViewById(R.id.textView2);
  15. final TextView scoreText = (TextView) findViewById(R.id.score);
  16. final TextView health = (TextView) findViewById(R.id.Health);
  17. health.setText("Health:"+ health2);
  18. //Enemy ImageViews
  19. final ImageView enemy1 = (ImageView) findViewById(R.id.enemy1);
  20. final ImageView enemy2 = (ImageView) findViewById(R.id.enemy2);
  21. final ImageView enemy3 = (ImageView) findViewById(R.id.enemy3);
  22. final ImageView enemy4 = (ImageView) findViewById(R.id.enemy4);
  23.  
  24. //sets screen orientation on created
  25. this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  26.  
  27. //sets imageViews into array
  28. final ImageView[] enemies = new ImageView[4];
  29. enemies[0] = enemy1;
  30. enemies[1] = enemy2;
  31. enemies[2] = enemy3;
  32. enemies[3] = enemy4;
  33.  
  34. boolean running = true;
  35. while (!running) {
  36. if (enemy1.getVisibility() == View.VISIBLE) {
  37. int damage = 1;
  38. health2 = health2 - damage;
  39. health.setText("Health:" + health2);
  40. } else {
  41. // Either gone or invisible
  42. }
  43. if (enemy2.getVisibility() == View.VISIBLE) {
  44. int damage = 1;
  45. health2 = health2 - damage;
  46. health.setText("Health:" + health2);
  47. } else {
  48. // Either gone or invisible
  49. }
  50. if (enemy3.getVisibility() == View.VISIBLE) {
  51. int damage = 1;
  52. health2 = health2 - damage;
  53. health.setText("Health:" + health2);
  54. } else {
  55. // Either gone or invisible
  56. }
  57. if (enemy4.getVisibility() == View.VISIBLE) {
  58. int damage = 1;
  59. health2 = health2 - damage;
  60. health.setText("Health:" + health2);
  61. } else {
  62. // Either gone or invisible
  63. }
  64. }
  65.  
  66. //random number generator between 10-25
  67. Random r = new Random();
  68. int Low = 10000;
  69. int High = 25000;
  70. int Result = r.nextInt(High-Low) + Low;
  71.  
  72. //count down timer for spawing enemies
  73. countDownTimer = new CountDownTimer(Result, 1000) {
  74.  
  75. @Override
  76. public void onTick(long millisUntilFinished) {
  77. text.setText("seconds remaining: " + millisUntilFinished / 1000);
  78.  
  79. if (score == 500)
  80. {
  81. countDownTimer.cancel();
  82. }
  83. }
  84. @Override
  85. public void onFinish() {
  86. Random r = new Random();
  87. int Low = 0;
  88. int High = 4;
  89. int Result = r.nextInt(High-Low) + Low;
  90. enemies[Result].setVisibility(View.VISIBLE);
  91.  
  92. countDownTimer.start();
  93. if (score == 500)
  94. {
  95. countDownTimer.cancel();
  96. }
  97. }
  98.  
  99.  
  100.  
  101. };
  102.  
  103.  
  104.  
  105.  
  106. countDownTimer.start();
  107.  
  108.  
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement