Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Replace the solitary brick object with a vector of 5 bricks. 1 . Edit Game.h to #include and replace the single brick for a vector
Replace the solitary brick object with a vector of bricks.
Edit Game.h to #include and replace the single brick for a vector of bricks
Add bricks to the vector with their positions evenly spaced across a single row.
Update the Game::Render function to utilize the vector.
Update the Game::CheckCollision function to check all the bricks.
Collision Response
If a brick is hit by the ball times, remove it from the vector.
Win Condition
If no bricks remain, pause the ball and print the following text to the middle of the screen. You win! Press R to play again.
Lose Condition
If the ball touches the bottom of the window, pause the ball and print the following text to the middle of the screen. You lose. Press R to play again.
End Result
Your finished project should behave like the example. It doesnt have to be exact but should contain the same basic functionality.Game::Game
forint i ; i;i
Box brick;
brick.xposition i;
bricks.pushbackbrick;
Reset;
void Game::Reset
Console::SetWindowSizeWINDOWWIDTH, WINDOWHEIGHT;
Console::CursorVisiblefalse;
paddle.width ;
paddle.height ;
paddle.xposition ;
paddle.yposition ;
ball.visage O;
ball.color ConsoleColor::Cyan;
ResetBall;
TODO # Add this brick and more bricks to the vector
brick.width ;
brick.height ;
brick.xposition ;
brick.yposition ;
brick.doubleThick true;
brick.color ConsoleColor::DarkGreen;
void Game::ResetBall
ball.xposition paddle.xposition paddle.width ;
ball.yposition paddle.yposition ;
ball.xvelocity rand : ;
ball.yvelocity ;
ball.moving false;
bool Game::Update
if GetAsyncKeyStateVKESCAPE & x
return false;
if GetAsyncKeyStateVKRIGHT && paddle.xposition WINDOWWIDTH paddle.width
paddle.xposition ;
if GetAsyncKeyStateVKLEFT && paddle.xposition
paddle.xposition ;
if GetAsyncKeyStateVKSPACE & x
ball.moving ball.moving;
if GetAsyncKeyStateR & x
Reset;
ball.Update;
CheckCollision;
return true;
All rendering should be done between the locks in this function
void Game::Render const
Console::Locktrue;
Console::Clear;
paddle.Draw;
ball.Draw;
TODO # Update render to render all bricks
forconst auto&brick: bricks
brick.Draw;
Console::Lockfalse;
void Game::CheckCollision
TODO # Update collision to check all bricks
if brickContainsballxposition ball.xvelocity, ball.yposition ball.yvelocity
brick.color ConsoleColorbrickcolor ;
ball.yvelocity ;
TODO # If the ball hits the same brick times color black remove it from the vector
TODO # If no bricks remain, pause ball and display victory text with R to reset
if paddleContainsballxposition ball.xvelocity, ball.yvelocity ball.yposition
ball.yvelocity ;
TODO # If ball touches bottom of window, pause ball and display defeat text with R to reset
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