Hi, I am working on tetris project and I am having problem with my code program
ID: 3770023 • Letter: H
Question
Hi,
I am working on tetris project and I am having problem with my code program and I was wondering if someone could help me compile it with no error.
I can someone help me create a good functioning tetris game that can show the score and that can make the user rotate the blocks and build up the blocks properly all the way top of the gride line??
#include "stdafx.h"
#include <iostream>
#include "windows.h"
#include <ctime>
using namespace std;
using namespace std;
//console width height
const int WIDTH = 400;
const int HEIGHT = 400;
//bucket row and column size
const int buckHeight = 25;
const int buckWidth = 12;
//bucket array
char bucket[buckHeight][buckWidth];
void initializeBucket();
void displayBucket();
void setCursorTo(int x, int y);
void userInput();
void moveShape();
void shapeDrop();
void clearRow();
void score();
void beginGame();
void endGame();
int main()
{
int score = 0;
char playAgain;
//this is my working game loop, keeps replaying until n is entered
cout << " Welcome to Tetris!!! Would you like to play? (y/n): ";
cin >> playAgain;
while ((playAgain != 'y') && (playAgain != 'n'))
{
cout << " Please enter y or n: ";
cin >> playAgain;
}
if (playAgain == 'y')
{
//rand for shape
srand(static_cast<unsigned int>(time(0)));
int shapeType = rand() % 7;
while (playAgain == 'y')
{
displayBucket();
setCursorTo(0, 0);
beginGame();
cout << " Would you like to play again? (y/n): ";
cin >> playAgain;
while ((playAgain != 'y') && (playAgain != 'n'))
{
cout << " Please enter y or n: ";
cin >> playAgain;
}
}
}
else
system("pause");
return 0;
}
void setCursorTo(int x, int y)
{
HANDLE handle;
COORD position;
handle = GetStdHandle(STD_OUTPUT_HANDLE);
position.X = x;
position.Y = y;
SetConsoleCursorPosition(handle, position);
}
void beginGame()
{
//this function calls the gameplay functions
//each function here is what keeps the shapes moving and user playing
userInput();
moveShape();
shapeDrop();
clearRow();
endGame();
}
void displayBucket()
{
setCursorTo(0, 1);
initializeBucket();
for (int i = 0; i < buckHeight; i++) {
for (int j = 0; j < buckWidth; j++) {
cout << bucket[i][j];
if (j == 11) cout << endl;
}
}
}
void initializeBucket()
{
for (int i = 0; i < buckHeight; i++) {
for (int j = 0; j < buckWidth; j++) {
if (j == 0 || j == 11 || i == 24) {
bucket[i][j] = '#';
}
else if (bucket[i][j] == 'X') {
continue;
}
else {
bucket[i][j] = ' ';
}
}
}
}
class TetrisShape {
public:
int shapeTopLeftX;
int shapeTopLeftY;
TetrisShape() {
shapeTopLeftX = 6;
shapeTopLeftY = 0;
}
char shapeArray[4][4];
void populateShapeArray(int shapeType) {
switch (shapeType) {
case 1:
shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = 'X'; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
break;
case 2:
shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = 'X'; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
break;
case 3:
shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = 'X'; shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = 'X'; shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
break;
case 4:
shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = 'X'; shapeArray[3][0] = ' ';
shapeArray[0][1] = 'X'; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
break;
case 5:
shapeArray[0][0] = 'X'; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = 'X'; shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = ' '; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
break;
case 6:
shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
shapeArray[0][2] = 'X'; shapeArray[1][2] = 'X'; shapeArray[2][2] = ' '; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
break;
}
}
};
void userInput(char shapeType)
{
char shapeArray[4][4];
char mvDir; // Move Direction
//user presses keys to flip/move shape
cout << " User moves shape" << endl;
cout << "Please enter move direction: L = left, R = right, U = Up, D = Down ";
cin >> mvDir;
switch (mvDir) {
case 'L':
shapeArray[0][0] = ' '; shapeArray[1][0] = 'X'; shapeArray[2][0] = ' '; shapeArray[3][0] = ' ';
shapeArray[0][1] = ' '; shapeArray[1][1] = 'X'; shapeArray[2][1] = ' '; shapeArray[3][1] = ' ';
shapeArray[0][2] = ' '; shapeArray[1][2] = 'X'; shapeArray[2][2] = 'X'; shapeArray[3][2] = ' ';
shapeArray[0][3] = ' '; shapeArray[1][3] = ' '; shapeArray[2][3] = ' '; shapeArray[3][3] = ' ';
break;
case 'R':
shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = 'X ';shapeArray[3][0] = ' ';
shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = ' ';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = 'X';shapeArray[2][2] = 'X';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
break;
case 'U':
shapeArray[0][0] = ' ';shapeArray[1][0] = 'X';shapeArray[2][0] = ' ';shapeArray[3][0] = ' ';
shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = 'X';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = 'X';shapeArray[2][2] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
break;
case 'D':
shapeArray[0][0] = ' ';shapeArray[1][0] = 'X';shapeArray[2][0] = ' ';shapeArray[3][0] = ' ';
shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = ' ';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = 'X';shapeArray[2][2] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = 'X';shapeArray[3][3] = ' ';
break;
} // end of switch
}
void moveShape(int shapeType)
{
char shapeArray[4][4];
//shape reacts to user input
cout << " Computer moves shape according to user request" << endl;
int mvDir; // Move Direction
//user presses keys to flip/move shape
cout << "Please enter move direction: 1 = Up & left, 2 = Up & right, 3 = Down & Left, 4 = Down & Right";
cin >> mvDir;
switch (mvDir) {
case '1':
shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = ' ';shapeArray[3][0] = 'X';
shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = ' ';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = 'X';shapeArray[2][2] = 'X';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
break;
case '2':
shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = 'X ';shapeArray[3][0] = ' ';
shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = ' ';shapeArray[3][1] = 'X';
shapeArray[0][2] = ' ';shapeArray[1][2] = 'X';shapeArray[2][2] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
break;
case '3':
shapeArray[0][0] = ' ';shapeArray[1][0] = 'X';shapeArray[2][0] = ' ';shapeArray[3][0] = ' ';
shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = 'X';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = ' ';shapeArray[2][2] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = 'X';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
break;
case '4':
shapeArray[0][0] = ' ';shapeArray[1][0] = 'X';shapeArray[2][0] = ' ';shapeArray[3][0] = 'X';
shapeArray[0][1] = ' ';shapeArray[1][1] = 'X';shapeArray[2][1] = ' ';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = 'X';shapeArray[2][2] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
break;
} // end of switch
}
void shapeDrop()
{
char shapeArray[4][4];
//when shape drops on bottom and stops
cout << " Shape drops to bottom" << endl;
shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = ' ';shapeArray[3][0] = ' ';
shapeArray[0][1] = ' ';shapeArray[1][1] = ' ';shapeArray[2][1] = ' ';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = ' ';shapeArray[2][2] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = 'X';shapeArray[1][3] = 'X';shapeArray[2][3] = 'X';shapeArray[3][3] = 'X';
}
void clearRow()
{
char shapeArray[4][4];
//when a row is filled, will clear and score
cout << " A row is filled, it clears" << endl;
shapeArray[0][0] = ' ';shapeArray[1][0] = ' ';shapeArray[2][0] = ' ';shapeArray[3][0] = ' ';
shapeArray[0][1] = ' ';shapeArray[1][1] = ' ';shapeArray[2][1] = ' ';shapeArray[3][1] = ' ';
shapeArray[0][2] = ' ';shapeArray[1][2] = ' ';shapeArray[2][2] = ' ';shapeArray[3][2] = ' ';
shapeArray[0][3] = ' ';shapeArray[1][3] = ' ';shapeArray[2][3] = ' ';shapeArray[3][3] = ' ';
score();
}
void score()
{
//calculates score
int score;
cout << " Add to score" << endl;
score++;
}
void endGame()
{
//when shape hits top, clear screen and display/save score
cout << " Clear screen and save score" << endl;
clearRow();
cout << " Score = " << score;
}
Please dont past some other online code program but instead help me out with my code.
Explanation / Answer
Tetries code in C++:
Tetries code in java:
}
#include "tetris.h" Tetrad::Tetrad() { LoadGraphics(); } Tetrad::~Tetrad() { SDL_FreeSurface(tetrisbits); } void Tetrad::Init(int newtype) { type=newtype; switch(type) { case SHAPE_Z: piece[0]=5; piece[1]=4; piece[2]=15; piece[3]=16; break; case SHAPE_S: piece[0]=15; piece[1]=6; piece[2]=14; piece[3]=5; break; case SHAPE_L: piece[0]=5; piece[1]=4; piece[2]=6; piece[3]=14; break; case SHAPE_J: piece[0]=5; piece[1]=4; piece[2]=6; piece[3]=16; break; case SHAPE_O: piece[0]=4; piece[1]=5; piece[2]=14; piece[3]=15; break; case SHAPE_T: piece[0]=5; piece[1]=4; piece[2]=6; piece[3]=15; break; case SHAPE_I: default: piece[0]=4; piece[1]=3; piece[2]=5; piece[3]=6; break; } pieces=4; color = type; moves=0; haslanded=false; tetradrect.x=color*16; tetradrect.y=0; tetradrect.w=16; tetradrect.h=16; shadowrect.x=color*16; shadowrect.y=32; shadowrect.w=16; shadowrect.h=16; return; } void Tetrad::Theme(const char* theme) { SDL_Surface *temp; char* filename = new char[80]; sprintf(filename, "media/pieces%s.png", theme); temp=IMG_Load(filename); if(!temp) { printf("Failed to load tetrad graphics %s ", filename); } else { SDL_FreeSurface(tetrisbits); tetrisbits=SDL_DisplayFormatAlpha(temp); SDL_FreeSurface(temp); } delete[] filename; return; } int Tetrad::GetType() { return type; } void Tetrad::LoadGraphics() { SDL_Surface* temp; temp=IMG_Load("media/pieces.png"); if(!temp) { printf("Failed to load tetrad graphics media/pieces.png "); } tetrisbits=SDL_DisplayFormatAlpha(temp); SDL_FreeSurface(temp); } bool Tetrad::MoveLeft(Bucket* bucket) { int i; bool move=!haslanded; for(i=0; i<pieces; i++) { if(!bucket->IsEmpty(piece[i]-1, true) || piece[i]%10==0) { move=false; } } if(move) { for(i=0; i<pieces; i++) { piece[i]--; } moves++; } return move; } bool Tetrad::MoveRight(Bucket* bucket) { int i; bool move=!haslanded; for(i=0; i<pieces; i++) { piece[i]%10==9) { move=false; } } if(move) { for(i=0; i<pieces; i++) { piece[i]++; } moves++; } return move; } bool Tetrad::MoveDown(Bucket* bucket) { int i; for(i=0; i<pieces; i++) { piece[i]/10==19) { move=false; } } if(move) { for(i=0; i<pieces; i++) { piece[i]+=10; } moves++; } else { for(i=0; i<pieces; i++) { bucket->AddBlock(piece[i], color); } haslanded=true; } return move; } bool Tetrad::MoveUp(Bucket* bucket) { int i; bool move=true; for(i=0; i<pieces; i++) { piece[i]/10==0) { move=false; } } if(move) { for(i=0; i<pieces; i++) { piece[i]-=10; } moves++; } return move; } bool Tetrad::Rotate(Bucket* bucket, bool clockwise) { int i, leniancy, leniancytype, min, max; bool leftedge=false, rightedge=false; bool preleft=false, preright=false; int temp[8]; //acts as a temporary last[], in case rotation is illegal bool rotate=!haslanded; for(i=0; i<pieces; i++) { temp[i]=piece[i]; if(temp[i]%10==0) { preleft=true; } else if(temp[i]%10==9) { preright=true; } } for(leniancy=1; leniancy<pieces/2+1; leniancy++) { for(leniancytype=0; leniancytype<3; leniancytype++) { if(piece[0]%10==0) { leftedge=true; } else { leftedge=false; } if(piece[0]%10==9) { rightedge=true; } else { rightedge=false; } rotate=true; for(i=1; i<pieces; i++) { if(clockwise) { piece[i]=-10*(piece[0]%10-piece[i]%10) +piece[0]+(piece[0]/10-piece[i]/10); } else { piece[i]=10*(piece[0]%10-piece[i]%10) +piece[0]-(piece[0]/10-piece[i]/10); } if(piece[i]%10==0) { leftedge=true; } else if(piece[i]%10==9) { rightedge=true; } } min=9; max=0; for(i=0; i<pieces; i++) { (leftedge && rightedge) ) { rotate=false; } if(piece[i]%10<min) { min=piece[i]%10; } if(piece[i]%10>max) { max=piece[i]%10; } } if(max-min>pieces) { rotate=false; } if(rotate) { break; } else { for(i=0; i<pieces; i++) { switch(leniancytype) { case 0: //try left if(!preleft) { piece[i]=temp[i]-leniancy; } else { piece[i]=temp[i]; } break; if(!preright) { piece[i]=temp[i]+leniancy; } else { piece[i]=temp[i]; } break; default: piece[i]=temp[i]+(10*leniancy); break; } } } } if(rotate) { break; } } if(!rotate) { for(i=0; i<pieces; i++) { //reset piece[] if we rotated illegally piece[i]=temp[i]; } } else { moves++; } return rotate; } bool Tetrad::IsAt(int loc) { int i; for(i=0; i<pieces; i++) { if(piece[i]==loc) { return true; } } return false; } bool Tetrad::AddBlock(int loc) { int i; if(0>loc||loc>199) { return false; } for(i=0; i<pieces; i++) { if(IsAt(loc)) { return false; } } if(pieces<8) { piece[pieces]=loc; pieces++; moves++; return true; } else { return false; } } void Tetrad::DelBlock(int loc) { moves++; int i; bool gotit=false; for(i=0; i<pieces; i++) { if(piece[i]==loc) { gotit=true; if(i<pieces+1) { piece[i]=piece[i+1]; loc=piece[i]; } } } if(gotit) { pieces--; } if(pieces<1) { haslanded=true; } } bool Tetrad::HasLanded() { return haslanded; } void Tetrad::Draw(Bucket *bucket, SDL_Surface *surf) { int i, j; int shadoff=0, shadmin=20; for(i=0; i<pieces; i++) { destrect.x=(piece[i]%10)*16+OFFSET_X; destrect.y=(piece[i]/10)*16+OFFSET_Y; for(j=piece[i]; j<200; j+=10) { if(bucket->IsEmpty(j, true)) { shadoff=(j/10)-(piece[i]/10); } else { break; } } shadmin = (shadmin>shadoff) ? shadoff : shadmin; if(SDL_BlitSurface(tetrisbits, &tetradrect, surf, &destrect)) { LoadGraphics(); SDL_BlitSurface(tetrisbits, &tetradrect, surf, &destrect); } } for(i=0; i<pieces; i++) { destrect.x=(piece[i]%10)*16+OFFSET_X; destrect.y=((piece[i]+((shadmin)*10))/10)*16+OFFSET_Y; if(SDL_BlitSurface(tetrisbits, &shadowrect, surf, &destrect)) { LoadGraphics(); SDL_BlitSurface(tetrisbits, &shadowrect, surf, &destrect); } } return; } void Tetrad::Preview(SDL_Surface *surf) { int i; SDL_Rect rect; rect.x=type * 16; rect.y=16; rect.w=rect.h=16; for(i=0; i<pieces; i++) { destrect.x=(piece[i]%10)*16+PREVIEW_OFFSET_X-32; destrect.y=(piece[i]/10)*16+PREVIEW_OFFSET_Y; if(SDL_BlitSurface(tetrisbits, &rect, surf, &destrect)) { LoadGraphics(); SDL_BlitSurface(tetrisbits, &rect, surf, &destrect); } } return; } int Tetrad::GetMoves() { return moves; } Bucket::Bucket() { LoadGraphics(); } Bucket::~Bucket() { SDL_FreeSurface(tetrisbits); } void Bucket::Init(int junklevel) { int i; int inarow=0; for(i=0; i<200; i++) { area[i]=EMPTY; } for(i=200-junklevel*10; i<200; i++) { if(rand()%2 && inarow<10) { area[i]=rand()%6+1; inarow++; } else { inarow=0; } } } void Bucket::LoadGraphics() { SDL_Surface *temp; temp=IMG_Load("media/pieces.png"); if(!temp) { printf("Failed to load bucket graphics media/pieces.png "); } tetrisbits=SDL_DisplayFormatAlpha(temp); stackrect.w=16; stackrect.h=16; breakstart=0; breakrowmin=19; breakrowmax=0; } void Bucket::Theme(const char* theme) { SDL_Surface *temp; char* filename = new char[80]; sprintf(filename, "media/pieces%s.png", theme); temp=IMG_Load(filename); if(!temp) { printf("Failed to load bucket graphics %s ", filename); } else { SDL_FreeSurface(tetrisbits); tetrisbits=SDL_DisplayFormatAlpha(temp); SDL_FreeSurface(temp); } delete[] filename; return; } void Bucket::GreyOut() { int i; for(i=0; i<200; i++) { if(area[i]!=EMPTY) { area[i]=STACK|WHITE; } } return; } void Bucket::AddJunk() { int i; int hole; for(i=0; i<190; i++) { area[i]=area[i+10]; } hole=(rand()%10)+190; for(i=190; i<200; i++) { if(i!=hole) { area[i]=STACK|WHITE; } else { area[i]=EMPTY; } } return; } void Bucket::StartOver() { int i; for(i=0; i<200; i++) { if(area[i]!=EMPTY) { area[i]|=BREAK; } } } bool Bucket::IsBreaking() { int i; bool breaking=false; for(i=0; i<200; i++) { if(area[i]&BREAK) { return true; } } return breaking; } bool Bucket::IsBreaking(int block) { return (area[block]&BREAK)?true:false; } bool Bucket::IsEmpty(int block, bool break_is_empty) { if(block>199) { return false; } else { return (area[block]==EMPTY || (break_is_empty && area[block]&BREAK)); } } void Bucket::AddBlock(int block, int color) { int i; bool fullrow=true; if(0>block||block>199) { return; } area[block]=STACK | color; for(i=(block/10)*10; i<(block/10)*10+10; i++) { if(IsEmpty(i, false)) { fullrow=false; break; } } if(fullrow) { for(i=(block/10)*10; i<(block/10)*10+10; i++) { area[i]|=BREAK; } if(block/10<breakrowmin) { breakrowmin=block/10; } if(block/10>breakrowmax) { breakrowmax=block/10; } } return; } void Bucket::DelBlock(int block) { if(0>block||block>200) { return; } if(!IsEmpty(block, false)) { area[block]|=BREAK; } return; } int Bucket::Drop() { int i, j; int droppingto=breakrowmax; int lines=0; if(breakrowmin<=breakrowmax) { for(i=breakrowmax; i>=0; i--) { if(!(area[i*10]&BREAK)) { for(j=0; j<10; j++) { area[droppingto*10+j]=area[i*10+j]; area[i]=EMPTY; } droppingto--; } else { lines++; } } } else { for(i=0; i<200; i++) { if(area[i]&BREAK) { area[i]=EMPTY; } } } breakrowmin=19; breakrowmax=0; return lines; } int Bucket::Draw(SDL_Surface* surf) { int i; int lines=0; if(breakstart && SDL_GetTicks()-breakstart>BREAK_TIME) { lines=Drop(); breakstart=0; } for(i=0; i<200; i++) { destrect.x=(i%10)*16+OFFSET_X; destrect.y=(i/10)*16+OFFSET_Y; if(area[i]&BREAK) { if(!breakstart) { stackrect.x=0; stackrect.y=0; if(SDL_BlitSurface(tetrisbits, &stackrect, surf, &destrect)) { LoadGraphics(); SDL_BlitSurface(tetrisbits, &stackrect, surf, &destrect); } breakstart=SDL_GetTicks(); } else { stackrect.x=(rand()%7)*16; stackrect.y=(rand()%2)*16; if(((float)(i%10)/10.0)+0.4 <= 1.0-(((float)SDL_GetTicks()-(float)breakstart)/ (float)BREAK_TIME/2) || 1.0-((float)(i%10)/10.0)+0.4 <= 1.0-(((float)SDL_GetTicks()-(float)breakstart)/ (float)BREAK_TIME/2)) { if(SDL_BlitSurface(tetrisbits, &stackrect, surf, &destrect)) { LoadGraphics(); SDL_BlitSurface(tetrisbits, &stackrect, surf, &destrect); } } } } else if(area[i]!=EMPTY) { stackrect.x=(area[i] & COLORMASK) *16; stackrect.y=16; if(SDL_BlitSurface(tetrisbits, &stackrect, surf, &destrect)) { LoadGraphics(); SDL_BlitSurface(tetrisbits, &stackrect, surf, &destrect); } } } return lines; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.