I have my Tetris game code, but I need some help with the blocks. The blocks are
ID: 3578532 • Letter: I
Question
I have my Tetris game code, but I need some help with the blocks. The blocks are not showing up on screen and they don't generate as randomly as I would like. Can someone look at my code and help me fix these errors to make a complete functional game?
#include <iostream>
#include "windows.h"
#include <ctime>
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 score1 = 0;
int main() {
char playAgain;
cout << "Welcome to Tetris!! Would you like to play?(y/n)" << endl;
cin >> playAgain;
while ((playAgain != 'y') && (playAgain != 'n')) {
cout << "Please enter a y or a n" << endl;
cin >> playAgain;
}
if(playAgain == 'y') {
srand(static_cast<unsigned int>(time(0)));
int shapeType = rand() % 7;
while(playAgain == 'y') {
tetrisShape(shapeType);
displayBucket();
setCursorTo(0,0);
beginGame();
cout << "Would you like to play again?(y/n): " << endl;
cin >> playAgain;
while((playAgain != 'y') && (playAgain != 'n')) {
cout << "Please enter a y or a n: " << endl;
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 << "| |" << endl;
}
else
{
cout << "|============|" << 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" << endl;
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" << endl;
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() {
score1++;
}
void endGame() {
// clrscr();
cout << "Score = " << score1 << endl;
}
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include "windows.h"
#include <ctime>
#include <string>
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 displayShape(string shapeArray[][4]);
void shapeDrop();
void clearRow();
int score();
void beginGame();
void endGame();
int score1 = 0;
int main() {
char playAgain;
cout << "Welcome to Tetris!! Would you like to play?(y/n)" << endl;
cin >> playAgain;
while ((playAgain != 'y') && (playAgain != 'n')) {
cout << "Please enter a y or a n" << endl;
cin >> playAgain;
}
if(playAgain == 'y') {
srand(static_cast<unsigned int>(time(0)));
int shapeType = rand() % 7;
while(playAgain == 'y') {
tetrisShape(shapeType);
displayBucket();
setCursorTo(0,0);
beginGame();
cout << "Would you like to play again?(y/n): " << endl;
cin >> playAgain;
while((playAgain != 'y') && (playAgain != 'n')) {
cout << "Please enter a y or a n: " << endl;
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 << "| |" << endl;
}
else
{
cout << "|============|" << endl;
}
}
}
void tetrisShape(int x) {
int shapeTopLeftX = 6;
int shapeTopLeftY = 0;
populateShapeArray(x);
}
void populateShapeArray(int x) {
string shapeArray[4][4] = {"0"};
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] = ' ';
displayShape(shapeArray);
break;
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] = ' ';
displayShape(shapeArray);
break;
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] = ' ';
displayShape(shapeArray);
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] = ' ';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] = ' ';
displayShape(shapeArray);
break;
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] = ' ';
displayShape(shapeArray);
break;
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] = ' ';
displayShape(shapeArray);
break;
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] = ' ';
displayShape(shapeArray);
break;
default:
break;
}
}
void userInput() {
char mvDir;
cout << "Please enter move direction: L = left, R = right, U = up, D = down" << endl;
cin >> mvDir;
string 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] = ' ';
displayShape(shapeArray);
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] = ' ';
displayShape(shapeArray);
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] = ' ';
displayShape(shapeArray);
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] = ' ';
displayShape(shapeArray);
break;
}
}
void moveShape() {
char mvDir;
cout << "Please enter move direction: 1 = Up & left, 2 = Up & right, 3 = Down & Left, 4 = Down & Right" << endl;
cin >> mvDir;
string 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] = ' ';
displayShape(shapeArray);
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] = ' ';
displayShape(shapeArray);
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] = ' ';
displayShape(shapeArray);
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] = ' ';
displayShape(shapeArray);
break;
}
}
void displayShape(string shapeArray[][4])
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << shapeArray[i][j] << " ";
}
cout << endl;
}
}
void shapeDrop() {
string 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() {
string 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() {
score1++;
return score1;
}
void endGame() {
// clrscr();
cout << "Score = " << score1 << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.