Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am creating a tetrisGame and this is the assignment: You have already displayed the Tetris Bucket and started dropping the shapes. During this module,

I am creating a tetrisGame and this is the assignment:

You have already displayed the Tetris Bucket and started dropping the shapes. During this module, you stop the falling shape at the bottom of the Bucket. If there are shapes already stacked at the bottom of the bucket, then you stop the shape on top of other shapes. At the same time, you drop another shape from the top. Add plenty of narrative comments. Your program must be compilable and executable.

Here is my code so far, I am stuck with the checkBucket() and setShape() functions as I cant figure out how to store the shape in place and also how to transition to a new shape.

What I need is to stop the shape in place and store the placement and then call for another shape

// tetris.cpp : Defines the entry point for the console application.

//

#include

#include

#include

#include

using namespace std;

int shapeTopLeftX = 0;

int shapeTopLeftY = 6;

class TetrisShape {

public:

int shapeTopLeftY = 0;

int shapeTopLeftX = 6;

;

char shapeArray[4][4];

void populateShapeArray(int shapeType) {

switch (shapeType) {

case 2:

shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = 'X'; shapeArray[3][0] = ' ';

shapeArray[0][1] = ' '; shapeArray[1][1] = ' '; shapeArray[2][1] = 'X'; shapeArray[3][1] = ' ';

shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = 'X'; shapeArray[3][2] = 'X';

shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';

break;

case 5:

shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = ' '; shapeArray[3][0] = 'X';

shapeArray[0][1] = ' '; shapeArray[1][1] = ' '; shapeArray[2][1] = ' '; shapeArray[3][1] = 'X';

shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = ' '; shapeArray[3][2] = 'X';

shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = 'X';

break;

case 1:

shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = 'X'; shapeArray[3][0] = 'X';

shapeArray[0][1] = ' '; shapeArray[1][1] = ' '; shapeArray[2][1] = 'X'; shapeArray[3][1] = 'X';

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 3:

shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = 'X'; shapeArray[3][0] = 'X';

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] = ' '; shapeArray[1][1] = ' '; shapeArray[2][1] = 'X'; shapeArray[3][1] = 'X';

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] = ' '; shapeArray[2][0] = ' '; shapeArray[3][0] = 'X';

shapeArray[0][1] = ' '; shapeArray[1][1] = ' '; shapeArray[2][1] = ' '; shapeArray[3][1] = 'X';

shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = 'X'; shapeArray[3][2] = 'X';

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',

};//end of class

void setCursorTo(int x, int y) {

HANDLE handle;

COORD position;

handle = GetStdHandle(STD_OUTPUT_HANDLE);

position.X = x;

position.Y = y;

SetConsoleCursorPosition(handle, position);

Sleep(500);

};

void drawBucket() {//function to draw the bucket boundaries

int a = width;

int b = width;

setCursorTo(0, 0);//setting start point of bucket

for (int x = 0; x <= height; x++) {//drawing sides of bucket

for (int y = 0; y < a; y++) {

cout << bucket[x][y];

}

if (b == width) {

cout << bucket[x][b] << endl;

}

}

}

void checkBucket(TetrisShape localTetrisShape) {

int x = height;

int y = width;

if (shapeTopLeftX == height - 3) {

setShape();

if (shapeTopLeftY == width, 0) {

shapeTopLeftY = shapeTopLeftY;

shapeTopLeftX++;

}

}

}

void setShape(TetrisShape localTetrisShape) {

}

void updateBucket(TetrisShape localTetrisShape) {//moving shape along the bucket

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

for (int j = 0; j < 4; j++) {

bucket[shapeTopLeftX + i][shapeTopLeftY + j] = localTetrisShape.shapeArray[i][j];

}

}

}

int main() {

drawBucket();

TetrisShape currentTetrisShape, nextTetrisShape;

TetrisShape shape;

int gameOver = 0;

srand(time(NULL));

int number = rand() % 6 + 1;

shape.populateShapeArray(number);

updateBucket(shape);

drawBucket();

while (gameOver == 0) {

int newShapeTopLeftX = shapeTopLeftX + 1;

shapeTopLeftX = newShapeTopLeftX;

checkBucket(shape);

updateBucket(shape);

drawBucket();

}

}

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

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago