Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.brothers.cailles.spotthecage;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.os.CountDownTimer;
- import android.util.Log;
- import android.widget.ImageView;
- import android.widget.TextView;
- import com.github.chrisbanes.photoview.OnPhotoTapListener;
- import com.github.chrisbanes.photoview.PhotoView;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.lang.Math;
- import java.util.Set;
- /**
- * Created by solal vallee on 20/03/2017.
- */
- public class cageActivity extends Activity {
- //private double[][] nicolasPosition = new double[][]{{0.34, 0.365, 0.54, 0.60}, {0.20, 0.23, 0.52, 0.57}};
- //private int[] picturesNicolas = new int[]{R.drawable.cageee, R.drawable.cage2, R.drawable.cage3};
- //ArrayList 2 Dimension pour les positions de nicolas cage
- private ArrayList<List<Double>> nicolasPosition = new ArrayList<List<Double>>();
- private ArrayList<Integer> picturesNicolas = new ArrayList<Integer>();
- public static String scoreFile = "sharedFile";
- SharedPreferences dataTransfer;
- int compteurImage = 0;
- private int randomChoice = 0;
- private int compteurTouch = 0;
- private int compteurGame = 120;
- private int level = 0;
- CountDownTimer myTimerGame = new CountDownTimer(300000,1000) {
- public void onTick ( long millisUntilFinished) {
- compteurGame -= 1;
- TextView myText = (TextView) findViewById(R.id.textView2);
- myText.setText(String.format(String.valueOf(compteurGame)));
- }
- public void onFinish(){
- Intent MainActivity = new Intent(cageActivity.this,MainActivity.class);
- startActivity(MainActivity);
- }
- }.start();
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.cage1);
- dataTransfer = getSharedPreferences(scoreFile, Context.MODE_PRIVATE);
- picturesNicolas.add(R.drawable.cageee);
- picturesNicolas.add(R.drawable.cage2);
- picturesNicolas.add(R.drawable.cage3);
- //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
- nicolasPosition.add(0, (List<Double>) Arrays.asList(0.34, 0.365, 0.54, 0.60));
- nicolasPosition.add(1, (List<Double>) Arrays.asList(0.20, 0.23, 0.52, 0.57));
- nicolasPosition.add(2, (List<Double>) Arrays.asList(0.32, 0.38, 0.0, 0.15));
- //Random image de nicolas au lamcement du jeu (lors du click sur play)
- randomChoice = (int) (Math.random() * nicolasPosition.size());
- Log.d("Taille du tableau ",Float.toString(picturesNicolas.size()));
- PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
- photoView.setImageResource(picturesNicolas.get(randomChoice));
- Log.d("random number first: ",Float.toString(randomChoice));
- TextView levelText = (TextView) findViewById(R.id.textView3);
- levelText.setText("Level : " + level);
- photoView.setOnPhotoTapListener(test);
- }
- OnPhotoTapListener test = new OnPhotoTapListener() {
- @Override
- public void onPhotoTap(ImageView view, float x, float y) {
- final AlertDialog.Builder customAlert = new AlertDialog.Builder(cageActivity.this);
- CountDownTimer myTimerTouch = new CountDownTimer(2000,1000) {
- public void onTick ( long millisUntilFinished){
- compteurTouch = 1;
- }
- public void onFinish() {
- compteurTouch = 0;
- }
- }.start();
- /*-----------------TEST----------------------------
- Log.d("click : ", Float.toString(compteurTouch));
- Log.d("x : ", Float.toString(x/1000));
- Log.d("y : ", Float.toString(y/1000));
- Double c = nicolasPosition.get(randomChoice).get(0);
- Log.d("X1 : ", Double.toString(c));
- */
- //--------------------------------------------------
- TextView myText = (TextView) findViewById(R.id.textView);
- myText.setText(" X : " + Double.toString(Math.round(x*100)/100d) + " Y : " + Double.toString(Math.round(y*100)/100d));
- if(compteurTouch == 0 ){
- 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))) {
- if(picturesNicolas.size() == 1){
- myTimerGame.cancel();
- level += 1;
- TextView levelText = (TextView) findViewById(R.id.textView3);
- levelText.setText("Level : " + level);
- customAlert.setMessage("AND YOU FIND : " + level + " Nicolas").create();
- customAlert.show();
- }
- else{
- picturesNicolas.remove(picturesNicolas.get(randomChoice));
- nicolasPosition.remove(randomChoice);
- randomChoice = (int) (Math.random() * nicolasPosition.size());
- level +=1;
- if(level == 1) {
- PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
- photoView.setImageResource(picturesNicolas.get(randomChoice));
- compteurGame = 100;
- }
- if(level == 2) {
- PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
- photoView.setImageResource(picturesNicolas.get(randomChoice));
- compteurGame = 80;
- }
- TextView levelText = (TextView) findViewById(R.id.textView3);
- levelText.setText("Level : " + level);
- }
- }
- }
- else {
- customAlert.setMessage("DON'T CHEAT, WAIT BEFORE CLICK AGAIN..").create();
- customAlert.show();
- }
- }
- };
- /*
- public void save(){
- //On dit ici que le fichier scoreFile est prive a l'application et que ce sera ce fichier ou seront stockes les data
- //Object qui autorise l'edition de ce fichier
- SharedPreferences.Editor editFile = dataTransfer.edit();
- //On ajoute notre score du compteur a notre fichier dans la variable score
- editFile.putInt("score", compteurGame);
- editFile.commit();
- //creer lien avec notre activite hall of fame
- //Intent hallOfFame = new Intent(cageActivity.this,HallFame.class);
- //on demmare directement notre activity
- //startActivity(hallOfFame);
- }
- */
- /*public void onTouch
- OnTouchListener monTouch = PhotoView.OnTouchListener() {
- @Override
- public boolean onTouch(PhotoView view, MotionEvent event) {
- float eventX = event.getX();
- float eventY = event.getY();
- float[] eventXY = new float[]{eventX, eventY};
- String x = Float.toString(eventX);
- String y = Float.toString(eventY);
- //monTexte.setText(test);
- monTexteX.setText(" X : "+x+" Y : " +y);
- }};*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement