Advertisement
Guest User

AIDE Error

a guest
May 1st, 2018
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.29 KB | None | 0 0
  1. package com.mpadhq.tonysmith.whackamonkey;
  2.  
  3. import android.app.*;
  4. import android.os.*;
  5. import android.view.*;
  6. import android.view.View.*;
  7. import android.widget.*;
  8. import android.content.*;
  9. import android.content.ClipboardManager;
  10. import android.graphics.*;
  11. import android.media.*;
  12. import android.net.*;
  13. import android.text.*;
  14. import android.util.*;
  15. import android.webkit.*;
  16. import android.animation.*;
  17. import android.view.animation.*;
  18.  
  19. import com.google.android.gms.ads.AdRequest;
  20. import com.google.android.gms.ads.AdView;
  21. import com.google.android.gms.ads.InterstitialAd;
  22. import com.google.android.gms.ads.MobileAds;
  23. import com.google.android.gms.ads.reward.RewardItem;
  24. import com.google.android.gms.ads.reward.RewardedVideoAd;
  25. import com.google.android.gms.ads.reward.RewardedVideoAdListener;
  26.  
  27. import java.util.*;
  28. import java.text.*;
  29.  
  30.  
  31. public class GameActivity extends Activity implements RewardedVideoAdListener {
  32.  
  33. private LinearLayout linear1;
  34. private LinearLayout linear4;
  35. private LinearLayout linear5;
  36. private LinearLayout linear6;
  37. private LinearLayout linear2;
  38. private LinearLayout linear3;
  39. private LinearLayout linear7;
  40. private LinearLayout linear8;
  41. private TextView textview1;
  42. private TextView monkey;
  43. private TextView score;
  44. private TextView lives;
  45. private TextView deco1;
  46. private Button mole1;
  47. private Button mole2;
  48. private Button mole3;
  49. private Button mole4;
  50. private Button mole5;
  51. private Button mole6;
  52. private TextView deco2;
  53. private TextView notify;
  54. private Button video_life;
  55.  
  56. private double speed = 0;
  57. private double random = 0;
  58. private String mole = "";
  59. private double scoreValue = 0;
  60. private double life = 0;
  61. private String lifeString = "";
  62. private double hideSpeed = 0;
  63. private double level = 0;
  64. private double threshold = 0;
  65. private double blinkSpeed = 0;
  66. private double defaultSpeed = 0;
  67. private double defaultHideSpeed = 0;
  68. private double hideThreshold = 0;
  69.  
  70. private ArrayList<String> moleList = new ArrayList<String>();
  71.  
  72. private Timer _timer = new Timer();
  73. private TimerTask timer1;
  74. private TimerTask temp;
  75. private MediaPlayer music;
  76. private AlertDialog.Builder dialog;
  77. private Intent i = new Intent();
  78.  
  79. //Ad variables
  80. private AdView mAdView;
  81. private RewardedVideoAd mRewardedVideoAd;
  82.  
  83.  
  84. @Override
  85. protected void onCreate(Bundle savedInstanceState) {
  86. super.onCreate(savedInstanceState);
  87. setContentView(R.layout.game);
  88.  
  89. //Start ad process
  90. MobileAds.initialize(this,
  91. "ca-app-pub-3940256099942544~3347511713");//TODO this
  92.  
  93. //Insert ad in game banner
  94. mAdView = (AdView) findViewById(R.id.adView);
  95. AdRequest adRequest = new AdRequest.Builder().build();
  96. mAdView.loadAd(adRequest);
  97.  
  98. //Get reward video ad
  99. mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
  100. mRewardedVideoAd.setRewardedVideoAdListener(this);
  101. loadRewardedVideoAd();
  102.  
  103. initialize();
  104. initializeLogic();
  105. }
  106.  
  107. private void initialize() {
  108. linear1 = (LinearLayout) findViewById(R.id.linear1);
  109. linear4 = (LinearLayout) findViewById(R.id.linear4);
  110. linear5 = (LinearLayout) findViewById(R.id.linear5);
  111. linear6 = (LinearLayout) findViewById(R.id.linear6);
  112. linear2 = (LinearLayout) findViewById(R.id.linear2);
  113. linear3 = (LinearLayout) findViewById(R.id.linear3);
  114. linear7 = (LinearLayout) findViewById(R.id.linear7);
  115. linear8 = (LinearLayout) findViewById(R.id.linear8);
  116. textview1 = (TextView) findViewById(R.id.textview1);
  117. monkey = (TextView) findViewById(R.id.monkey);
  118. score = (TextView) findViewById(R.id.score);
  119. lives = (TextView) findViewById(R.id.lives);
  120. deco1 = (TextView) findViewById(R.id.deco1);
  121. mole1 = (Button) findViewById(R.id.mole1);
  122. mole2 = (Button) findViewById(R.id.mole2);
  123. mole3 = (Button) findViewById(R.id.mole3);
  124. mole4 = (Button) findViewById(R.id.mole4);
  125. mole5 = (Button) findViewById(R.id.mole5);
  126. mole6 = (Button) findViewById(R.id.mole6);
  127. deco2 = (TextView) findViewById(R.id.deco2);
  128. notify = (TextView) findViewById(R.id.notify);
  129. video_life = (Button) findViewById(R.id.video_life);
  130.  
  131.  
  132.  
  133.  
  134. dialog = new AlertDialog.Builder(this);
  135.  
  136. video_life.setOnClickListener(new View.OnClickListener() {
  137. @Override
  138. public void onClick(View _v) {
  139. if (mRewardedVideoAd.isLoaded()) {
  140. mRewardedVideoAd.show();
  141. }
  142. }
  143. });
  144.  
  145. mole1.setOnClickListener(new View.OnClickListener() {
  146. @Override
  147. public void onClick(View _v) {
  148. if (mole1.getText().toString().equals("šŸ™Š")) {
  149. scoreValue++;
  150. }
  151. if (mole1.getText().toString().equals("šŸ™‰")) {
  152. scoreValue++;
  153. }
  154. if (mole1.getText().toString().equals("šŸ™ˆ")) {
  155. scoreValue++;
  156. }
  157. if (mole1.getText().toString().equals("šŸ’£")) {
  158. life--;
  159. showMessage("Owie!\nā¤ - 1");
  160. }
  161. if (mole1.getText().toString().equals("ā¤")) {
  162. life++;
  163. showMessage("ā¤ + 1");
  164. }
  165. if (mole1.getText().toString().equals("šŸ•›")) {
  166. showMessage("Speed Reset šŸ•›");
  167. speed = defaultSpeed;
  168. hideSpeed = defaultHideSpeed;
  169. }
  170. mole1.setEnabled(false);
  171. _updateScore();
  172. }
  173. });
  174. mole2.setOnClickListener(new View.OnClickListener() {
  175. @Override
  176. public void onClick(View _v) {
  177. if (mole2.getText().toString().equals("šŸ™Š")) {
  178. scoreValue++;
  179. }
  180. if (mole2.getText().toString().equals("šŸ™‰")) {
  181. scoreValue++;
  182. }
  183. if (mole2.getText().toString().equals("šŸ™ˆ")) {
  184. scoreValue++;
  185. }
  186. if (mole2.getText().toString().equals("šŸ’£")) {
  187. life--;
  188. showMessage("Owie!\nā¤ - 1");
  189. }
  190. if (mole2.getText().toString().equals("ā¤")) {
  191. life++;
  192. showMessage("ā¤ + 1");
  193. }
  194. if (mole2.getText().toString().equals("šŸ•›")) {
  195. showMessage("Speed Reset šŸ•›");
  196. speed = defaultSpeed;
  197. hideSpeed = defaultHideSpeed;
  198. }
  199. mole2.setEnabled(false);
  200. _updateScore();
  201. }
  202. });
  203. mole3.setOnClickListener(new View.OnClickListener() {
  204. @Override
  205. public void onClick(View _v) {
  206. if (mole3.getText().toString().equals("šŸ™Š")) {
  207. scoreValue++;
  208. }
  209. if (mole3.getText().toString().equals("šŸ™‰")) {
  210. scoreValue++;
  211. }
  212. if (mole3.getText().toString().equals("šŸ™ˆ")) {
  213. scoreValue++;
  214. }
  215. if (mole3.getText().toString().equals("šŸ’£")) {
  216. life--;
  217. showMessage("Owie!\nā¤ - 1");
  218. }
  219. if (mole3.getText().toString().equals("ā¤")) {
  220. life++;
  221. showMessage("ā¤ + 1");
  222. }
  223. if (mole3.getText().toString().equals("šŸ•›")) {
  224. showMessage("Speed Reset šŸ•›");
  225. speed = defaultSpeed;
  226. hideSpeed = defaultHideSpeed;
  227. }
  228. mole3.setEnabled(false);
  229. _updateScore();
  230. }
  231. });
  232. mole4.setOnClickListener(new View.OnClickListener() {
  233. @Override
  234. public void onClick(View _v) {
  235. if (mole4.getText().toString().equals("šŸ™Š")) {
  236. scoreValue++;
  237. }
  238. if (mole4.getText().toString().equals("šŸ™‰")) {
  239. scoreValue++;
  240. }
  241. if (mole4.getText().toString().equals("šŸ™ˆ")) {
  242. scoreValue++;
  243. }
  244. if (mole4.getText().toString().equals("šŸ’£")) {
  245. life--;
  246. showMessage("Owie!\nā¤ - 1");
  247. }
  248. if (mole4.getText().toString().equals("ā¤")) {
  249. life++;
  250. showMessage("ā¤ + 1");
  251. }
  252. if (mole4.getText().toString().equals("šŸ•›")) {
  253. showMessage("Speed Reset šŸ•›");
  254. speed = defaultSpeed;
  255. hideSpeed = defaultHideSpeed;
  256. }
  257. mole4.setEnabled(false);
  258. _updateScore();
  259. }
  260. });
  261. mole5.setOnClickListener(new View.OnClickListener() {
  262. @Override
  263. public void onClick(View _v) {
  264. if (mole5.getText().toString().equals("šŸ™Š")) {
  265. scoreValue++;
  266. }
  267. if (mole5.getText().toString().equals("šŸ™‰")) {
  268. scoreValue++;
  269. }
  270. if (mole5.getText().toString().equals("šŸ™ˆ")) {
  271. scoreValue++;
  272. }
  273. if (mole5.getText().toString().equals("šŸ’£")) {
  274. life--;
  275. showMessage("Owie!\nā¤ - 1");
  276. }
  277. if (mole5.getText().toString().equals("ā¤")) {
  278. life++;
  279. showMessage("ā¤ + 1");
  280. }
  281. if (mole5.getText().toString().equals("šŸ•›")) {
  282. showMessage("Speed Reset šŸ•›");
  283. speed = defaultSpeed;
  284. hideSpeed = defaultHideSpeed;
  285. }
  286. mole5.setEnabled(false);
  287. _updateScore();
  288. }
  289. });
  290. mole6.setOnClickListener(new View.OnClickListener() {
  291. @Override
  292. public void onClick(View _v) {
  293. if (mole6.getText().toString().equals("šŸ™Š")) {
  294. scoreValue++;
  295. }
  296. if (mole6.getText().toString().equals("šŸ™‰")) {
  297. scoreValue++;
  298. }
  299. if (mole6.getText().toString().equals("šŸ™ˆ")) {
  300. scoreValue++;
  301. }
  302. if (mole6.getText().toString().equals("šŸ’£")) {
  303. life--;
  304. showMessage("Owie!\nā¤ - 1");
  305. }
  306. if (mole6.getText().toString().equals("ā¤")) {
  307. life++;
  308. showMessage("ā¤ + 1");
  309. }
  310. if (mole6.getText().toString().equals("šŸ•›")) {
  311. showMessage("Speed Reset šŸ•›");
  312. speed = defaultSpeed;
  313. hideSpeed = defaultHideSpeed;
  314. }
  315. mole6.setEnabled(false);
  316. _updateScore();
  317. }
  318. });
  319.  
  320. }
  321.  
  322. private void initializeLogic() {
  323. music = MediaPlayer.create(getApplicationContext(), R.raw.christophertinbabayetu);
  324. music.start();
  325. music.setLooping(true);
  326. showMessage("Music credits: Christopher Tin - Baba Yetu");
  327. defaultSpeed = 800;
  328. defaultHideSpeed = 700;
  329. speed = defaultSpeed;
  330. hideSpeed = defaultHideSpeed;
  331. life = 3;
  332. threshold = 5;
  333. blinkSpeed = 500;
  334. hideThreshold = 1;
  335. moleList.add("šŸ™ˆ");
  336. moleList.add("šŸ™Š");
  337. moleList.add("šŸ™‰");
  338. monkey.setText("šŸ’ x ");
  339. deco1.setText("šŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒ");
  340. deco2.setText("šŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒšŸŒ");
  341. _showLife();
  342. _generateMoles();
  343. dialog.setTitle("Leaving already?");
  344. dialog.setMessage("Please stay");
  345. dialog.setPositiveButton("Leave", new DialogInterface.OnClickListener() {
  346. @Override
  347. public void onClick(DialogInterface _dialog, int _which) {
  348. i.setClass(getApplicationContext(), MainActivity.class);
  349. i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  350. startActivity(i);
  351. }
  352. });
  353. dialog.setNegativeButton("Stay", new DialogInterface.OnClickListener() {
  354. @Override
  355. public void onClick(DialogInterface _dialog, int _which) {
  356.  
  357. }
  358. });
  359. // ActionBar actionBar = getActionBar(); actionBar.setBackground///Drawable(new android.graphics.drawable.ColorDrawable(Color.parseColor("#FF66BB6A")));
  360.  
  361. //getActionBar().setTitle(Html.fromHtml("<font color='#FFFFFFFF'>'Score' + scoreValue </jenniferlynne>"));
  362. }
  363.  
  364. private void loadRewardedVideoAd() {
  365. mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
  366. new AdRequest.Builder().build());
  367. }
  368.  
  369. @Override
  370. public void onRewarded(RewardItem reward) {
  371. scoreValue++;
  372. }
  373.  
  374. @Override
  375. public void onRewardedVideoAdLeftApplication() {
  376.  
  377. }
  378.  
  379. @Override
  380. public void onRewardedVideoAdClosed() {
  381. // Load the next rewarded video ad.
  382. loadRewardedVideoAd();
  383. }
  384.  
  385. @Override
  386. public void onRewardedVideoAdFailedToLoad(int errorCode) {
  387.  
  388. }
  389.  
  390. @Override
  391. public void onRewardedVideoAdLoaded() {
  392.  
  393. }
  394.  
  395. @Override
  396. public void onRewardedVideoAdOpened() {
  397.  
  398. }
  399.  
  400. @Override
  401. public void onRewardedVideoStarted() {
  402.  
  403. }
  404.  
  405. @Override
  406. public void onRewardedVideoCompleted() {
  407. life++;
  408. showMessage("ā¤ + 1");
  409. }
  410.  
  411. @Override
  412. public void onPause() {
  413. super.onPause();
  414. music.release();
  415. }
  416. @Override
  417. public void onStop() {
  418. super.onStop();
  419. music.release();
  420. }
  421. @Override
  422. public void onDestroy() {
  423. super.onDestroy();
  424. music.release();
  425. }
  426. @Override
  427. public void onBackPressed() {
  428. music.release();
  429. dialog.create().show();
  430. }
  431.  
  432. private void _generateMoles () {
  433. timer1 = new TimerTask() {
  434. @Override
  435. public void run() {
  436. runOnUiThread(new Runnable() {
  437. @Override
  438. public void run() {
  439. random = getRandom((int)(1), (int)(6));
  440. _viewMole(random);
  441. temp = new TimerTask() {
  442. @Override
  443. public void run() {
  444. runOnUiThread(new Runnable() {
  445. @Override
  446. public void run() {
  447. _hideMole(random);
  448. }
  449. });
  450. }
  451. };
  452. _timer.schedule(temp, (int)(hideSpeed));
  453. }
  454. });
  455. }
  456. };
  457. _timer.scheduleAtFixedRate(timer1, (int)(1000), (int)(speed));
  458. }
  459. private void _viewMole (final double _index) {
  460. mole = moleList.get((int)(getRandom((int)(0), (int)(moleList.size() - 1))));
  461. if (getRandom((int)(0), (int)(10)) < 3) {
  462. mole = "šŸ’£";
  463. }
  464. if (getRandom((int)(0), (int)(10)) < 1) {
  465. mole = "ā¤";
  466. }
  467. if (getRandom((int)(0), (int)(100)) < 5) {
  468. mole = "šŸ•›";
  469. }
  470. if (_index == 1) {
  471. mole1.setText(mole);
  472. mole1.setEnabled(true);
  473. }
  474. if (_index == 2) {
  475. mole2.setText(mole);
  476. mole2.setEnabled(true);
  477. }
  478. if (_index == 3) {
  479. mole3.setText(mole);
  480. mole3.setEnabled(true);
  481. }
  482. if (_index == 4) {
  483. mole4.setText(mole);
  484. mole4.setEnabled(true);
  485. }
  486. if (_index == 5) {
  487. mole5.setText(mole);
  488. mole5.setEnabled(true);
  489. }
  490. if (_index == 6) {
  491. mole6.setText(mole);
  492. mole6.setEnabled(true);
  493. }
  494. }
  495. private void _hideMole (final double _index) {
  496. if (_index == 1) {
  497. mole1.setText("ā—");
  498. mole1.setEnabled(false);
  499. }
  500. if (_index == 2) {
  501. mole2.setText("ā—");
  502. mole2.setEnabled(false);
  503. }
  504. if (_index == 3) {
  505. mole3.setText("ā—");
  506. mole3.setEnabled(false);
  507. }
  508. if (_index == 4) {
  509. mole4.setText("ā—");
  510. mole4.setEnabled(false);
  511. }
  512. if (_index == 5) {
  513. mole5.setText("ā—");
  514. mole5.setEnabled(false);
  515. }
  516. if (_index == 6) {
  517. mole6.setText("ā—");
  518. mole6.setEnabled(false);
  519. }
  520. }
  521. private void _showLife () {
  522. lifeString = "";
  523. if (life > 5) {
  524. lifeString = "ā¤ x ".concat(String.valueOf((long)(life)));
  525. }
  526. else {
  527. for(int _repeat10 = 0; _repeat10 < (int)(life); _repeat10++) {
  528. lifeString = lifeString.concat("ā¤ ");
  529. }
  530. }
  531. lives.setText(lifeString);
  532. }
  533. private void _updateScore () {
  534. _showLife();
  535. score.setText(String.valueOf((long)(scoreValue)));
  536. if (level < (scoreValue / 5)) {
  537. _notifyUser("Speed Up!!");
  538. }
  539. level = scoreValue / 5;
  540. speed = speed - (level * threshold);
  541. hideSpeed = hideSpeed - (level * hideThreshold);
  542. _checkGameOver();
  543. }
  544. private void _checkGameOver () {
  545. if (life == 0) {
  546. showMessage("Game Over\nPress back to try again!");
  547. timer1.cancel();
  548. }
  549. }
  550. private void _notifyUser (final String _message) {
  551. notify.setText(_message);
  552. temp = new TimerTask() {
  553. @Override
  554. public void run() {
  555. runOnUiThread(new Runnable() {
  556. @Override
  557. public void run() {
  558. notify.setVisibility(View.INVISIBLE);
  559. }
  560. });
  561. }
  562. };
  563. _timer.schedule(temp, (int)(blinkSpeed * 1));
  564. temp = new TimerTask() {
  565. @Override
  566. public void run() {
  567. runOnUiThread(new Runnable() {
  568. @Override
  569. public void run() {
  570. notify.setVisibility(View.VISIBLE);
  571. }
  572. });
  573. }
  574. };
  575. _timer.schedule(temp, (int)(blinkSpeed * 2));
  576. temp = new TimerTask() {
  577. @Override
  578. public void run() {
  579. runOnUiThread(new Runnable() {
  580. @Override
  581. public void run() {
  582. notify.setVisibility(View.INVISIBLE);
  583. }
  584. });
  585. }
  586. };
  587. _timer.schedule(temp, (int)(blinkSpeed * 3));
  588. temp = new TimerTask() {
  589. @Override
  590. public void run() {
  591. runOnUiThread(new Runnable() {
  592. @Override
  593. public void run() {
  594. notify.setVisibility(View.VISIBLE);
  595. }
  596. });
  597. }
  598. };
  599. _timer.schedule(temp, (int)(blinkSpeed * 4));
  600. temp = new TimerTask() {
  601. @Override
  602. public void run() {
  603. runOnUiThread(new Runnable() {
  604. @Override
  605. public void run() {
  606. notify.setVisibility(View.INVISIBLE);
  607. }
  608. });
  609. }
  610. };
  611. _timer.schedule(temp, (int)(blinkSpeed * 5));
  612. }
  613.  
  614.  
  615.  
  616.  
  617. // created automatically
  618. private void showMessage(String _s) {
  619. Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
  620. }
  621.  
  622. private int getLocationX(View _v) {
  623. int _location[] = new int[2];
  624. _v.getLocationInWindow(_location);
  625. return _location[0];
  626. }
  627.  
  628. private int getLocationY(View _v) {
  629. int _location[] = new int[2];
  630. _v.getLocationInWindow(_location);
  631. return _location[1];
  632. }
  633.  
  634. private int getRandom(int _minValue ,int _maxValue){
  635. Random random = new Random();
  636. return random.nextInt(_maxValue - _minValue + 1) + _minValue;
  637. }
  638.  
  639. public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
  640. ArrayList<Double> _result = new ArrayList<Double>();
  641. SparseBooleanArray _arr = _list.getCheckedItemPositions();
  642. for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
  643. if (_arr.valueAt(_iIdx))
  644. _result.add((double)_arr.keyAt(_iIdx));
  645. }
  646. return _result;
  647. }
  648.  
  649. private float getDip(int _input){
  650. return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
  651. }
  652.  
  653. private int getDisplayWidthPixels(){
  654. return getResources().getDisplayMetrics().widthPixels;
  655. }
  656.  
  657. private int getDisplayHeightPixels(){
  658. return getResources().getDisplayMetrics().heightPixels;
  659. }
  660.  
  661.  
  662. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement