SlideShare a Scribd company logo
i need an input of this program. anything good or bad. what
could be changed, what you may like or dislike about it. only
one paragraph.
// newTetris.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include
#include
#include
#include
#define GAME_INTERVAL 20
#define DIR_DOWN 2
#define DIR_LEFT 4
#define DIR_RIGHT 6
#define DIR_ROTATE 5
using namespace std;
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 _x = 0; _x < 4; _x++) {
for (int _y = 0; _y < 4; _y++) {
shapeArray[_x][_y] = _shapeArray[_x][_y];
}
}
}
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 score = 0;
int currentShape = -1; // this is going to represent the
shape that is currently in play.
bool isDropping = false; // global that defines if a piece
is currently falling - mainly for gameTick function.
int currentTick = 0;
template
void generateBucket(char(&bucket)[rows][cols]); // Creates
a slightly pre-filled bucket.
void generateShapeStream(); // Generate a stream of shapes.
void dropShape(); // Draw the shape top/center.
bool moveShape(int direction); // Move the shape in the
spec. dir.
template
bool gameTick(char(&bucket)[rows][cols],
char(&perm_bucket)[rows][cols]); // Handles what
is going on in the game every second.
template
void landShape(char(&bucket)[rows][cols]); //
What to do when the shape hits the bottom.
template
int checkScore(char(&bucket)[rows][cols],
char(&perm_bucket)[rows][cols], int tempvar, int score);
template
void drawBucket(char(&bucket)[rows][cols]); //
Draws the current contents of the bucket.
template
bool canEnter(int direction, char(&bucket)[rows][cols]);
// Checks if the shape can enter the space it is trying to drop
into.
int getUserInput(); // gets the key pressed from the
user.
void setCursorTo(int x, int y);// Move the cursor to the
appropriate position
int previousX = 6, previousY = 0;
int shapes[256];
template
int check_bucket(char(&bucket)[rows][cols]);
template
void set_bucket(char(&bucket)[rows][cols],
char(&perm_bucket)[rows][cols]);
TetrisShape activeShape;
int main() {
// Two bucket arrays, one shown on the screen, the other with
the permanent contents of the buckets (walls and any non-
moving shapes)
char bucket[12][25];
int score = 0;
int tempvar = 0;
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(50);
checkScore(bucket, _bucket, tempvar, score);
cout << "Your Score is: " << score << endl;
currentTick++;
}
setCursorTo(25, 6);
cout << "GAME OVER";
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 - takes a bucket array of any size and
* creates a semi-empty bucket, with a
* few random shapes in the bottom few lines. */
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 a pre-determined list of
* shapes that will fall from the sky. */
void generateShapeStream() {
// Initialize the random number generator
srand(time(NULL));
for (int i = 0; i < 256; i++) {
shapes[i] = rand() % 6 + 1;
}
//cout << "In generate shape..." << endl;
}
/* drawBucket - draws the actual bucket on the screen
* including the currently dropping shape. */
template
void drawBucket(char(&bucket)[rows][cols]) {
setCursorTo(0, 0);
for (int w = 0; w < 25; w++) {
for (int z = 0; z < 12; z++) {
cout << bucket[z][w];
}
cout << endl;
}
}
/* gameTick - this function does all of the different
* processessing that happens throughout
* the game.This also returns false to
* stop the main loop once gameover has
* been reached*/
template
bool gameTick(char(&bucket)[rows][cols],
char(&perm_bucket)[rows][cols]) {
drawBucket(bucket);
if (!isDropping) {
currentShape++;
activeShape = TetrisShape(shapes[currentShape]);
if (!canEnter(DIR_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(DIR_DOWN, perm_bucket)) {
updateBucket(bucket, moveShape(DIR_DOWN));
}
else {
landShape(perm_bucket);
}
}
}
int direction = getUserInput();
if (canEnter(direction, perm_bucket)) {
updateBucket(bucket, moveShape(direction));
}
if (!canEnter(DIR_DOWN, perm_bucket)) {
landShape(perm_bucket);
set_bucket(bucket, perm_bucket);
}
return false;
}
/* moveShape - Handles moving the shape in the bucket. */
bool moveShape(int direction) {
previousX = activeShape.shapeTopLeftX;
previousY = activeShape.shapeTopLeftY;
switch (direction) {
case DIR_DOWN:
activeShape.shapeTopLeftY++;
return false;
break;
case DIR_RIGHT:
activeShape.shapeTopLeftX++;
return false;
break;
case DIR_LEFT:
activeShape.shapeTopLeftX--;
return false;
break;
case DIR_ROTATE:
activeShape.rotate();
return true;
break;
}
}
/* updateBucket - place the cureret shape in the bucket, remove
the old shape*/
template
void updateBucket(char(&bucket)[rows][cols], bool isRotation)
{
for (int _x = 0; _x < 4; _x++) {
for (int _y = 0; _y < 4; _y++) {
if (!isRotation) {
if ((activeShape.shapeArray[_x][_y] != ' ') && (bucket[_x +
previousX][_y + previousY] != '|') && (bucket[_x +
previousX][_y + previousY] != '-')) {
bucket[_x + previousX][_y + previousY] = ' ';
}
}
else {
if ((bucket[_x + previousX][_y + previousY] != '|') &&
(bucket[_x + previousX][_y + previousY] != '-')) {
bucket[_x + previousX][_y + previousY] = ' ';
}
}
}
}
for (int _x = 0; _x < 4; _x++) {
for (int _y = 0; _y < 4; _y++) {
if (activeShape.shapeArray[_x][_y] != ' ') {
bucket[_x + activeShape.shapeTopLeftX][_y +
activeShape.shapeTopLeftY] = activeShape.shapeArray[_x][_y];
}
}
}
}
/* 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;
check_bucket(bucket);
isDropping = false;
}
template
int checkScore(char(&bucket)[rows][cols],
char(&perm_bucket)[rows][cols], int tempvar, int score)
{
for (int y = 0; y < 25; y++) {
int tmp_count = 0;
for (int x = 0; x < 13; x++) {
if (bucket[x][y] == 'X') {
tmp_count++;
}
}
if (tmp_count == 10) {
tempvar = 1;
if (tempvar == 1) {
score = score + 100;
return score;
}
}
}
}
/* getUserInput - Reads the user input from the player*/
int getUserInput() {
setCursorTo(35, 9);
if ((GetKeyState(VK_DOWN) != 0) &&
(GetKeyState(VK_DOWN) != 1)) { return DIR_DOWN; }
if ((GetKeyState(VK_RIGHT) != 0) &&
(GetKeyState(VK_RIGHT) != 1)) { return DIR_RIGHT; }
if ((GetKeyState(VK_LEFT) != 0) &&
(GetKeyState(VK_LEFT) != 1)) { return DIR_LEFT; }
if ((GetKeyState(VK_UP) != 0) && (GetKeyState(VK_UP) !=
1)) { return DIR_ROTATE; }
return 0;
}
/* canRotate - if we are adjacent to another shape, then we
CANNOT rotate */
template
bool canRotate(char(&bucket)[rows][cols]) {
// The only real way to do this is to create a copy of the shape,
rotate it, then try to determine where it will be in the bucket.
TetrisShape _tmp = TetrisShape(activeShape);
_tmp.rotate();
for (int _x = 0; _x < 4; _x++) {
for (int _y = 0; _y < 4; _y++) {
if (_tmp.shapeArray[_x][_y] != ' ') {
if (bucket[_tmp.shapeTopLeftX + _x][_tmp.shapeTopLeftY +
_y] != ' ') {
return false;
}
}
}
}
return true;
}
/* canEnter - Tests to see if the falling blocks can
enter in any direction.*/
template
bool canEnter(int dir, char(&bucket)[rows][cols]) {
// Check for collision with any elements of the shape array, and
any elements of the bucket.
// Determine which direction we are moving.
int delta_x = 0, delta_y = 0;
switch (dir) {
case DIR_DOWN:
delta_y++;
break;
case DIR_LEFT:
delta_x--;
break;
case DIR_RIGHT:
delta_x++;
break;
case DIR_ROTATE:
return canRotate(bucket);
break;
}
// Create the starting {x, y} position to test for collsion
int test_x = activeShape.shapeTopLeftX + delta_x;
int test_y = activeShape.shapeTopLeftY + delta_y;
for (int _x = 0; _x < 4; _x++) {
for (int _y = 0; _y < 4; _y++) {
if (activeShape.shapeArray[_x][_y] != ' ') {
if (bucket[test_x + _x][test_y + _y] != ' ') {
return false;
}
}
}
}
return true;
}
template
int checkScore(char(&bucket)[rows][cols], int tempvar, int
score) {
for (int y = 0; y < 25; y++) {
int tmp_count = 0;
for (int x = 0; x < 13; x++) {
if (bucket[x][y] == 'X') {
tmp_count++;
}
}
if (tmp_count == 10) {
tempvar = 1;
if (tempvar == 1) {
score = score + 100;
return score;
}
for (int x = 1; x < 11; x++) {
for (int _y = y; _y > 0; _y--) {
bucket[x][_y] = bucket[x][_y - 1];
}
}
}
}
}
template
void check_bucket(char(&bucket)[rows][cols]) {
for (int y = 0; y < 25; y++) {
int tmp_count = 0;
for (int x = 0; x < 13; x++) {
if (bucket[x][y] == 'X') {
tmp_count++;
}
}
if (tmp_count == 10) {
for (int x = 1; x < 11; x++) {
for (int _y = y; _y > 0; _y--) {
bucket[x][_y] = bucket[x][_y - 1];
}
}
}
}
}
template
void set_bucket(char(&bucket)[rows][cols],
char(&perm_bucket)[rows][cols]) {
for (int x = 0; x < 12; x++) {
for (int y = 0; y < 25; y++) {
bucket[x][y] = perm_bucket[x][y];
}
}
}

More Related Content

Similar to i need an input of this program.  anything good or bad.  what could .docx

i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
armcomputers
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
Kevin Hoyt
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
Manoj Kumar
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
Jenchoke Tachagomain
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
Jenchoke Tachagomain
 
Ass2 1 (2)
Ass2 1 (2)Ass2 1 (2)
Ass2 1 (2)
vacbalolenvadi90
 
Internal workshop es6_2015
Internal workshop es6_2015Internal workshop es6_2015
Internal workshop es6_2015
Miguel Ruiz Rodriguez
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
Maja Kraljič
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
poblettesedanoree498
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
fonecomp
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
Jason Yeo Jie Shun
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
eyelineoptics
 
c++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdfc++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdf
apexjaipur
 
Theme verdadeiro
Theme verdadeiroTheme verdadeiro
Theme verdadeiro
Izabelly Souza
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
anjandavid
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
annetnash8266
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
contact41
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding class
Jonah Marrs
 
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
ShaiAlmog1
 

Similar to i need an input of this program.  anything good or bad.  what could .docx (20)

i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 
Ass2 1 (2)
Ass2 1 (2)Ass2 1 (2)
Ass2 1 (2)
 
Internal workshop es6_2015
Internal workshop es6_2015Internal workshop es6_2015
Internal workshop es6_2015
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
c++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdfc++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdf
 
Theme verdadeiro
Theme verdadeiroTheme verdadeiro
Theme verdadeiro
 
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdfIn Java using Eclipse, Im suppose to write a class that encapsulat.pdf
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding class
 
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
 

More from ursabrooks36447

Assignment 3 Email Based on Listening Skills ScenarioMonica.docx
Assignment 3 Email Based on Listening Skills ScenarioMonica.docxAssignment 3 Email Based on Listening Skills ScenarioMonica.docx
Assignment 3 Email Based on Listening Skills ScenarioMonica.docx
ursabrooks36447
 
Assignment 3 Elastic and Inelastic TrafficWrite a three to four.docx
Assignment 3 Elastic and Inelastic TrafficWrite a three to four.docxAssignment 3 Elastic and Inelastic TrafficWrite a three to four.docx
Assignment 3 Elastic and Inelastic TrafficWrite a three to four.docx
ursabrooks36447
 
Assignment 3 Defining Social Justice Social justice has been .docx
Assignment 3 Defining Social Justice Social justice has been .docxAssignment 3 Defining Social Justice Social justice has been .docx
Assignment 3 Defining Social Justice Social justice has been .docx
ursabrooks36447
 
Assignment 3 Discussion QuestionsYour facilitator will guide yo.docx
Assignment 3 Discussion QuestionsYour facilitator will guide yo.docxAssignment 3 Discussion QuestionsYour facilitator will guide yo.docx
Assignment 3 Discussion QuestionsYour facilitator will guide yo.docx
ursabrooks36447
 
Assignment 3 Direct ManipulationDue Week 8 and worth 80 points.docx
Assignment 3 Direct ManipulationDue Week 8 and worth 80 points.docxAssignment 3 Direct ManipulationDue Week 8 and worth 80 points.docx
Assignment 3 Direct ManipulationDue Week 8 and worth 80 points.docx
ursabrooks36447
 
Assignment 3 Defining Social JusticeSocial justice has been defin.docx
Assignment 3 Defining Social JusticeSocial justice has been defin.docxAssignment 3 Defining Social JusticeSocial justice has been defin.docx
Assignment 3 Defining Social JusticeSocial justice has been defin.docx
ursabrooks36447
 
Assignment 3 Data SourcesFor this assignment, you will explore th.docx
Assignment 3 Data SourcesFor this assignment, you will explore th.docxAssignment 3 Data SourcesFor this assignment, you will explore th.docx
Assignment 3 Data SourcesFor this assignment, you will explore th.docx
ursabrooks36447
 
Assignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docx
Assignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docxAssignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docx
Assignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docx
ursabrooks36447
 
Assignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docx
Assignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docxAssignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docx
Assignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docx
ursabrooks36447
 
Assignment 3 Corrections Case StudyDue Week 10 and worth .docx
Assignment 3 Corrections Case StudyDue Week 10 and worth .docxAssignment 3 Corrections Case StudyDue Week 10 and worth .docx
Assignment 3 Corrections Case StudyDue Week 10 and worth .docx
ursabrooks36447
 
Assignment 3 Chapter 6 The Communication ProcessAssignment #3.docx
Assignment 3 Chapter 6 The Communication ProcessAssignment #3.docxAssignment 3 Chapter 6 The Communication ProcessAssignment #3.docx
Assignment 3 Chapter 6 The Communication ProcessAssignment #3.docx
ursabrooks36447
 
Assignment 3 Areas of SpecializationThere are many wonderful oppo.docx
Assignment 3 Areas of SpecializationThere are many wonderful oppo.docxAssignment 3 Areas of SpecializationThere are many wonderful oppo.docx
Assignment 3 Areas of SpecializationThere are many wonderful oppo.docx
ursabrooks36447
 
Assignment 3 Bill of RightsWhen the Constitution was completed in.docx
Assignment 3 Bill of RightsWhen the Constitution was completed in.docxAssignment 3 Bill of RightsWhen the Constitution was completed in.docx
Assignment 3 Bill of RightsWhen the Constitution was completed in.docx
ursabrooks36447
 
Assignment 3 Bill of Rights When the Constitution was completed i.docx
Assignment 3 Bill of Rights When the Constitution was completed i.docxAssignment 3 Bill of Rights When the Constitution was completed i.docx
Assignment 3 Bill of Rights When the Constitution was completed i.docx
ursabrooks36447
 
Assignment 3 Assault, Battery, and Crimes against PersonsRe.docx
Assignment 3 Assault, Battery, and Crimes against PersonsRe.docxAssignment 3 Assault, Battery, and Crimes against PersonsRe.docx
Assignment 3 Assault, Battery, and Crimes against PersonsRe.docx
ursabrooks36447
 
Assignment 3 Annual Review and Create yourAssignment 3 Annua.docx
Assignment 3 Annual Review and Create yourAssignment 3 Annua.docxAssignment 3 Annual Review and Create yourAssignment 3 Annua.docx
Assignment 3 Annual Review and Create yourAssignment 3 Annua.docx
ursabrooks36447
 
Assignment 3 America as a Superpower For History 105 Dr..docx
Assignment 3 America as a Superpower For History 105 Dr..docxAssignment 3 America as a Superpower For History 105 Dr..docx
Assignment 3 America as a Superpower For History 105 Dr..docx
ursabrooks36447
 
Assignment 3 (Hypotheses, Methods, and Measurements) Name ______.docx
Assignment 3 (Hypotheses, Methods, and Measurements) Name ______.docxAssignment 3 (Hypotheses, Methods, and Measurements) Name ______.docx
Assignment 3 (Hypotheses, Methods, and Measurements) Name ______.docx
ursabrooks36447
 
Assignment 3 10 Cs for Writing Effectively Review the ema.docx
Assignment 3 10 Cs for Writing Effectively Review the ema.docxAssignment 3 10 Cs for Writing Effectively Review the ema.docx
Assignment 3 10 Cs for Writing Effectively Review the ema.docx
ursabrooks36447
 
Assignment 3 - Information Systems Concepts  2 pages of disc.docx
Assignment 3 - Information Systems Concepts  2 pages of disc.docxAssignment 3 - Information Systems Concepts  2 pages of disc.docx
Assignment 3 - Information Systems Concepts  2 pages of disc.docx
ursabrooks36447
 

More from ursabrooks36447 (20)

Assignment 3 Email Based on Listening Skills ScenarioMonica.docx
Assignment 3 Email Based on Listening Skills ScenarioMonica.docxAssignment 3 Email Based on Listening Skills ScenarioMonica.docx
Assignment 3 Email Based on Listening Skills ScenarioMonica.docx
 
Assignment 3 Elastic and Inelastic TrafficWrite a three to four.docx
Assignment 3 Elastic and Inelastic TrafficWrite a three to four.docxAssignment 3 Elastic and Inelastic TrafficWrite a three to four.docx
Assignment 3 Elastic and Inelastic TrafficWrite a three to four.docx
 
Assignment 3 Defining Social Justice Social justice has been .docx
Assignment 3 Defining Social Justice Social justice has been .docxAssignment 3 Defining Social Justice Social justice has been .docx
Assignment 3 Defining Social Justice Social justice has been .docx
 
Assignment 3 Discussion QuestionsYour facilitator will guide yo.docx
Assignment 3 Discussion QuestionsYour facilitator will guide yo.docxAssignment 3 Discussion QuestionsYour facilitator will guide yo.docx
Assignment 3 Discussion QuestionsYour facilitator will guide yo.docx
 
Assignment 3 Direct ManipulationDue Week 8 and worth 80 points.docx
Assignment 3 Direct ManipulationDue Week 8 and worth 80 points.docxAssignment 3 Direct ManipulationDue Week 8 and worth 80 points.docx
Assignment 3 Direct ManipulationDue Week 8 and worth 80 points.docx
 
Assignment 3 Defining Social JusticeSocial justice has been defin.docx
Assignment 3 Defining Social JusticeSocial justice has been defin.docxAssignment 3 Defining Social JusticeSocial justice has been defin.docx
Assignment 3 Defining Social JusticeSocial justice has been defin.docx
 
Assignment 3 Data SourcesFor this assignment, you will explore th.docx
Assignment 3 Data SourcesFor this assignment, you will explore th.docxAssignment 3 Data SourcesFor this assignment, you will explore th.docx
Assignment 3 Data SourcesFor this assignment, you will explore th.docx
 
Assignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docx
Assignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docxAssignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docx
Assignment 3 Cultural Activity ReportDue Week 10 and worth 100 po.docx
 
Assignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docx
Assignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docxAssignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docx
Assignment 3 Colin Powell’s Leadership Lessons PaperBy Frid.docx
 
Assignment 3 Corrections Case StudyDue Week 10 and worth .docx
Assignment 3 Corrections Case StudyDue Week 10 and worth .docxAssignment 3 Corrections Case StudyDue Week 10 and worth .docx
Assignment 3 Corrections Case StudyDue Week 10 and worth .docx
 
Assignment 3 Chapter 6 The Communication ProcessAssignment #3.docx
Assignment 3 Chapter 6 The Communication ProcessAssignment #3.docxAssignment 3 Chapter 6 The Communication ProcessAssignment #3.docx
Assignment 3 Chapter 6 The Communication ProcessAssignment #3.docx
 
Assignment 3 Areas of SpecializationThere are many wonderful oppo.docx
Assignment 3 Areas of SpecializationThere are many wonderful oppo.docxAssignment 3 Areas of SpecializationThere are many wonderful oppo.docx
Assignment 3 Areas of SpecializationThere are many wonderful oppo.docx
 
Assignment 3 Bill of RightsWhen the Constitution was completed in.docx
Assignment 3 Bill of RightsWhen the Constitution was completed in.docxAssignment 3 Bill of RightsWhen the Constitution was completed in.docx
Assignment 3 Bill of RightsWhen the Constitution was completed in.docx
 
Assignment 3 Bill of Rights When the Constitution was completed i.docx
Assignment 3 Bill of Rights When the Constitution was completed i.docxAssignment 3 Bill of Rights When the Constitution was completed i.docx
Assignment 3 Bill of Rights When the Constitution was completed i.docx
 
Assignment 3 Assault, Battery, and Crimes against PersonsRe.docx
Assignment 3 Assault, Battery, and Crimes against PersonsRe.docxAssignment 3 Assault, Battery, and Crimes against PersonsRe.docx
Assignment 3 Assault, Battery, and Crimes against PersonsRe.docx
 
Assignment 3 Annual Review and Create yourAssignment 3 Annua.docx
Assignment 3 Annual Review and Create yourAssignment 3 Annua.docxAssignment 3 Annual Review and Create yourAssignment 3 Annua.docx
Assignment 3 Annual Review and Create yourAssignment 3 Annua.docx
 
Assignment 3 America as a Superpower For History 105 Dr..docx
Assignment 3 America as a Superpower For History 105 Dr..docxAssignment 3 America as a Superpower For History 105 Dr..docx
Assignment 3 America as a Superpower For History 105 Dr..docx
 
Assignment 3 (Hypotheses, Methods, and Measurements) Name ______.docx
Assignment 3 (Hypotheses, Methods, and Measurements) Name ______.docxAssignment 3 (Hypotheses, Methods, and Measurements) Name ______.docx
Assignment 3 (Hypotheses, Methods, and Measurements) Name ______.docx
 
Assignment 3 10 Cs for Writing Effectively Review the ema.docx
Assignment 3 10 Cs for Writing Effectively Review the ema.docxAssignment 3 10 Cs for Writing Effectively Review the ema.docx
Assignment 3 10 Cs for Writing Effectively Review the ema.docx
 
Assignment 3 - Information Systems Concepts  2 pages of disc.docx
Assignment 3 - Information Systems Concepts  2 pages of disc.docxAssignment 3 - Information Systems Concepts  2 pages of disc.docx
Assignment 3 - Information Systems Concepts  2 pages of disc.docx
 

Recently uploaded

C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 

Recently uploaded (20)

C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 

i need an input of this program.  anything good or bad.  what could .docx

  • 1. i need an input of this program. anything good or bad. what could be changed, what you may like or dislike about it. only one paragraph. // newTetris.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #define GAME_INTERVAL 20 #define DIR_DOWN 2 #define DIR_LEFT 4 #define DIR_RIGHT 6 #define DIR_ROTATE 5 using namespace std; 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() {};
  • 2. }; 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 _x = 0; _x < 4; _x++) { for (int _y = 0; _y < 4; _y++) { shapeArray[_x][_y] = _shapeArray[_x][_y]; } } } 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] = ' ';
  • 3. 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] = ' ';
  • 4. 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 score = 0; int currentShape = -1; // this is going to represent the shape that is currently in play. bool isDropping = false; // global that defines if a piece is currently falling - mainly for gameTick function. int currentTick = 0; template void generateBucket(char(&bucket)[rows][cols]); // Creates a slightly pre-filled bucket. void generateShapeStream(); // Generate a stream of shapes. void dropShape(); // Draw the shape top/center. bool moveShape(int direction); // Move the shape in the spec. dir. template bool gameTick(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols]); // Handles what
  • 5. is going on in the game every second. template void landShape(char(&bucket)[rows][cols]); // What to do when the shape hits the bottom. template int checkScore(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols], int tempvar, int score); template void drawBucket(char(&bucket)[rows][cols]); // Draws the current contents of the bucket. template bool canEnter(int direction, char(&bucket)[rows][cols]); // Checks if the shape can enter the space it is trying to drop into. int getUserInput(); // gets the key pressed from the user. void setCursorTo(int x, int y);// Move the cursor to the appropriate position int previousX = 6, previousY = 0; int shapes[256]; template int check_bucket(char(&bucket)[rows][cols]); template void set_bucket(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols]); TetrisShape activeShape; int main() { // Two bucket arrays, one shown on the screen, the other with the permanent contents of the buckets (walls and any non- moving shapes) char bucket[12][25]; int score = 0; int tempvar = 0;
  • 6. 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(50); checkScore(bucket, _bucket, tempvar, score); cout << "Your Score is: " << score << endl; currentTick++; } setCursorTo(25, 6); cout << "GAME OVER"; 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); }
  • 7. /* generateBucket - takes a bucket array of any size and * creates a semi-empty bucket, with a * few random shapes in the bottom few lines. */ 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 a pre-determined list of * shapes that will fall from the sky. */ void generateShapeStream() { // Initialize the random number generator srand(time(NULL)); for (int i = 0; i < 256; i++) { shapes[i] = rand() % 6 + 1; } //cout << "In generate shape..." << endl; } /* drawBucket - draws the actual bucket on the screen * including the currently dropping shape. */ template void drawBucket(char(&bucket)[rows][cols]) { setCursorTo(0, 0);
  • 8. for (int w = 0; w < 25; w++) { for (int z = 0; z < 12; z++) { cout << bucket[z][w]; } cout << endl; } } /* gameTick - this function does all of the different * processessing that happens throughout * the game.This also returns false to * stop the main loop once gameover has * been reached*/ template bool gameTick(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols]) { drawBucket(bucket); if (!isDropping) { currentShape++; activeShape = TetrisShape(shapes[currentShape]); if (!canEnter(DIR_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(DIR_DOWN, perm_bucket)) {
  • 9. updateBucket(bucket, moveShape(DIR_DOWN)); } else { landShape(perm_bucket); } } } int direction = getUserInput(); if (canEnter(direction, perm_bucket)) { updateBucket(bucket, moveShape(direction)); } if (!canEnter(DIR_DOWN, perm_bucket)) { landShape(perm_bucket); set_bucket(bucket, perm_bucket); } return false; } /* moveShape - Handles moving the shape in the bucket. */ bool moveShape(int direction) { previousX = activeShape.shapeTopLeftX; previousY = activeShape.shapeTopLeftY; switch (direction) { case DIR_DOWN: activeShape.shapeTopLeftY++; return false; break; case DIR_RIGHT: activeShape.shapeTopLeftX++; return false;
  • 10. break; case DIR_LEFT: activeShape.shapeTopLeftX--; return false; break; case DIR_ROTATE: activeShape.rotate(); return true; break; } } /* updateBucket - place the cureret shape in the bucket, remove the old shape*/ template void updateBucket(char(&bucket)[rows][cols], bool isRotation) { for (int _x = 0; _x < 4; _x++) { for (int _y = 0; _y < 4; _y++) { if (!isRotation) { if ((activeShape.shapeArray[_x][_y] != ' ') && (bucket[_x + previousX][_y + previousY] != '|') && (bucket[_x + previousX][_y + previousY] != '-')) { bucket[_x + previousX][_y + previousY] = ' '; } } else { if ((bucket[_x + previousX][_y + previousY] != '|') && (bucket[_x + previousX][_y + previousY] != '-')) { bucket[_x + previousX][_y + previousY] = ' '; } } } } for (int _x = 0; _x < 4; _x++) {
  • 11. for (int _y = 0; _y < 4; _y++) { if (activeShape.shapeArray[_x][_y] != ' ') { bucket[_x + activeShape.shapeTopLeftX][_y + activeShape.shapeTopLeftY] = activeShape.shapeArray[_x][_y]; } } } } /* 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; check_bucket(bucket); isDropping = false; } template int checkScore(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols], int tempvar, int score) { for (int y = 0; y < 25; y++) { int tmp_count = 0; for (int x = 0; x < 13; x++) { if (bucket[x][y] == 'X') { tmp_count++; }
  • 12. } if (tmp_count == 10) { tempvar = 1; if (tempvar == 1) { score = score + 100; return score; } } } } /* getUserInput - Reads the user input from the player*/ int getUserInput() { setCursorTo(35, 9); if ((GetKeyState(VK_DOWN) != 0) && (GetKeyState(VK_DOWN) != 1)) { return DIR_DOWN; } if ((GetKeyState(VK_RIGHT) != 0) && (GetKeyState(VK_RIGHT) != 1)) { return DIR_RIGHT; } if ((GetKeyState(VK_LEFT) != 0) && (GetKeyState(VK_LEFT) != 1)) { return DIR_LEFT; } if ((GetKeyState(VK_UP) != 0) && (GetKeyState(VK_UP) != 1)) { return DIR_ROTATE; } return 0; } /* canRotate - if we are adjacent to another shape, then we CANNOT rotate */ template bool canRotate(char(&bucket)[rows][cols]) { // The only real way to do this is to create a copy of the shape, rotate it, then try to determine where it will be in the bucket. TetrisShape _tmp = TetrisShape(activeShape); _tmp.rotate();
  • 13. for (int _x = 0; _x < 4; _x++) { for (int _y = 0; _y < 4; _y++) { if (_tmp.shapeArray[_x][_y] != ' ') { if (bucket[_tmp.shapeTopLeftX + _x][_tmp.shapeTopLeftY + _y] != ' ') { return false; } } } } return true; } /* canEnter - Tests to see if the falling blocks can enter in any direction.*/ template bool canEnter(int dir, char(&bucket)[rows][cols]) { // Check for collision with any elements of the shape array, and any elements of the bucket. // Determine which direction we are moving. int delta_x = 0, delta_y = 0; switch (dir) { case DIR_DOWN: delta_y++; break; case DIR_LEFT: delta_x--; break; case DIR_RIGHT: delta_x++; break; case DIR_ROTATE: return canRotate(bucket); break;
  • 14. } // Create the starting {x, y} position to test for collsion int test_x = activeShape.shapeTopLeftX + delta_x; int test_y = activeShape.shapeTopLeftY + delta_y; for (int _x = 0; _x < 4; _x++) { for (int _y = 0; _y < 4; _y++) { if (activeShape.shapeArray[_x][_y] != ' ') { if (bucket[test_x + _x][test_y + _y] != ' ') { return false; } } } } return true; } template int checkScore(char(&bucket)[rows][cols], int tempvar, int score) { for (int y = 0; y < 25; y++) { int tmp_count = 0; for (int x = 0; x < 13; x++) { if (bucket[x][y] == 'X') { tmp_count++; } } if (tmp_count == 10) { tempvar = 1; if (tempvar == 1) { score = score + 100; return score; } for (int x = 1; x < 11; x++) { for (int _y = y; _y > 0; _y--) {
  • 15. bucket[x][_y] = bucket[x][_y - 1]; } } } } } template void check_bucket(char(&bucket)[rows][cols]) { for (int y = 0; y < 25; y++) { int tmp_count = 0; for (int x = 0; x < 13; x++) { if (bucket[x][y] == 'X') { tmp_count++; } } if (tmp_count == 10) { for (int x = 1; x < 11; x++) { for (int _y = y; _y > 0; _y--) { bucket[x][_y] = bucket[x][_y - 1]; } } } } } template void set_bucket(char(&bucket)[rows][cols], char(&perm_bucket)[rows][cols]) { for (int x = 0; x < 12; x++) {
  • 16. for (int y = 0; y < 25; y++) { bucket[x][y] = perm_bucket[x][y]; } } }