Question
This is a c++ tetris game. It does not compile. I am not sure why. It MUST be a console app. No graphics. If someone
This is a c++ tetris game. It does not compile. I am not sure why. It MUST be a console app. No graphics. If someone could paste my fixed code as the answer that would be great! Also when you fix it could you please include as a comment what was wrong and how you fixed it for each problem. Thank You!!!
code:
#include
using namespace std;
void initializeBucket(); void displayBucket(); void setCursorTo(int x, int y); void tetrisShape(int x); void populateShapeArray(int x); void userInput(); void moveShape(); void shapeDrop(); void clearRow(); int score(); void beginGame(); void endGame();
int main() { int score = 0; char playAgain;
cout << "Welcome to Tetris!! t\t\ Would you like to play?(y/n)"; cin >> playAgain;
while ((playAgain != 'y')&&(playAgain != 'n')) { cout << "Please enter a y or an n"; cin >> playAgain; }
if(playAgain == 'y') { srand(static_cast
while(playAgain == 'y') { tetrisShape(shapeType); displayBucket(); setCursorTo(0,0); beginGame();
cout << "Would you like to play again?(y/n): "; cin >> playAgain; while((playAgain != 'y')&&(playAgain != 'n')) { cout << "Please enter a y or an n: "; cin >> playAgain; } } }else
return 0; }
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 beginGame() { userInput(); moveShape(); shapeDrop(); clearRow(); endGame(); }
void displayBucket() { initializeBucket(); }
void initializeBucket() { for(int j=0;j<25;j++) { if(j<24) { cout << "\t\t\t| |" << endl;
} else { cout << "\t\t\t|============|" << endl; } } }
void tetrisShape(int x) { int shapeTopLeftX = 6; int shapeTopLeftY = 0; populateShapeArray(x);
}
void populateShapeArray(int x) { int shapeArray[4][4];
switch(x) { case 0: 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] = ' ';
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] = 'X';shapeArray[1][2] = 'X';shapeArray[2][2] = ' ';shapeArray[3][2] = ' '; shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
case 2: shapeArray[0][0] = ' ';shapeArray[1][0] = 'X';shapeArray[2][0] = ' ';shapeArray[3][0] = ' '; shapeArray[0][1] = 'X';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] = ' ';
case 3: 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] = ' ';
case 4: 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] = ' ';
case 5: 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] = ' ';
case 6: 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] = ' ';
default:
break;
} }
void userInput() { char mvDir;
cout << "Please enter move direction: L = left, R = right, U = up, D = down"; cin >> mvDir;
int shapeArray[4][4];
switch(mvDir) { case 'L': shapeArray[0][0] = 'X';shapeArray[1][0] = ' ';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 'R': shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = 'X';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 'U': shapeArray[0][0] = ' ';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] = 'X';shapeArray[2][2] = ' ';shapeArray[3][2] = ' '; shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' '; break;
case 'D': 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;
} }
void moveShape() { char mvDir; cout << "Please enter move direction: 1 = Up & left, 2 = Up & right, 3 = Down & Left, 4 = Down & Right"; cin >> mvDir;
int shapeArray[4][4];
switch(mvDir) { case '1': shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = ' ';shapeArray[3][0] = 'X'; 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] = ' ';shapeArray[2][0] = 'X';shapeArray[3][0] = ' '; shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = ' ';shapeArray[3][1] = 'X'; shapeArray[0][2] = ' ';shapeArray[1][2] = 'X';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] = '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] = 'X';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' '; break;
case 4: shapeArray[0][0] = ' ';shapeArray[1][0] = 'X';shapeArray[2][0] = ' ';shapeArray[3][0] = 'X'; 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] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' '; break; } }
void shapeDrop() { int shapeArray[4][4];
shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = ' ';shapeArray[3][0] = ' '; shapeArray[0][1] = ' ';shapeArray[1][1] = ' ';shapeArray[2][1] = ' ';shapeArray[3][1] = ' '; shapeArray[0][2] = ' ';shapeArray[1][2] = ' ';shapeArray[2][2] = ' ';shapeArray[3][2] = ' '; shapeArray[0][3] = 'X';shapeArray[1][3] = 'X';shapeArray[2][3] = 'X';shapeArray[3][3] = 'X';
}
void clearRow() { int shapeArray[4][4];
shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = ' ';shapeArray[3][0] = ' '; shapeArray[0][1] = ' ';shapeArray[1][1] = ' ';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] = ' ';
score(); }
int score() { score++; }
void endGame() { clrscr(); cout << "/n Score = " << score << endl; }
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