Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago