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

You have already displayed the Tetris Bucket, started dropping the shapes, stopp

ID: 3777044 • Letter: Y

Question

You have already displayed the Tetris Bucket, started dropping the shapes, stopped them at the bottom of the Bucket, dropped another shape from the top, got the user input and moved/rotated the shape in response to the user input.

In this assignment, you need to:

1. Determine whether any of the rows are complete.

2. If a row is complete, remove that line and drop all the shapes above the line by one cell.

3. Compute and display the score.

4. Add plenty of narrative comments. Your program must be compilable and executable.

The code I have so far is:

// F. Deen
// November 20, 2016
// This program is being submitted on November 20, 2016 for Carl Arrington's N207/COP2224 Section 01 Programming II Course.
// Moving And Rotating The Shapes.


#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <cstdlib>
#include <time.h>


using namespace std;


class TetrisShape {

public:

   int shapeTopLeftX;
   int shapeTopLeftY;

   TetrisShape() {
   shapeTopLeftX = 6;
   shapeTopLeftY = 0;
   }
  
   char shapeArray[4][4];
   void populateShapeArray(int shapeType) {
   switch(shapeType) {
  
       case 1:
       shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
       shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
       shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = 'X'; shapeArray[3][2] = ' ';
       shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
       break;
  
       case 2:
       shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
       shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
       shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
       shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
       break;
  
       case 3:
       shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = 'X'; shapeArray[3][0] = ' ';
       shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = 'X'; shapeArray[3][1] = ' ';
       shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
       shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
       break;
  
       case 4:
       shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = 'X'; shapeArray[3][0] = ' ';
       shapeArray[0][1] = 'X'; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
       shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
       shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
       break;
  
       case 5:
       shapeArray[0][0] = 'X'; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
       shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = 'X'; shapeArray[3][1] = ' ';
       shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
       shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
       break;
  
       case 6:
        shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
        shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
        shapeArray[0][2] = 'X'; shapeArray[1][2] = 'X'; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
        shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
        break;
       }
   }
};

const int width = 12;
const int height = 25;
char bucket [height][width] = {             
           'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x',
'x','x','x','x','x','x','x','x','x','x','x','x',
               };


void setCursorTo(int x, int y) {
   HANDLE handle;
   COORD position;
   handle = GetStdHandle(STD_OUTPUT_HANDLE);
   position.X = x;
   position.Y = y;
   SetConsoleCursorPosition(handle, position);
}


void drawBucket() {
   setCursorTo(0,0);
    for(int x = 0; x <= height; x++) {
       int a = width;
   a = width;
   int b = width;
  
           for(int y = 0; y < a; y++) {
       cout << bucket[x][y];
       }
  
           if(b == width) {
       cout << bucket[x][b] << endl;
   }

}
}


void updateBucket(TetrisShape localTetrisShape) {
   int shapeTopLeftX = 6;
   int shapeTopLeftY = 0;
  
       for(int i = 0; i < 4; i++){
  
           for(int j = 0; j < 4; j++){
            bucket[shapeTopLeftX+i][shapeTopLeftY+j] = localTetrisShape.shapeArray[i][j];
       }
       }
}


int _tmain(int argc, _TCHAR* argv[]) {
  
   TetrisShape shape;
   int gameOver = 0;

   while(gameOver == 0) {
  
       void drawBucket();
   srand(time(NULL));
   int number = rand() % 6 + 1;
   shape.populateShapeArray(number);
   updateBucket(shape);
   int newshapeTopLeftY = shape.shapeTopLeftY + 1;

   }

   return
}

Explanation / Answer

Answer:

class TetrisShape
{
public:
int shapeTopLeftX;
int shapeTopLeftY;

bool active =true;
TetrisShape()
{
shapeTopLeftX = 6;
shapeTopLeftY = 0;
}
char shapeArray[4][4];
int stoppointY[4];
  
void populateShapeArray(int shapeType)
{
int a=0,b=1,c=2,d=3;
switch(shapeType)
{
case 1:
shapeArray[a][0] = ' '; shapeArray[b][0] = 'X'; shapeArray[c][0] = ' '; shapeArray[d][0] = ' ';
shapeArray[a][1] = ' '; shapeArray[b][1] = 'X'; shapeArray[c][1] = ' '; shapeArray[d][1] = ' ';
shapeArray[a][2] = ' '; shapeArray[b][2] = 'X'; shapeArray[c][2] = 'X'; shapeArray[d][2] = ' ';
shapeArray[a][3] = ' '; shapeArray[b][3] = ' '; shapeArray[c][3] = ' '; shapeArray[d][3] = ' ';
stoppointY[a]=0;
stoppointY[b]=3;
stoppointY[c]=3;
stoppointY[d]=0;
break;
case 2:
shapeArray[a][0] = ' '; shapeArray[b][0] = 'X'; shapeArray[c][0] = ' '; shapeArray[d][0] = ' ';
shapeArray[a][1] = ' '; shapeArray[b][1] = 'X'; shapeArray[c][1] = ' '; shapeArray[d][1] = ' ';
shapeArray[a][2] = ' '; shapeArray[b][2] = 'X'; shapeArray[c][2] = ' '; shapeArray[d][2] = ' ';
shapeArray[a][3] = ' '; shapeArray[b][3] = 'X'; shapeArray[c][3] = ' '; shapeArray[d][3] = ' ';
stoppointY[a]=0;
stoppointY[b]=4;
stoppointY[c]=0;
stoppointY[d]=0;
break;
case 3:
shapeArray[a][0] = ' '; shapeArray[b][0] = 'X'; shapeArray[c][0] = 'X'; shapeArray[d][0] = ' ';
shapeArray[a][1] = ' '; shapeArray[b][1] = 'X'; shapeArray[c][1] = 'X'; shapeArray[d][1] = ' ';
shapeArray[a][2] = ' '; shapeArray[b][2] = ' '; shapeArray[c][2] = ' '; shapeArray[d][2] = ' ';
shapeArray[a][3] = ' '; shapeArray[b][3] = ' '; shapeArray[c][3] = ' '; shapeArray[d][3] = ' ';
stoppointY[a]=0;
stoppointY[b]=2;
stoppointY[c]=2;
stoppointY[d]=0;
break;
case 4:
shapeArray[a][0] = ' '; shapeArray[b][0] = 'X'; shapeArray[c][0] = 'X'; shapeArray[d][0] = ' ';
shapeArray[a][1] = 'X'; shapeArray[b][1] = 'X'; shapeArray[c][1] = ' '; shapeArray[d][1] = ' ';
shapeArray[a][2] = ' '; shapeArray[b][2] = ' '; shapeArray[c][2] = ' '; shapeArray[d][2] = ' ';
shapeArray[a][3] = ' '; shapeArray[b][3] = ' '; shapeArray[c][3] = ' '; shapeArray[d][3] = ' ';
stoppointY[a]=2;
stoppointY[b]=2;
stoppointY[c]=1;
stoppointY[d]=0;
break;
case 5:
shapeArray[a][0] = 'X'; shapeArray[b][0] = 'X'; shapeArray[c][0] = ' '; shapeArray[d][0] = ' ';
shapeArray[a][1] = ' '; shapeArray[b][1] = 'X'; shapeArray[c][1] = 'X'; shapeArray[d][1] = ' ';
shapeArray[a][2] = ' '; shapeArray[b][2] = ' '; shapeArray[c][2] = ' '; shapeArray[d][2] = ' ';
shapeArray[a][3] = ' '; shapeArray[b][3] = ' '; shapeArray[c][3] = ' '; shapeArray[d][3] = ' ';

stoppointY[a]=1;
stoppointY[b]=2;
stoppointY[c]=2;
stoppointY[d]=0;
break;
case 6:
shapeArray[a][0] = ' '; shapeArray[b][0] = 'X'; shapeArray[c][0] = ' '; shapeArray[d][0] = ' ';
shapeArray[a][1] = ' '; shapeArray[b][1] = 'X'; shapeArray[c][1] = ' '; shapeArray[d][1] = ' ';
shapeArray[a][2] = 'X'; shapeArray[b][2] = 'X'; shapeArray[c][2] = ' '; shapeArray[d][2] = ' ';
shapeArray[a][3] = ' '; shapeArray[b][3] = ' '; shapeArray[c][3] = ' '; shapeArray[d][3] = ' ';
stoppointY[a]=3;
stoppointY[b]=3;
stoppointY[c]=0;
stoppointY[d]=0;
break;
}
}
};

const int width = 12;
const int height = 25;
int bucketobjectheight[width];
char bucket [height][width] =
{
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','x'},
{'x','x','x','x','x','x','x','x','x','x','x','x'}

};
void InitializeBucket()
{
for(int i =0;i<width;i++)
{
bucketobjectheight[i] = 20;

}

}


void setCursorTo(int x, int y)
{
HANDLE handle;
COORD position;
handle = GetStdHandle(STD_OUTPUT_HANDLE);
position.X = x;
position.Y = y;
SetConsoleCursorPosition(handle, position);
}

void drawBucket()
{
setCursorTo(0,0);
for(int x = 0; x <= height; x++)
{

for(int y = 0; y < width; y++)
{
cout<<bucket[x][y];
}
cout<<endl;

}
}
  
int movedown =0;

void updateBucket(TetrisShape localTetrisShape)
{

movedown++;

int shapeTopLeftX=6;

for(int i =0;i<width;i++)
{
for (int a = 0;a<4;a++)
{

if(i>i-4)
{
break;
}

if(localTetrisShape.stoppointY[a]+movedown >= bucketobjectheight[i+a] && localTetrisShape.active == true)
{
for(int j = 0; j < 4; j++)
{
  
bucketobjectheight[shapeTopLeftX+j] -= localTetrisShape.stoppointY[j];
}

localTetrisShape.active= false;
}
}

}

  
if(localTetrisShape.active==true)
{
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
{
bucket[movedown+i][shapeTopLeftX+j] = localTetrisShape.shapeArray[i][j];
}
}
}
}

int _tmain(int argc, _TCHAR* argv[])
{
TetrisShape shape;
int gameOver = 0;
InitializeBucket();

while(gameOver == 0)
{
  
srand(time(NULL));
int number = rand() % 6 + 1;
shape.populateShapeArray(1);
updateBucket(shape);
drawBucket();
Sleep(500);

}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote