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
  • Game Description: Most of you have played a very interesting game “Snake” on your old Nokia...

    Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...

  • Objective: Write a program that implements the Game of Life cellular automata system invented by John...

    Objective: Write a program that implements the Game of Life cellular automata system invented by John Conway. 1. Create two game grids of size at least 50x50. These grid cells can be either Boolean or integer. In the following, I’ll refer to these as gridOne and gridTwo. 2. Set all cells in both grids to false. 3. Start by initializing gridOne. Allow the user to specify two different ways of initializing the grid: 1) by specifying a pattern file to...

  • The following guidelines outline the basic template for a robot vacuum cleaner game. The game must...

    The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...

  • The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use...

    The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...

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