Question

***16.25 (Game: hit balloons) Write a program that displays a balloon in a random position in a panel (Figure 16.27a). Use th

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Balloon hitting game Program Plan: Create an applet panel and set the gun inside it Create a balloon in that panel as random

Program *Compile Rurn : javac HittingBalloons.java : java HittingBalloons t/ // header files import java. awt.Graphics; impor

add ( board ); board. setFocusable ( true clas s Game extends JPanel //instance variables private int ballons Hit= 0; private

//this timer will end the shatter visual private Timer stopShatter; The current distance ofthe mini-balloons from the shatter

this.setSize (width, height); xCoordinate this.getWidth)/2-1;

Dont try this line before the constructor, because it depends on the size of the panel which isnt set before setSize is cal

switch e. getKeyCode ) case KeyEvent. VK_UP: shootBall); bulletTilt gunTİlt; break; case KeyEvent. VK_LEFT: turnLeft ); break

Make y between 1 and half of the y-co ordinate of the lower hand edge of the JPanel Random rand new Random Point location - n

public void turnLeft () xCoordinate - 1; gunTiltt5; public void turnRight () Coordinate gunTilt 1; 5 Biggest issue here is, t

//Draw gun //turnLeft ) and turnRight will control it g.drawLine ( getWidth / 2 + x, getHeight- y, getMidth) / 2, getHeight;

//Draw bullet if (shooting) g. drawoval shootingFrom. x, shootingFrom.y, bulletRadius, bulletRadius) //check if the bullet hi

//bullets shoot straight up if (shootingFron.y <= 0 //hits top shootingFrom. x < 0 //hits left edge shootingFrom.x >- this.ge

lic static void main( Stringl] args) int width 300, height 300 HittingBalloons frame - new HittingBalloons (width, height); f

frame. setLocationRelativeTo ( null frame.setDefaultcloseoperation( JFrame. EXIT_ON_CLOSE frame. setvisible ( true ) Sample o

Hit Boundary Hit Boundary! The ball is already being shot! Hit Boundary! Hit Boundary Hit Boundary! Hit Boundary Ballon Hit!



Add a comment
Know the answer?
Add Answer to:
***16.25 (Game: hit balloons) Write a program that displays a balloon in a random position in a p...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT