6.1. Introduction

The Cannon Game app challenges you to destroy a seven-piece target before a ten-second time limit expires (Fig. 6.1). The game consists of four visual components—a cannon that you control, a cannonball, the target and a blocker that defends the target. You aim and fire the cannon by touching the screen—the cannon then aims at the touched point and fires the cannonball in a straight line in that direction. At the end of the game, the app displays an AlertDialog indicating whether you won or lost, and showing the number of shots fired and the elapsed time (Fig. 6.2).

Image

Fig. 6.1 | Completed Cannon Game app.

Image

a) AlertDialog displayed after user destroys all seven target sections

Image

b) AlertDialog displayed when game ends before user destroys all seven target sections

Fig. 6.2 | Cannon Game app AlertDialogs showing a win and a loss.

The game begins with a 10-second time limit. Each time you destroy a target section, a three-second time bonus is added to your remaining time, and each time you hit the blocker, a two-second time penalty is subtracted from your remaining time. You win by destroying all seven target sections before you run out of time—if the timer reaches zero, you lose.

When you fire the cannon, the game plays a firing sound. When a cannonball hits a target piece, a glass-breaking sound plays and that piece of the target disappears. When the cannonball hits the blocker, a hit sound plays and the cannonball bounces back. The blocker cannot be destroyed. The target and blocker move vertically at different speeds, changing direction when they hit the top or bottom of the screen.

[Note: Due to performance issues with the Android Emulator, you should test this app on an Android device.]

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset