menu FixWins.com Spring MVC Spring Boot NodeJS+ExpressJS+Mysql ReactJS+NodeJS+Mysql ReactJS+Redux :CRUD Android PFE
Spring MVC Spring Boot NodeJS+ExpressJS+Mysql ReactJS+NodeJS+Mysql ReactJS+Redux :CRUD PFE

Android : Game Eagle hunter

Créer une application qui permet de chasser un Eagle
il faut ajouter des images gif et des sons mp3 et aussi les dépendances du gif dans le fichier build.gradle

1.Layout

<pl.droidsonroids.gif.GifImageButton

android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/figbg"
android:id="@+id/bgbirds"
android:background="@android:color/transparent"
/>

<pl.droidsonroids.gif.GifImageButton
android:layout_marginTop="150dp"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="fitXY"
android:src="@drawable/bbirds"
android:id="@+id/birdsid"
android:background="@android:color/transparent"
/>

<pl.droidsonroids.gif.GifImageButton
android:layout_marginTop="250dp"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="fitXY"
android:src="@drawable/bbirds"
android:id="@+id/birdsid2"
android:background="@android:color/transparent"
/>

<pl.droidsonroids.gif.GifImageButton
android:layout_marginTop="450dp"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="fitXY"
android:src="@drawable/bbirds"
android:id="@+id/birdsid3"
android:background="@android:color/transparent"
/>
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/scores"
android:text="0"
android:textSize="30dp"/>

2.Java


import androidx.appcompat.app.AppCompatActivity;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Birds extends AppCompatActivity implements View.OnClickListener{
ImageView birds[]=new ImageView[3];
ImageView bgbirds;
TextView scores;
float x1=10,y1=0,v1=5,v2=3,v3=7;
float x2=100,y2=50;
float x3=200,y3=10;
int score=0;
MediaPlayer player;
Handler handler = new Handler();
CountDownTimer interval;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_birds);
birds[0]=findViewById(R.id.birdsid);
birds[1]=findViewById(R.id.birdsid2);
birds[2]=findViewById(R.id.birdsid3);
bgbirds=findViewById(R.id.bgbirds);
birds[0].setOnClickListener(this);
birds[1].setOnClickListener(this);
birds[2].setOnClickListener(this);
bgbirds.setOnClickListener(this);
scores=findViewById(R.id.scores);
player=MediaPlayer.create( this,R.raw.eagle);
player.start();
interval=new CountDownTimer(100000,25) {
@Override
public void onTick(long l) {
x1+=v1;
birds[0].setX(x1);

x2+=v2;
birds[1].setX(x2);

x3+=v3;
birds[2].setX(x3);

if(x1>bgbirds.getWidth())
{
player.start();
x1=-20;
y1=(int)(Math.random()*bgbirds.getHeight());
birds[0].setY(y1);
birds[0].setRotation(0);
}

if(x2>bgbirds.getWidth())
{
player.start();
x2=-20;
y2=(int)(Math.random()*bgbirds.getHeight());
birds[1].setY(y2);
birds[1].setRotation(0);
}

if(x3>bgbirds.getWidth())
{
player.start();
x3=-20;
y3=(int)(Math.random()*bgbirds.getHeight());
birds[2].setY(y3);
birds[2].setRotation(0);
}


}

@Override
public void onFinish() {

}
}.start();
}

@Override
public void onClick(View view) {
if (bgbirds.getId() == view.getId()) {
score--;
scores.setText(""+score);
} else {

for (int i = 0; i < 3; i++) {
if (view.getId() == birds[i].getId()) {

score++;
scores.setText(""+score);


switch (i)
{
case 0:
birds[0].setRotation((int)(Math.random()*360));
CountDownTimer t1=new CountDownTimer(3000,20) {
@Override
public void onTick(long l) {
y1+=5;
birds[0].setY(y1);
}

@Override
public void onFinish() {

}
}.start();
break;

case 1:birds[1].setRotation((int)(Math.random()*360));
CountDownTimer t2=new CountDownTimer(3000,20) {
@Override
public void onTick(long l) {
y2+=5;
birds[1].setY(y2);
}

@Override
public void onFinish() {

}
}.start();
break;


case 2:birds[2].setRotation((int)(Math.random()*360));
CountDownTimer t3=new CountDownTimer(3000,20) {
@Override
public void onTick(long l) {
y3+=5;
birds[2].setY(y3);
}

@Override
public void onFinish() {

}
}.start();
break;
}
}

}
}

}
}