Answered step by step
Verified Expert Solution
Link Copied!

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

Q3: Add a row of bricks and other features to finalize creation of Breakout.
(DentStewA4Q3.pde)
In this question you will take the code you created in Q2 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 NUM_BRICKS for the total number of bricks. Choose
a value of 10 or less, so that each brick can be identified by a
single-digit number.
o Constant BRICK_HEIGHT.
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: RESTART_LEFT, RESTART_TOP, RESTART_WIDTH and
RESTART_HEIGHT.
o Constants for the exit button: EXIT_LEFT, EXIT_TOP, EXIT_WIDTH and EXIT_HEIGHT.
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 3 then 7 then 0 then 4, then this String should contain "3704".
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 4
COURSE NUMBER: COMP 1010
4
o boolean isInString(String, int): This function should determine whether or not the String
contains the given integer digit. For example, isinString("3704",7) should return true, but
isinString("3704",6) should return false.
Remember that 7 and '7' 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 10 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 COMP1010A4Q3.MP4 on moodle for an illustration.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions