Java Reference
In-Depth Information
***16.25
( Game: hit balloons ) Write a program that displays a balloon in a random
position in a panel (Figure 16.27a). Use the left- and right-arrow keys to point
the gun left or right to aim at the balloon (Figure 16.27b). Press the up-arrow
key to fire a small ball from the gun (Figure 16.27c-d). Once the ball hits the
balloon, the debris is displayed (Figure 16.27e) and a new balloon is dis-
played in a random location (Figure 16.27f). If the ball misses the balloon, the
ball disappears once it hits the boundary of the panel. You can then press the
up-arrow key to fire another ball. Whenever you press the left- or the right-
arrow key, the gun turns 5 degrees left or right. (Instructors may modify the
game as follows: 1. Display the number of the balloons destroyed; 2. display
a countdown timer (e.g., 60 seconds) and terminate the game once the time
expires; and/or 3. allow the balloon to rise dynamically.)
(a)
(b)
(c)
(d) (e) (f)
F IGURE 16.27 (a) A balloon is displayed in a random location. (b) Press the left-/right-
arrow keys to aim at the balloon. (c) Press the up-arrow key to fire a ball. (d) The ball moves
straight toward the balloon. (e) The ball hits the balloon. (f ) A new balloon is displayed in a
random position.
**16.26
( Move a circle using mouse ) Write a program that displays a circle with radius 10
pixels. You can point the mouse inside the circle and drag (i.e., move with mouse
pressed) the circle wherever the mouse goes, as shown in Figure 16.28a-b.
(a) (b) (c) (d)
F IGURE 16.28 (a-b) You can point, drag, and move the circle. (c) When you click a circle, a new circle is displayed at a
random location. (d) After 20 circles are clicked, the time spent is displayed in the panel.
***16.27
( Game: eye-hand coordination ) Write a program that displays a circle of radius
10 pixels filled with a random color at a random location on a panel, as shown
in Figure 16.28c. When you click the circle, it disappears and a new random-
color circle is displayed at another random location. After twenty circles are
clicked, display the time spent in the panel, as shown in Figure 16.28d.
 
Search WWH ::




Custom Search