Answered step by step
Verified Expert Solution
Link Copied!

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 5 bricks.
1. Edit Game.h to #include and replace the single brick for a vector of bricks
2. Add 5 bricks to the vector with their positions evenly spaced across a single row.
3. Update the Game::Render function to utilize the vector.
4. Update the Game::CheckCollision function to check all the bricks.
Collision Response
If a brick is hit by the ball 3 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()
{
for(int i =0; i<5;++i)
{
Box brick;
brick.x_position =5+i;
bricks.push_back(brick);
}
Reset();
}
void Game::Reset()
{
Console::SetWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
Console::CursorVisible(false);
paddle.width =12;
paddle.height =2;
paddle.x_position =32;
paddle.y_position =30;
ball.visage ='O';
ball.color = ConsoleColor::Cyan;
ResetBall();
// TODO #2- Add this brick and 4 more bricks to the vector
brick.width =10;
brick.height =2;
brick.x_position =0;
brick.y_position =5;
brick.doubleThick = true;
brick.color = ConsoleColor::DarkGreen;
}
void Game::ResetBall()
{
ball.x_position = paddle.x_position + paddle.width /2;
ball.y_position = paddle.y_position -1;
ball.x_velocity = rand()%2?1 : -1;
ball.y_velocity =-1;
ball.moving = false;
}
bool Game::Update()
{
if (GetAsyncKeyState(VK_ESCAPE) & 0x1)
return false;
if (GetAsyncKeyState(VK_RIGHT) && paddle.x_position < WINDOW_WIDTH - paddle.width)
paddle.x_position +=2;
if (GetAsyncKeyState(VK_LEFT) && paddle.x_position >0)
paddle.x_position -=2;
if (GetAsyncKeyState(VK_SPACE) & 0x1)
ball.moving =!ball.moving;
if (GetAsyncKeyState('R') & 0x1)
Reset();
ball.Update();
CheckCollision();
return true;
}
// All rendering should be done between the locks in this function
void Game::Render() const
{
Console::Lock(true);
Console::Clear();
paddle.Draw();
ball.Draw();
// TODO #3- Update render to render all bricks
for(const auto&brick: bricks)
{
brick.Draw();
}
Console::Lock(false);
}
void Game::CheckCollision()
{
// TODO #4- Update collision to check all bricks
if (brick.Contains(ball.x_position + ball.x_velocity, ball.y_position + ball.y_velocity))
{
brick.color = ConsoleColor(brick.color -1);
ball.y_velocity *=-1;
// TODO #5- If the ball hits the same brick 3 times (color == black), remove it from the vector
}
// TODO #6- If no bricks remain, pause ball and display victory text with R to reset
if (paddle.Contains(ball.x_position + ball.x_velocity, ball.y_velocity + ball.y_position))
{
ball.y_velocity *=-1;
}
// TODO #7- 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

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

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

1. Arouse curiosity with questions such as What would happen if?

Answered: 1 week ago

Question

Did you cite the sources of the statistics?

Answered: 1 week ago