Line::Line(int row,int z,SafeMatrix& matrix,SDL_Surface* (&blocks)[5]) :SurfaceWidget(MATRIX_X,row*BLOCK_DIM+MATRIX_Y,MATRIX_W,BLOCK_DIM,z) { try { surface_=Util::createSurface(BLOCK_DIM*MATRIX_COLS,BLOCK_DIM); } catch(const exception& ex) { throw runtime_error(string("Line::Line(...): ")+ex.what()); } SDL_Rect r; r.x=r.y=0; for(int i=0;i<MATRIX_COLS;i++,r.x+=BLOCK_DIM) { SDL_BlitSurface(blocks[matrix.get(row,i)],0,surface_,&r); matrix.set(row,i,-1); } alpha_=SDL_ALPHA_OPAQUE; SDL_SetAlpha(surface_,SDL_SRCALPHA|SDL_RLEACCEL,alpha_); ticks_=0; }
Block::Block(int row,int z,SafeMatrix& matrix) :FallingObject(0,0,0,0,z) { int ro; for(ro=0;ro<row;ro++) { int j; for(j=0;j<MATRIX_COLS && matrix.get(ro,j)==-1;j++); if(j<MATRIX_COLS) break; } if(ro>=row) throw runtime_error("Block::Block(): Block vacio"); int co; for(co=0;co<MATRIX_COLS;co++) { int j; for(j=ro;j<row && matrix.get(j,co)==-1;j++); if(j<row) break; } int cf; for(cf=MATRIX_COLS-1;cf>=co;cf--) { int j; for(j=0;j<row && matrix.get(j,cf)==-1;j++); if(j<row) break; } if(co>cf) throw runtime_error("Block::Block(): Block vacio"); matrix_=SafeMatrix(row-ro,cf-co+1); for(int r=0;r<matrix_.getRows();r++) for(int c=0;c<matrix_.getCols();c++) { matrix_.set(r,c,matrix.get(ro+r,co+c)); matrix.set(ro+r,co+c,-1); } setX(co*BLOCK_DIM+MATRIX_X); setY(ro*BLOCK_DIM+MATRIX_Y); setWidth(matrix_.getCols()*BLOCK_DIM); setHeight(matrix_.getRows()*BLOCK_DIM); //matrix_.print(); rects_.reserve(matrix_.getCols()); refreshRects(); }
void Block::putIn(int row,int col,SafeMatrix& matrix) { for(int r=0;r<matrix_.getRows();r++) for(int c=0;c<matrix_.getCols();c++) if(matrix_.get(r,c)>=0 && row+r>=0) matrix.set(row+r,col+c,matrix_.get(r,c)); }
int Block::getMinimumDeltaY(SafeMatrix& matrix) { int row,col,min; row=(getY()-MATRIX_Y)/BLOCK_DIM; col=(getX()-MATRIX_X)/BLOCK_DIM; min=MATRIX_ROWS; for(int i=0;i<matrix_.getCols();i++) { int j; for(j=matrix_.getRows()-1;j>=0 && matrix_.get(j,i)==-1;j--); if(j>=0) min=Util::min(min,matrix.getLowerRow(row+j,col+i)-(row+j+1)); } return min; }
int main(){ cout<<"hello\n"; SafeMatrix<int> first = SafeMatrix<int>(5,6); for(int g=0; g<first.numRows(); g++){ for(int h=0; h<first.numCols(); h++){ first[g][h]=g+h; } } SafeMatrix<int> second = first; for(int j=0; j<second.numRows(); j++){ for(int k=0; k<second.numCols(); k++){ cout<<second[j][k]<<", "; } cout<<"\n"; } return 0; }