Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C++ program that will play the Breakout game under windows cmd console

ID: 3569116 • Letter: C

Question

Create a C++ program that will play the Breakout game under windows cmd console screen. I only need the ball, paddle and brick objectives and combine all in a game. No need for different levels or difficulty. Everything are controlled by the arrow keys. Think of the easilest breakout game under the windows cmd console. Thanks

A ball travels across the screen, bouncing off the top and side walls of the screen. When a brick is hit, the ball bounces away and the brick is destroyed. The player loses a turn when the ball touches the bottom of the screen. To prevent this from happening, the player has a movable paddle to bounce the ball upward, keeping it in play.

Create the ball object in C++ and if you like, create the block objects.

Here are the plotter objects:

//plotter.cpp

-------------------------------------------------------------------------------------------------------------------------------------------------------

//plotter.h

Explanation / Answer

#include <iostream>
#include <cstdlib>
using namespace std;

typedef enum
{
   VALUE,
   JACK,
   QUEEN,
   KING,
   ACE
} FACE;

typedef struct
{
   int value;
   FACE f;
} CARD;

void print_card(CARD c)
{
   if (c.f == ACE)
       cout << "ACE (11)";
   else if (c.f == KING)
       cout << "KING (10)";
   else if (c.f == QUEEN)
       cout << "QUEEN (10)";
   else if (c.f == JACK)
       cout << "JACK (10)";
   else if (c.f == VALUE)
   {
       if (c.value == 10)
           cout << "TEN (10)";
       else if (c.value == 9)
           cout << "NINE (9)";
       else if (c.value == 8)
           cout << "EIGHT (8)";
       else if (c.value == 7)
           cout << "SEVEN (7)";
       else if (c.value == 6)
           cout << "SIX (6)";
       else if (c.value == 5)
           cout << "FIVE (5)";
       else if (c.value == 4)
           cout << "FOUR (4)";
       else if (c.value == 3)
           cout << "THREE (3)";
       else if (c.value == 2)
           cout << "TWO (2)";
       else
           cout << "Value not recognized";
   }
   else
       cout << "Face not recognized";
}

void init_deck(CARD deck[])
{
   for (int index = 0; index < 4; index++)
   {
       int seg = index * 13;

       deck[seg + 0].f = VALUE;
       deck[seg + 0].value = 2;

       deck[seg + 1].f = VALUE;
       deck[seg + 1].value = 3;

       deck[seg + 2].f = VALUE;
       deck[seg + 2].value = 4;

       deck[seg + 3].f = VALUE;
       deck[seg + 3].value = 5;

       deck[seg + 4].f = VALUE;
       deck[seg + 4].value = 6;

       deck[seg + 5].f = VALUE;
       deck[seg + 5].value = 7;

       deck[seg + 6].f = VALUE;
       deck[seg + 6].value = 8;

       deck[seg + 7].f = VALUE;
       deck[seg + 7].value = 9;

       deck[seg + 8].f = VALUE;
       deck[seg + 8].value = 10;

       deck[seg + 9].f = JACK;
       deck[seg + 9].value = 10;

       deck[seg + 10].f = QUEEN;
       deck[seg + 10].value = 10;

       deck[seg + 11].f = KING;
       deck[seg + 11].value = 10;

       deck[seg + 12].f = ACE;
       deck[seg + 12].value = 11;
   }
}

void print_deck(CARD deck[])
{
   for (int x = 0; x < 52; x++)
   {
       print_card(deck[x]);
       cout << endl;
   }
}

void shuffle_deck(CARD deck[])
{
   for (int x = 0; x < 52; x++)
   {
       int new_index = rand() % 52;
       CARD temp = deck[x];
       deck[x] = deck[new_index];
       deck[new_index] = temp;
   }
}

int main()
{
   srand();
   CARD deck[52];
   init_deck(deck);
   shuffle_deck(deck);
   print_deck(deck);
   int bank;
   int seed;
   int bet;

   cout << "Enter the initial bankroll" << endl;
   cin >> bank;
   cout << "Enter seed" << endl;
   cin >> seed;
   cout << "Seeding random number generator..." << endl;
   cout << "== Blackjack v1.0 ==" << endl;
   cout << "Initializing deck..." << endl;
   init_deck(deck);
   cout << "Shuffling deck..." << endl;
   shuffle_deck(deck);
   cout << "Enter bet:" << endl;
   cin >> bet;
   cout << "Current hand: " << srand(seed) % 3 << ".";
   cout << "Player has: " << endl;
}