Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.62 KB | None | 0 0
  1. package com.brothers.cailles.spotthecage;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.SharedPreferences;
  8. import android.os.Bundle;
  9. import android.os.CountDownTimer;
  10. import android.util.Log;
  11. import android.widget.ImageView;
  12. import android.widget.TextView;
  13.  
  14. import com.github.chrisbanes.photoview.OnPhotoTapListener;
  15. import com.github.chrisbanes.photoview.PhotoView;
  16.  
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. import java.lang.Math;
  21. import java.util.Set;
  22.  
  23.  
  24. /**
  25. * Created by solal vallee on 20/03/2017.
  26. */
  27.  
  28. public class cageActivity extends Activity {
  29.  
  30. //private double[][] nicolasPosition = new double[][]{{0.34, 0.365, 0.54, 0.60}, {0.20, 0.23, 0.52, 0.57}};
  31. //private int[] picturesNicolas = new int[]{R.drawable.cageee, R.drawable.cage2, R.drawable.cage3};
  32.  
  33. //ArrayList 2 Dimension pour les positions de nicolas cage
  34. private ArrayList<List<Double>> nicolasPosition = new ArrayList<List<Double>>();
  35. private ArrayList<Integer> picturesNicolas = new ArrayList<Integer>();
  36.  
  37. public static String scoreFile = "sharedFile";
  38. SharedPreferences dataTransfer;
  39.  
  40. int compteurImage = 0;
  41. private int randomChoice = 0;
  42. private int compteurTouch = 0;
  43. private int compteurGame = 120;
  44. private int level = 0;
  45.  
  46. CountDownTimer myTimerGame = new CountDownTimer(300000,1000) {
  47.  
  48. public void onTick ( long millisUntilFinished) {
  49. compteurGame -= 1;
  50. TextView myText = (TextView) findViewById(R.id.textView2);
  51. myText.setText(String.format(String.valueOf(compteurGame)));
  52. }
  53.  
  54. public void onFinish(){
  55. Intent MainActivity = new Intent(cageActivity.this,MainActivity.class);
  56. startActivity(MainActivity);
  57. }
  58. }.start();
  59.  
  60.  
  61. protected void onCreate(Bundle savedInstanceState) {
  62. super.onCreate(savedInstanceState);
  63. setContentView(R.layout.cage1);
  64.  
  65. dataTransfer = getSharedPreferences(scoreFile, Context.MODE_PRIVATE);
  66.  
  67. picturesNicolas.add(R.drawable.cageee);
  68. picturesNicolas.add(R.drawable.cage2);
  69. picturesNicolas.add(R.drawable.cage3);
  70.  
  71. //j'ajoute a l'index tant les differentes positions x et y de la tete de nicolas qui sont cast en tant que list de double
  72. nicolasPosition.add(0, (List<Double>) Arrays.asList(0.34, 0.365, 0.54, 0.60));
  73. nicolasPosition.add(1, (List<Double>) Arrays.asList(0.20, 0.23, 0.52, 0.57));
  74. nicolasPosition.add(2, (List<Double>) Arrays.asList(0.32, 0.38, 0.0, 0.15));
  75.  
  76. //Random image de nicolas au lamcement du jeu (lors du click sur play)
  77. randomChoice = (int) (Math.random() * nicolasPosition.size());
  78.  
  79. Log.d("Taille du tableau ",Float.toString(picturesNicolas.size()));
  80.  
  81.  
  82. PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
  83. photoView.setImageResource(picturesNicolas.get(randomChoice));
  84. Log.d("random number first: ",Float.toString(randomChoice));
  85.  
  86. TextView levelText = (TextView) findViewById(R.id.textView3);
  87. levelText.setText("Level : " + level);
  88.  
  89. photoView.setOnPhotoTapListener(test);
  90. }
  91.  
  92.  
  93. OnPhotoTapListener test = new OnPhotoTapListener() {
  94. @Override
  95. public void onPhotoTap(ImageView view, float x, float y) {
  96.  
  97. final AlertDialog.Builder customAlert = new AlertDialog.Builder(cageActivity.this);
  98.  
  99. CountDownTimer myTimerTouch = new CountDownTimer(2000,1000) {
  100.  
  101. public void onTick ( long millisUntilFinished){
  102. compteurTouch = 1;
  103. }
  104.  
  105. public void onFinish() {
  106. compteurTouch = 0;
  107. }
  108. }.start();
  109.  
  110. /*-----------------TEST----------------------------
  111. Log.d("click : ", Float.toString(compteurTouch));
  112.  
  113. Log.d("x : ", Float.toString(x/1000));
  114. Log.d("y : ", Float.toString(y/1000));
  115.  
  116. Double c = nicolasPosition.get(randomChoice).get(0);
  117. Log.d("X1 : ", Double.toString(c));
  118. */
  119. //--------------------------------------------------
  120.  
  121. TextView myText = (TextView) findViewById(R.id.textView);
  122. myText.setText(" X : " + Double.toString(Math.round(x*100)/100d) + " Y : " + Double.toString(Math.round(y*100)/100d));
  123.  
  124. if(compteurTouch == 0 ){
  125. if ((x > nicolasPosition.get(randomChoice).get(0) && x < nicolasPosition.get(randomChoice).get(1)) && (y > nicolasPosition.get(randomChoice).get(2) && y < nicolasPosition.get(randomChoice).get(3))) {
  126.  
  127. if(picturesNicolas.size() == 1){
  128. myTimerGame.cancel();
  129.  
  130. level += 1;
  131. TextView levelText = (TextView) findViewById(R.id.textView3);
  132. levelText.setText("Level : " + level);
  133.  
  134. customAlert.setMessage("AND YOU FIND : " + level + " Nicolas").create();
  135. customAlert.show();
  136.  
  137. }
  138. else{
  139. picturesNicolas.remove(picturesNicolas.get(randomChoice));
  140. nicolasPosition.remove(randomChoice);
  141. randomChoice = (int) (Math.random() * nicolasPosition.size());
  142.  
  143.  
  144. level +=1;
  145.  
  146. if(level == 1) {
  147. PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
  148. photoView.setImageResource(picturesNicolas.get(randomChoice));
  149.  
  150. compteurGame = 100;
  151. }
  152. if(level == 2) {
  153. PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
  154. photoView.setImageResource(picturesNicolas.get(randomChoice));
  155.  
  156. compteurGame = 80;
  157. }
  158.  
  159. TextView levelText = (TextView) findViewById(R.id.textView3);
  160. levelText.setText("Level : " + level);
  161.  
  162. }
  163.  
  164. }
  165. }
  166. else {
  167. customAlert.setMessage("DON'T CHEAT, WAIT BEFORE CLICK AGAIN..").create();
  168. customAlert.show();
  169. }
  170. }
  171. };
  172.  
  173. /*
  174. public void save(){
  175. //On dit ici que le fichier scoreFile est prive a l'application et que ce sera ce fichier ou seront stockes les data
  176.  
  177. //Object qui autorise l'edition de ce fichier
  178. SharedPreferences.Editor editFile = dataTransfer.edit();
  179.  
  180. //On ajoute notre score du compteur a notre fichier dans la variable score
  181. editFile.putInt("score", compteurGame);
  182. editFile.commit();
  183.  
  184. //creer lien avec notre activite hall of fame
  185. //Intent hallOfFame = new Intent(cageActivity.this,HallFame.class);
  186.  
  187. //on demmare directement notre activity
  188. //startActivity(hallOfFame);
  189. }
  190. */
  191.  
  192.  
  193.  
  194. /*public void onTouch
  195. OnTouchListener monTouch = PhotoView.OnTouchListener() {
  196.  
  197. @Override
  198. public boolean onTouch(PhotoView view, MotionEvent event) {
  199. float eventX = event.getX();
  200. float eventY = event.getY();
  201. float[] eventXY = new float[]{eventX, eventY};
  202. String x = Float.toString(eventX);
  203. String y = Float.toString(eventY);
  204.  
  205. //monTexte.setText(test);
  206. monTexteX.setText(" X : "+x+" Y : " +y);
  207. }};*/
  208.  
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement