O'Reilly logo

Android™ How to Program, Second Edition by Abbey Deitel, Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

a) AlertDialog displayed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required