SlideShare a Scribd company logo
1 of 14
Download to read offline
I'm trying again -
Okay, I'm in need of some help - this is the code I have so far for a C++ project on Tetris that
uses the Visual Studio (which is why the #stdafx.h file is in the header). I need to add to this
code to complete the tasks as listed in the assignment. Here's the assignment as I recieved it,
followed by the code:
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.
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
#define GAME_INTERVAL 2
#define GO_DOWN 2
#define GO_LEFT 4
#define GO_RIGHT 6
#define GO_ROTATE 5
class TetrisShape
{
public:
char shapeArray[4][4];
int shapeTopLeftX = 6;
int shapeTopLeftY = 0;
void populateShapeArray(int shape);
void rotate();
template
void setShape(char(&shape)[rows][cols]);
TetrisShape(int shape) { populateShapeArray(shape); };
TetrisShape() {};
};
void TetrisShape::rotate()
{
char _shapeArray[4][4];
_shapeArray[0][0] = shapeArray[0][3]; _shapeArray[1][0] = shapeArray[0][2];
_shapeArray[2][0] = shapeArray[0][1]; _shapeArray[3][0] = shapeArray[0][0];
_shapeArray[0][1] = shapeArray[1][3]; _shapeArray[1][1] = shapeArray[1][2];
_shapeArray[2][1] = shapeArray[1][1]; _shapeArray[3][1] = shapeArray[1][0];
_shapeArray[0][2] = shapeArray[2][3]; _shapeArray[1][2] = shapeArray[2][2];
_shapeArray[2][2] = shapeArray[2][1]; _shapeArray[3][2] = shapeArray[2][0];
_shapeArray[0][3] = shapeArray[3][3]; _shapeArray[1][3] = shapeArray[3][2];
_shapeArray[2][3] = shapeArray[3][1]; _shapeArray[3][3] = shapeArray[3][0];
for (int _s = 0; _s < 4; _s++)
{
for (int _a = 0; _a < 4; _a++)
{
shapeArray[_s][_a] = _shapeArray[_s][_a];
}
}
}
void TetrisShape::populateShapeArray(int shape)
{
switch (shape)
{
case 1:
shapeArray[0][0] = ' '; 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] = ' ';
shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = 'X';
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] = ' '; 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] = 'X';
shapeArray[3][3] = ' ';
break;
case 4:
shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = ' ';
shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = ' '; shapeArray[2][1] = 'X';
shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = 'X';
shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = ' ';
shapeArray[3][3] = ' ';
break;
case 5:
shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = ' ';
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] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = 'X';
shapeArray[3][3] = ' ';
break;
case 6:
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] = 'X'; shapeArray[2][2] = 'X';
shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = 'X';
shapeArray[3][3] = ' ';
break;
}
}
int currentShape = -1; // this is the shape that is currently in play.
int x[4] = { -1, -1, -1, -1 };
int y[4] = { -1, -1, -1, -1 }; // the x, y location for each of the shapes.
bool isDropping = false; // gameTick globals.
int currentTick = 0;
template
void generateBucket(char(&bucket)[rows][cols]); // create the bucket
void generateShapeStream(); // shapes, in drop and in queue, constantly
void dropShape(); // drop the shape
bool moveShape(int direction); // GO_DOWN (falling)
template
bool gameTick(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols]); // handles game
events
template
void landShape(char(&bucket)[rows][cols]); // shape hitting the bottom
template
void drawBucket(char(&bucket)[rows][cols]); // display bucket
int getUserInput(); // gets the key pressed from the user.
template
bool canEnter(int direction, char(&bucket)[rows][cols]); // is space available for the block
void setCursorTo(int x, int y); // set cursor to appropriate position
int previousX = 6, previousY = 0;
int shapes[256];
TetrisShape activeShape;
int main()
{
// set 2 buckets, one permanent and one for display
char bucket[12][25];
char _bucket[12][25];
int shapes[256] = {};
int shapeIndex = 0;
bool gameOver = false;
generateBucket(bucket);
generateBucket(_bucket);
generateShapeStream();
drawBucket(bucket);
while (!gameOver)
{
gameOver = gameTick(bucket, _bucket);
Sleep(500);
currentTick++;
}
setCursorTo(25, 6);
cout << "GAME OVER" << endl;
system("pause");
}
void setCursorTo(int x, int y)
{
HANDLE handle;
COORD position;
handle = GetStdHandle(STD_OUTPUT_HANDLE);
position.X = x;
position.Y = y;
SetConsoleCursorPosition(handle, position);
}
/* generateBucket */
template
void generateBucket(char(&bucket)[rows][cols])
{
for (int w = 0; w < 12; w++)
{
for (int z = 0; z < 25; z++)
{
if (((w == 0) || (w == 11)) && (z == 0))
{
bucket[w][z] = '.';
}
else if (((w % 12 == 0) || (w % 12 == 11)) && ((z > 0) && (z <
24)))
{
bucket[w][z] = '|';
}
else if (((w == 0) || (w == 11)) && (z == 24))
{
bucket[w][z] = '+';
}
else if (z == 24)
{
bucket[w][z] = '-';
}
else
{
bucket[w][z] = ' ';
}
}
}
}
/* generateShapeStream - generates the shapes preparing to fall */
void generateShapeStream()
{
// Initialize the random number generator
srand(time(NULL));
for (int p = 0; p < 256; p++)
{
shapes[p] = rand() % 6 + 1;
}
}
/* drawBucket -displays bucket and shapes to fall */
template
void drawBucket(char(&bucket)[rows][cols])
{
setCursorTo(0, 0);
for (int m = 0; m < 25; m++)
{
for (int k = 0; k < 12; k++)
{
cout << bucket[k][m];
}
cout << endl;
}
}
/* gameTick - everything happening in game, and game over procedures*/
template
bool gameTick(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols])
{
drawBucket(bucket);
if (!isDropping)
{
currentShape++;
activeShape = TetrisShape(shapes[currentShape]);
if (!canEnter(GO_DOWN, perm_bucket))
{
return true;
}
else
{
isDropping = true;
updateBucket(bucket, false);
}
}
else
{
if (currentTick % GAME_INTERVAL == 1)
{
// we are on a drop interval.
if (canEnter(GO_DOWN, perm_bucket))
{
updateBucket(bucket, moveShape(GO_DOWN));
}
else
{
landShape(perm_bucket);
}
}
}
int direction = getUserInput();
if (canEnter(direction, perm_bucket))
{
updateBucket(bucket, moveShape(direction));
}
if (!canEnter(GO_DOWN, perm_bucket))
{
landShape(perm_bucket);
}
return false;
}
/* moveShape - handles the shape dropping down. */
bool moveShape(int direction)
{
previousX = activeShape.shapeTopLeftX;
previousY = activeShape.shapeTopLeftY;
switch (direction)
{
case GO_DOWN:
activeShape.shapeTopLeftY++;
return false;
break;
case GO_RIGHT:
activeShape.shapeTopLeftX++;
return false;
break;
case GO_LEFT:
activeShape.shapeTopLeftX--;
return false;
break;
case GO_ROTATE:
activeShape.rotate();
return true;
break;
}
}
/* updateBucket - place new shape into bucket, and removing old shape*/
template
void updateBucket(char(&bucket)[rows][cols], bool isRotation)
{
for (int _l = 0; _l < 4; _l++)
{
for (int _g = 0; _g < 4; _g++)
{
if (!isRotation)
{
if ((activeShape.shapeArray[_l][_g] != ' ') &&
(bucket[_l + previousX][_g + previousY] != '|') && (bucket[_l + previousX][_g + previousY]
!= '-'))
{
bucket[_l + previousX][_g + previousY] = ' ';
}
}
else {
if ((bucket[_l + previousX][_g + previousY] != '|') &&
(bucket[_l + previousX][_g + previousY] != '-'))
{
bucket[_l + previousX][_g + previousY] = ' ';
}
}
}
}
for (int _l = 0; _l < 4; _l++)
{
for (int _g = 0; _g < 4; _g++)
{
if (activeShape.shapeArray[_l][_g] != ' ')
{
bucket[_l + activeShape.shapeTopLeftX][_g +
activeShape.shapeTopLeftY] = activeShape.shapeArray[_l][_g];
}
}
}
}
/* landShape - Sets the shape in place once it hits the bottom of the bucket. Moves the shape to
the permanent bucket (_bucket)*/
template
void landShape(char(&bucket)[rows][cols])
{
updateBucket(bucket, false);
previousX = 6; previousY = 0;
isDropping = false;
}
/* getUserInput - Reads the user input from the player*/
int getUserInput() {
setCursorTo(35, 9);
if ((GetKeyState(VK_DOWN) != 0) && (GetKeyState(VK_DOWN) != 1)) { return
GO_DOWN; }
if ((GetKeyState(VK_RIGHT) != 0) && (GetKeyState(VK_RIGHT) != 1)) { return
GO_RIGHT; }
if ((GetKeyState(VK_LEFT) != 0) && (GetKeyState(VK_LEFT) != 1)) { return
GO_LEFT; }
if ((GetKeyState(VK_UP) != 0) && (GetKeyState(VK_UP) != 1)) { return
GO_ROTATE; }
return 0;
}
/* canRotate - can we rotate? if we are adjacent to another shape NO! */
template
bool canRotate(char(&bucket)[rows][cols])
{
// creating a copy of the shape, rotating it so we can determine where in the bucket it
will land.
TetrisShape _tmp = TetrisShape(activeShape);
_tmp.rotate();
for (int _t = 0; _t < 4; _t++)
{
for (int _z = 0; _z < 4; _z++)
{
if (_tmp.shapeArray[_t][_z] != ' ')
{
if (bucket[_tmp.shapeTopLeftX +
_t][_tmp.shapeTopLeftY + _z] != ' ')
{
return false;
}
}
}
}
return true;
}
/* canEnter - Tests the direction in which a shape can enter*/
template
bool canEnter(int dir, char(&bucket)[rows][cols])
{
// Check for collisions between shapes or with the bucket
// Determining in which direction the shapes are moving
int delta_x = 0, delta_y = 0;
switch (dir)
{
case GO_DOWN:
delta_y++;
break;
case GO_LEFT:
delta_x--;
break;
case GO_RIGHT:
delta_x++;
break;
case GO_ROTATE:
return canRotate(bucket);
break;
}
// Create the starting {x, y} position to test for collision
int test_b = activeShape.shapeTopLeftX + delta_x;
int test_k = activeShape.shapeTopLeftY + delta_y;
for (int _b = 0; _b < 4; _b++)
{
for (int _k = 0; _k < 4; _k++)
{
if (activeShape.shapeArray[_b][_k] != ' ')
{
if (bucket[test_b + _b][test_k + _k] != ' ')
{
return false;
}
}
}
}
return true;
}
Solution
A)
typedef CList
IntList;
const int FIGURE_ARRAY_SIZE = 5;
class CTetrisDoc :
public
CDocument
{
protected:
CTetrisDoc();
public:
virtual ~CTetrisDoc();
void SaveScoreList();
protected:
DECLARE_MESSAGE_MAP()
DECLARE_DYNCREATE(CTetrisDoc)
virtual void Serialize(CArchive& archive);
int GetScore() const {return m_iScore;}
const IntList* GetScoreList() {return &m_scoreList;}
const ColorGrid* GetGrid() {return &m_colorGrid;}
const Figure& GetActiveFigure() const
{return m_activeFigure;}
const Figure& GetNextFigure() const {return m_nextFigure;}
void LeftArrowKey();
void RightArrowKey();
void UpArrowKey();
void DownArrowKey();
BOOL Timer();
void SpaceKey();
private:
void GameOver();
BOOL NewGame();
int AddScoreToList();
void DeleteFullRows();
BOOL IsRowFull(int iRow);
void FlashRow(int iFlashRow);
void DeleteRow(int iDeleteRow);
ColorGrid m_colorGrid;
Figure m_activeFigure, m_nextFigure;
int m_iScore;
IntList m_scoreList;
const CRect NEXT_AREA, SCORE_AREA;
static Figure m_figureArray[FIGURE_ARRAY_SIZE];
};

More Related Content

Similar to Im trying again -Okay, Im in need of some help - this is the c.pdf

ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202Mahmoud Samir Fayed
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Creating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfCreating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfShaiAlmog1
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxTashiBhutia12
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphaelPippi Labradoodle
 
Write a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdfWrite a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdfmckenziecast21211
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdfaquacosmossystems
 
How do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfHow do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfkrishnac481
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"Austin Zheng
 
Ruby-ying Javascript: Avoiding jQuery Spaghetti
Ruby-ying Javascript: Avoiding jQuery SpaghettiRuby-ying Javascript: Avoiding jQuery Spaghetti
Ruby-ying Javascript: Avoiding jQuery SpaghettiForrest Chang
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdffazilfootsteps
 

Similar to Im trying again -Okay, Im in need of some help - this is the c.pdf (20)

Include
IncludeInclude
Include
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
Graphical representation of Stack
Graphical representation of StackGraphical representation of Stack
Graphical representation of Stack
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 
Theme verdadeiro
Theme verdadeiroTheme verdadeiro
Theme verdadeiro
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Creating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfCreating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdf
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
 
Rkf
RkfRkf
Rkf
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
 
Write a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdfWrite a C++ program which generates and displays a random walk acros.pdf
Write a C++ program which generates and displays a random walk acros.pdf
 
Internal workshop es6_2015
Internal workshop es6_2015Internal workshop es6_2015
Internal workshop es6_2015
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
draw a sphere and use raytracing on the sphere in OpenGL glut. .pdf
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
How do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfHow do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdf
 
Aditazz 01-ul
Aditazz 01-ulAditazz 01-ul
Aditazz 01-ul
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"
 
Ruby-ying Javascript: Avoiding jQuery Spaghetti
Ruby-ying Javascript: Avoiding jQuery SpaghettiRuby-ying Javascript: Avoiding jQuery Spaghetti
Ruby-ying Javascript: Avoiding jQuery Spaghetti
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
 

More from eyeonsecuritysystems

For each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfFor each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfeyeonsecuritysystems
 
Explain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfExplain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfeyeonsecuritysystems
 
Explain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfExplain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfeyeonsecuritysystems
 
Explain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfExplain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfeyeonsecuritysystems
 
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfExercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfeyeonsecuritysystems
 
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfDiscussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfeyeonsecuritysystems
 
Discuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfDiscuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfeyeonsecuritysystems
 
Critique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfCritique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfeyeonsecuritysystems
 
Case Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfCase Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfeyeonsecuritysystems
 
An entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfAn entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfeyeonsecuritysystems
 
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfAssume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfeyeonsecuritysystems
 
A manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfA manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfeyeonsecuritysystems
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfeyeonsecuritysystems
 
Will a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfWill a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfeyeonsecuritysystems
 
Would you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfWould you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfeyeonsecuritysystems
 
White collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfWhite collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfeyeonsecuritysystems
 
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfWhy do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfeyeonsecuritysystems
 
Why is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfWhy is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfeyeonsecuritysystems
 
Which of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfWhich of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfeyeonsecuritysystems
 
What aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfWhat aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfeyeonsecuritysystems
 

More from eyeonsecuritysystems (20)

For each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfFor each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdf
 
Explain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfExplain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdf
 
Explain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfExplain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdf
 
Explain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfExplain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdf
 
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfExercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
 
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfDiscussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
 
Discuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfDiscuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdf
 
Critique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfCritique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdf
 
Case Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfCase Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdf
 
An entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfAn entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdf
 
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfAssume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
 
A manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfA manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdf
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
 
Will a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfWill a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdf
 
Would you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfWould you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdf
 
White collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfWhite collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdf
 
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfWhy do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
 
Why is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfWhy is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdf
 
Which of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfWhich of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdf
 
What aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfWhat aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdf
 

Recently uploaded

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

Im trying again -Okay, Im in need of some help - this is the c.pdf

  • 1. I'm trying again - Okay, I'm in need of some help - this is the code I have so far for a C++ project on Tetris that uses the Visual Studio (which is why the #stdafx.h file is in the header). I need to add to this code to complete the tasks as listed in the assignment. Here's the assignment as I recieved it, followed by the code: 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. #include "stdafx.h" #include #include #include #include using namespace std; #define GAME_INTERVAL 2 #define GO_DOWN 2 #define GO_LEFT 4 #define GO_RIGHT 6 #define GO_ROTATE 5 class TetrisShape { public: char shapeArray[4][4]; int shapeTopLeftX = 6; int shapeTopLeftY = 0; void populateShapeArray(int shape); void rotate(); template void setShape(char(&shape)[rows][cols]); TetrisShape(int shape) { populateShapeArray(shape); };
  • 2. TetrisShape() {}; }; void TetrisShape::rotate() { char _shapeArray[4][4]; _shapeArray[0][0] = shapeArray[0][3]; _shapeArray[1][0] = shapeArray[0][2]; _shapeArray[2][0] = shapeArray[0][1]; _shapeArray[3][0] = shapeArray[0][0]; _shapeArray[0][1] = shapeArray[1][3]; _shapeArray[1][1] = shapeArray[1][2]; _shapeArray[2][1] = shapeArray[1][1]; _shapeArray[3][1] = shapeArray[1][0]; _shapeArray[0][2] = shapeArray[2][3]; _shapeArray[1][2] = shapeArray[2][2]; _shapeArray[2][2] = shapeArray[2][1]; _shapeArray[3][2] = shapeArray[2][0]; _shapeArray[0][3] = shapeArray[3][3]; _shapeArray[1][3] = shapeArray[3][2]; _shapeArray[2][3] = shapeArray[3][1]; _shapeArray[3][3] = shapeArray[3][0]; for (int _s = 0; _s < 4; _s++) { for (int _a = 0; _a < 4; _a++) { shapeArray[_s][_a] = _shapeArray[_s][_a]; } } } void TetrisShape::populateShapeArray(int shape) { switch (shape) { case 1: shapeArray[0][0] = ' '; 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] = ' '; shapeArray[3][2] = ' '; shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = 'X'; shapeArray[3][3] = ' '; break; case 2:
  • 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] = ' '; break; case 3: shapeArray[0][0] = ' '; 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] = 'X'; shapeArray[3][3] = ' '; break; case 4: shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = ' '; shapeArray[3][0] = ' '; shapeArray[0][1] = ' '; shapeArray[1][1] = ' '; shapeArray[2][1] = 'X'; shapeArray[3][1] = ' '; shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = 'X'; shapeArray[3][2] = ' '; shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = ' '; shapeArray[3][3] = ' '; break; case 5: shapeArray[0][0] = ' '; shapeArray[1][0] = ' '; shapeArray[2][0] = ' '; 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] = ' ';
  • 4. shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = 'X'; shapeArray[3][3] = ' '; break; case 6: 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] = 'X'; shapeArray[2][2] = 'X'; shapeArray[3][2] = ' '; shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = 'X'; shapeArray[3][3] = ' '; break; } } int currentShape = -1; // this is the shape that is currently in play. int x[4] = { -1, -1, -1, -1 }; int y[4] = { -1, -1, -1, -1 }; // the x, y location for each of the shapes. bool isDropping = false; // gameTick globals. int currentTick = 0; template void generateBucket(char(&bucket)[rows][cols]); // create the bucket void generateShapeStream(); // shapes, in drop and in queue, constantly void dropShape(); // drop the shape bool moveShape(int direction); // GO_DOWN (falling) template bool gameTick(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols]); // handles game events template void landShape(char(&bucket)[rows][cols]); // shape hitting the bottom template void drawBucket(char(&bucket)[rows][cols]); // display bucket int getUserInput(); // gets the key pressed from the user. template bool canEnter(int direction, char(&bucket)[rows][cols]); // is space available for the block void setCursorTo(int x, int y); // set cursor to appropriate position
  • 5. int previousX = 6, previousY = 0; int shapes[256]; TetrisShape activeShape; int main() { // set 2 buckets, one permanent and one for display char bucket[12][25]; char _bucket[12][25]; int shapes[256] = {}; int shapeIndex = 0; bool gameOver = false; generateBucket(bucket); generateBucket(_bucket); generateShapeStream(); drawBucket(bucket); while (!gameOver) { gameOver = gameTick(bucket, _bucket); Sleep(500); currentTick++; } setCursorTo(25, 6); cout << "GAME OVER" << endl; system("pause"); } void setCursorTo(int x, int y) { HANDLE handle; COORD position; handle = GetStdHandle(STD_OUTPUT_HANDLE); position.X = x; position.Y = y; SetConsoleCursorPosition(handle, position); } /* generateBucket */ template
  • 6. void generateBucket(char(&bucket)[rows][cols]) { for (int w = 0; w < 12; w++) { for (int z = 0; z < 25; z++) { if (((w == 0) || (w == 11)) && (z == 0)) { bucket[w][z] = '.'; } else if (((w % 12 == 0) || (w % 12 == 11)) && ((z > 0) && (z < 24))) { bucket[w][z] = '|'; } else if (((w == 0) || (w == 11)) && (z == 24)) { bucket[w][z] = '+'; } else if (z == 24) { bucket[w][z] = '-'; } else { bucket[w][z] = ' '; } } } } /* generateShapeStream - generates the shapes preparing to fall */ void generateShapeStream() { // Initialize the random number generator srand(time(NULL)); for (int p = 0; p < 256; p++)
  • 7. { shapes[p] = rand() % 6 + 1; } } /* drawBucket -displays bucket and shapes to fall */ template void drawBucket(char(&bucket)[rows][cols]) { setCursorTo(0, 0); for (int m = 0; m < 25; m++) { for (int k = 0; k < 12; k++) { cout << bucket[k][m]; } cout << endl; } } /* gameTick - everything happening in game, and game over procedures*/ template bool gameTick(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols]) { drawBucket(bucket); if (!isDropping) { currentShape++; activeShape = TetrisShape(shapes[currentShape]); if (!canEnter(GO_DOWN, perm_bucket)) { return true; } else { isDropping = true; updateBucket(bucket, false); }
  • 8. } else { if (currentTick % GAME_INTERVAL == 1) { // we are on a drop interval. if (canEnter(GO_DOWN, perm_bucket)) { updateBucket(bucket, moveShape(GO_DOWN)); } else { landShape(perm_bucket); } } } int direction = getUserInput(); if (canEnter(direction, perm_bucket)) { updateBucket(bucket, moveShape(direction)); } if (!canEnter(GO_DOWN, perm_bucket)) { landShape(perm_bucket); } return false; } /* moveShape - handles the shape dropping down. */ bool moveShape(int direction) { previousX = activeShape.shapeTopLeftX; previousY = activeShape.shapeTopLeftY; switch (direction) { case GO_DOWN: activeShape.shapeTopLeftY++;
  • 9. return false; break; case GO_RIGHT: activeShape.shapeTopLeftX++; return false; break; case GO_LEFT: activeShape.shapeTopLeftX--; return false; break; case GO_ROTATE: activeShape.rotate(); return true; break; } } /* updateBucket - place new shape into bucket, and removing old shape*/ template void updateBucket(char(&bucket)[rows][cols], bool isRotation) { for (int _l = 0; _l < 4; _l++) { for (int _g = 0; _g < 4; _g++) { if (!isRotation) { if ((activeShape.shapeArray[_l][_g] != ' ') && (bucket[_l + previousX][_g + previousY] != '|') && (bucket[_l + previousX][_g + previousY] != '-')) { bucket[_l + previousX][_g + previousY] = ' '; } } else { if ((bucket[_l + previousX][_g + previousY] != '|') && (bucket[_l + previousX][_g + previousY] != '-'))
  • 10. { bucket[_l + previousX][_g + previousY] = ' '; } } } } for (int _l = 0; _l < 4; _l++) { for (int _g = 0; _g < 4; _g++) { if (activeShape.shapeArray[_l][_g] != ' ') { bucket[_l + activeShape.shapeTopLeftX][_g + activeShape.shapeTopLeftY] = activeShape.shapeArray[_l][_g]; } } } } /* landShape - Sets the shape in place once it hits the bottom of the bucket. Moves the shape to the permanent bucket (_bucket)*/ template void landShape(char(&bucket)[rows][cols]) { updateBucket(bucket, false); previousX = 6; previousY = 0; isDropping = false; } /* getUserInput - Reads the user input from the player*/ int getUserInput() { setCursorTo(35, 9); if ((GetKeyState(VK_DOWN) != 0) && (GetKeyState(VK_DOWN) != 1)) { return GO_DOWN; } if ((GetKeyState(VK_RIGHT) != 0) && (GetKeyState(VK_RIGHT) != 1)) { return GO_RIGHT; } if ((GetKeyState(VK_LEFT) != 0) && (GetKeyState(VK_LEFT) != 1)) { return GO_LEFT; }
  • 11. if ((GetKeyState(VK_UP) != 0) && (GetKeyState(VK_UP) != 1)) { return GO_ROTATE; } return 0; } /* canRotate - can we rotate? if we are adjacent to another shape NO! */ template bool canRotate(char(&bucket)[rows][cols]) { // creating a copy of the shape, rotating it so we can determine where in the bucket it will land. TetrisShape _tmp = TetrisShape(activeShape); _tmp.rotate(); for (int _t = 0; _t < 4; _t++) { for (int _z = 0; _z < 4; _z++) { if (_tmp.shapeArray[_t][_z] != ' ') { if (bucket[_tmp.shapeTopLeftX + _t][_tmp.shapeTopLeftY + _z] != ' ') { return false; } } } } return true; } /* canEnter - Tests the direction in which a shape can enter*/ template bool canEnter(int dir, char(&bucket)[rows][cols]) { // Check for collisions between shapes or with the bucket // Determining in which direction the shapes are moving int delta_x = 0, delta_y = 0; switch (dir)
  • 12. { case GO_DOWN: delta_y++; break; case GO_LEFT: delta_x--; break; case GO_RIGHT: delta_x++; break; case GO_ROTATE: return canRotate(bucket); break; } // Create the starting {x, y} position to test for collision int test_b = activeShape.shapeTopLeftX + delta_x; int test_k = activeShape.shapeTopLeftY + delta_y; for (int _b = 0; _b < 4; _b++) { for (int _k = 0; _k < 4; _k++) { if (activeShape.shapeArray[_b][_k] != ' ') { if (bucket[test_b + _b][test_k + _k] != ' ') { return false; } } } } return true; } Solution A)
  • 13. typedef CList IntList; const int FIGURE_ARRAY_SIZE = 5; class CTetrisDoc : public CDocument { protected: CTetrisDoc(); public: virtual ~CTetrisDoc(); void SaveScoreList(); protected: DECLARE_MESSAGE_MAP() DECLARE_DYNCREATE(CTetrisDoc) virtual void Serialize(CArchive& archive); int GetScore() const {return m_iScore;} const IntList* GetScoreList() {return &m_scoreList;} const ColorGrid* GetGrid() {return &m_colorGrid;} const Figure& GetActiveFigure() const {return m_activeFigure;} const Figure& GetNextFigure() const {return m_nextFigure;} void LeftArrowKey(); void RightArrowKey(); void UpArrowKey(); void DownArrowKey(); BOOL Timer(); void SpaceKey(); private: void GameOver(); BOOL NewGame(); int AddScoreToList(); void DeleteFullRows(); BOOL IsRowFull(int iRow); void FlashRow(int iFlashRow); void DeleteRow(int iDeleteRow);
  • 14. ColorGrid m_colorGrid; Figure m_activeFigure, m_nextFigure; int m_iScore; IntList m_scoreList; const CRect NEXT_AREA, SCORE_AREA; static Figure m_figureArray[FIGURE_ARRAY_SIZE]; };