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 : Monster Game

Monster eating animals
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:id="@+id/bgnature"
android:background="@android:color/transparent"

android:scaleType="fitXY"
android:src="@drawable/backnautre"
/>


<pl.droidsonroids.gif.GifImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/animals0"
android:scaleType="fitCenter"
android:background="@android:color/transparent"
android:src="@drawable/animal1"
/>

<pl.droidsonroids.gif.GifImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/animals1"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/animal2"
/>

<pl.droidsonroids.gif.GifImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/animals2"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/animal3"
/>
<pl.droidsonroids.gif.GifImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/monster"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/monster"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scoremonster"
android:fontFamily="cursive"
android:textSize="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scaped"

android:fontFamily="cursive"
android:textSize="20dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

2.Java


public class gamesMonster extends AppCompatActivity implements View.OnClickListener {
ImageView[]animaux=new ImageView[3];
ImageView bgnautre,monster;
TextView scoremonster,scaped;
CountDownTimer interval;
int x1=0,x2=0,x3=0;
int tiger=0;
int autriche=0;
int bison=0;
int scapedScore=0;
float xmonster=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_games_monster);
animaux[0]=findViewById(R.id.animals0);
animaux[1]=findViewById(R.id.animals1);
animaux[2]=findViewById(R.id.animals2);
bgnautre=findViewById(R.id.bgnature);
monster=findViewById(R.id.monster);
scoremonster=findViewById(R.id.scoremonster);
scaped=findViewById(R.id.scaped);
scaped.setX(550);
//ecoutez les animaux
int a=0;
for(int i=0;i<3;i++)
{
animaux[i].setOnClickListener(this);
animaux[i].setY(a);
a+=425;
}
float x=(float)(Math.random()*bgnautre.getWidth());
monster.setX(x);
interval=new CountDownTimer(10000000,50) {
@Override
public void onTick(long l) {
x1+=10;
x2+=15;
x3+=20;
//xmonster-=10;
//monster.setX(xmonster);
if(x1>bgnautre.getWidth())
{
scapedScore++;
scaped.setText("Scaped: "+scapedScore);
x1=-50;
float y=(float)(Math.random()*bgnautre.getHeight());
animaux[0].setY(y);
}
if(x2>bgnautre.getWidth())
{
scapedScore++;
scaped.setText("Scaped: "+scapedScore);
x2=-50;
float y=(float)(Math.random()*bgnautre.getHeight());
animaux[1].setY(y);
}
if(x3>bgnautre.getWidth())
{
x3=-50;
float y=(float)(Math.random()*bgnautre.getHeight());
animaux[2].setY(y);
scapedScore++;
scaped.setText("Scaped:"+scapedScore);
}
animaux[0].setX(x1);
animaux[1].setX(x2);
animaux[2].setX(x3);
}
@Override
public void onFinish() {
}
}.start();
}
@Override
public void onClick(View view) {
int[] values = new int[2];
view.getLocationOnScreen(values);
monster.setY(values[1]-150);
monster.setX(values[0]+150);
if(view.getId()==animaux[0].getId())
{
bison++;
x1=-200;
float y=(float)(Math.random()*bgnautre.getHeight());
animaux[0].setY(y);
}
if(view.getId()==animaux[1].getId())
{
tiger++;
x2=-200;
float y=(float)(Math.random()*bgnautre.getHeight());
animaux[1].setY(y);
}
if(view.getId()==animaux[2].getId())
{
autriche++;
x3=-200;
float y=(float)(Math.random()*bgnautre.getHeight());
animaux[2].setY(y);
}
scoremonster.setText("Tiger: "+tiger+"\n Autriche : "+autriche+"\n Bison :"+bison);
scaped.setTextColor(Color.RED);
}
}