Can someone help me Compile my Tetris code since I am getting error on it. WHAT
ID: 3769120 • Letter: C
Question
Can someone help me Compile my Tetris code since I am getting error on it.
WHAT AM I doing wrong?
Tetris Source Code:
#include "stdafx.h"
#include <iostream>
#include "windows.h"
#include <ctime>
using namespace std;
using namespace std;
//console width height
const int WIDTH = 400;
const int HEIGHT = 400;
//bucket row and column size
const int buckHeight = 25;
const int buckWidth = 12;
//bucket array
char bucket[buckHeight][buckWidth];
/*
Tetris-
1.user input-start game
2.launch bucket
3.randomize shape, drop in bucket
4.accept user input of shape
5.take user input and display with shape
6.repeat 3-5 till drop
7.drop shape
8.score
9. repeat 2-8 until game over
*/
void initializeBucket();
void displayBucket();
void setCursorTo(int x, int y);
void userInput();
void moveShape();
void shapeDrop();
void clearRow();
void score();
void beginGame();
void endGame();
int main()
{
int score = 0;
char playAgain;
//this is my working game loop, keeps replaying until n is entered
cout << " Welcome to Tetris!!! Would you like to play? (y/n): ";
cin >> playAgain;
while ((playAgain != 'y') && (playAgain != 'n'))
{
cout << " Please enter y or n: ";
cin >> playAgain;
}
if (playAgain == 'y')
{
//rand for shape
srand(static_cast<unsigned int>(time(0)));
int shapeType = rand() % 7;
while (playAgain == 'y')
{
displayBucket();
setCursorTo(0, 0);
beginGame();
cout << " Would you like to play again? (y/n): ";
cin >> playAgain;
while ((playAgain != 'y') && (playAgain != 'n'))
{
cout << " Please enter y or n: ";
cin >> playAgain;
}
}
}
else
system("pause");
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()
{
//this function calls the gameplay functions
//each function here is what keeps the shapes moving and user playing
userInput();
moveShape();
shapeDrop();
clearRow();
endGame();
}
void displayBucket()
{
setCursorTo(0, 1);
initializeBucket();
for (int i = 0; i < buckHeight; i++) {
for (int j = 0; j < buckWidth; j++) {
cout << bucket[i][j];
if (j == 11) cout << endl;
}
}
}
void initializeBucket()
{
for (int i = 0; i < buckHeight; i++) {
for (int j = 0; j < buckWidth; j++) {
if (j == 0 || j == 11 || i == 24) {
bucket[i][j] = '#';
}
else if (bucket[i][j] == 'X') {
continue;
}
else {
bucket[i][j] = ' ';
}
}
}
}
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;
}
}
};
void userInput(char shapeType)
{
char shapeArray[4][4];
char mvDir; // Move Direction
//user presses keys to flip/move shape
cout << " User moves shape" << endl;
cout << "Please enter move direction: L = left, R = right, U = Up, D = Down ";
cin >> mvDir;
switch (mvDir) {
case 'L':
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 '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] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = 'X';shapeArray[3][3] = ' ';
break;
} // end of switch
}
void moveShape(int shapeType)
{
char shapeArray[4][4];
//shape reacts to user input
cout << " Computer moves shape according to user request" << endl;
int mvDir; // Move Direction
//user presses keys to flip/move shape
cout << "Please enter move direction: 1 = Up & left, 2 = Up & right, 3 = Down & Left, 4 = Down & Right";
cin >> mvDir;
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;
} // end of switch
}
void shapeDrop()
{
char shapeArray[4][4];
//when shape drops on bottom and stops
cout << " Shape drops to bottom" << endl;
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()
{
char shapeArray[4][4];
//when a row is filled, will clear and score
cout << " A row is filled, it clears" << endl;
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();
}
void score()
{
//calculates score
int score;
cout << " Add to score" << endl;
score++;
}
void endGame()
{
//when shape hits top, clear screen and display/save score
cout << " Clear screen and save score" << endl;
clearRow();
cout << " Score = " << score;
}
Explanation / Answer
dear student
please find correct & complete tetris project in the link mentioned below.
https://drive.google.com/folderview?id=0By7fLD5Nv8bSZUpCR0tDcllRT1U&usp=sharing
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.