Question
public class RabbitGameActivity extends AppCompatActivity implements View.OnClickListener { //used to store the width and height of the screen int width, height, score; @Override protected void
public class RabbitGameActivity extends AppCompatActivity implements View.OnClickListener {
//used to store the width and height of the screen
int width, height, score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rabbit_game);
//getting the button - make sure you named your button!
buttonRabbit = (ImageButton) findViewById(R.id.buttonRabbit);
//get the displays height and width to know where to put the rabbit
DisplayMetrics display = getResources().getDisplayMetrics();
width = display.widthPixels;
height = display.heightPixels;
package com.example.kathykanemoto.project1_gettingrabbittowork;
Log.d("width ", "" + width);
Log.d("height", "" + height);
//adding a click listener event to the button
buttonRabbit.setOnClickListener(this);
//set the score to 0
score = 0;
TextView txtScore = (TextView)findViewById(R.id.txtScore);
txtScore.setText("");
}//end onCreate
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonRabbit:
break;
}
}//end onClick
//move the rabbit off of the screen
buttonRabbit.setX(-500);
buttonRabbit.setY(-500);
score++; //up the score
mediaPlayer.start(); //play the rabbit noise
//set the score
TextView txtScore = (TextView)findViewById(R.id.txtScore);
txtScore.setText("Score: " + score);
}//end class
default:
break;
}.start();
public void onFinish() {
}
CountDownTimer startRabbitHoppingAround = new CountDownTimer(26000, 1000) {
public void onTick(long millisUntilFinished) {
//every second move the rabbit
//put the rabbit at a random place on the screen
int xPos = (int)(Math.random() * width) - 72 * 2;
buttonRabbit.setX(xPos);
int yPos = (int)(Math.random() * height) - 99 * 2;
buttonRabbit.setY(yPos);
}
mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.rabbit);
MediaPlayer stopWatchSound = MediaPlayer.create(getApplicationContext(), R.raw.watch);
stopWatchSound.start();
//put the rabbit at a random place on the screen
int xPos = (int)(Math.random() * width) - 72 * 2;
buttonRabbit.setX(xPos);
Log.d("xPos ", "" + xPos);
Log.d("yPos", "" + yPos);
int yPos = (int)(Math.random() * height) - 99 * 2;
buttonRabbit.setY(yPos);
//setting the orientation to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
//create an attribute of our buttonPlay
private ImageButton buttonRabbit;
MediaPlayer mediaPlayer;
Button btnSaveHighScore;
I need to rearrange this code in the right order for AndroidStudio so that it works properly. I'm new to AndroidStudio, so I need help as soon as possible.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started