Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q 3 : Add a row of bricks and other features to finalize creation of Breakout. ( DentStewA 4 Q 3 . pde ) In
Q: Add a row of bricks and other features to finalize creation of Breakout.
DentStewAQpde
In this question you will take the code you created in Q and modify it You will add a row of bricks to the top wall.
When the ball hits a brick, the brick should disappear The ball should bounce off
the top wall as before. This process should repeat until all of the bricks have been
hit, at which stage the screen should be greyed out and two buttons should appear.
One button will restart the game, and the other will close the window.
To achieve the required funcitonalities, the following variables must be
declared.
o Constant NUMBRICKS for the total number of bricks. Choose
a value of or less, so that each brick can be identified by a
singledigit number.
o Constant BRICKHEIGHT.
o boolean variable gameOver to indicate that the game is over and
the buttons should appear to give the user the choice of starting a
new game or quitting.
o boolean variable exit to indicate that the program should end.
o Constants for the restart button: RESTARTLEFT, RESTARTTOP, RESTARTWIDTH and
RESTARTHEIGHT.
o Constants for the exit button: EXITLEFT, EXITTOP, EXITWIDTH and EXITHEIGHT.
o A String called brickHitNums which will store the brick numbers that have been hit by the ball.
For example, if the ball hit bricks then then then then this String should contain
The following functions must be created to achieve the required functionality:
o resetParameters: This function will not have any parameters and will return void. The purpose of
this function is to reset the ball position and speed, and the String brickHitNums, in order to start
a new game.
ASSIGNMENT
COURSE NUMBER: COMP
o boolean isInStringString int: This function should determine whether or not the String
contains the given integer digit. For example, isinString should return true, but
isinString should return false.
Remember that and are different types of data. You will need to use some casting or
conversion.
This function will be called by drawBricks function to determine whether or not a
particular brick has been hit.
o drawBricks: This function will be a void function with no parameters. It must perform following
tasks:
Draw the row of up to bricks, as specified by numOfBricks.
While drawing, determine if the ball is touching any brick. If so add that bricks number
to the String brickHitNum, but only if it is not already there. Use the isInString
function to help.
If any brick has been hit, do not draw that brick. Draw the bricks that have not been hit.
If all of the bricks have been hit, update the gameOver variable to indicate that the game
is over, and that the option buttons should be presented to the user.
o displayExitOptions: The purpose of this function is to display two buttons after the game is over.
One will be labelled Restart and the other Exit. Based on which
button the user clicks, call the appropriate function and update
any appropriate variables.
o mouseClicked: Use this function to determine which button the
user has clicked.
If user clicks on Restart, call the resetParameters
function to restart the game.
If user clicks on Exit, use exit to stop the program.
Watch the video COMPAQMP on moodle for an illustration.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started