|
|
@ -1,38 +1,29 @@
|
|
|
|
bool PieceStuck() {
|
|
|
|
bool InvalidMove() { // a bit wasteful, but piece are tiny
|
|
|
|
if(curpiece_){
|
|
|
|
int dy, dx;
|
|
|
|
// check for impact. iterate over bottom row of piece's plane, checking for
|
|
|
|
curpiece_->get_dim(&dy, &dx);
|
|
|
|
// presence of glyph. if there, check row below. if row below is occupied,
|
|
|
|
while(dy--){
|
|
|
|
// we're stuck.
|
|
|
|
int x = dx;
|
|
|
|
int y, dimx, x;
|
|
|
|
|
|
|
|
curpiece_->get_dim(&y, &dimx);
|
|
|
|
|
|
|
|
std::vector<bool> columns(dimx, false); // bitmap for column verification
|
|
|
|
|
|
|
|
int checked = 0;
|
|
|
|
|
|
|
|
while(y--){
|
|
|
|
|
|
|
|
x = dimx;
|
|
|
|
|
|
|
|
while(x--){
|
|
|
|
while(x--){
|
|
|
|
if(!columns[x]){
|
|
|
|
ncpp::Cell c, b;
|
|
|
|
ncpp::Cell piecec;
|
|
|
|
if(curpiece_->get_at(dy, x, &c) < 0){
|
|
|
|
if(curpiece_->get_at(y, x, &piecec) < 0){
|
|
|
|
|
|
|
|
throw TetrisNotcursesErr("get_at()");
|
|
|
|
throw TetrisNotcursesErr("get_at()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(piecec.is_simple()){
|
|
|
|
if(c.is_simple()){
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int cmpy = y + 1, cmpx = x; // need game area coordinates via translation
|
|
|
|
curpiece_->release(c);
|
|
|
|
curpiece_->translate(*board_, &cmpy, &cmpx);
|
|
|
|
int transy = dy, transx = x; // need game area coordinates via translation
|
|
|
|
ncpp::Cell c;
|
|
|
|
curpiece_->translate(*board_, &transy, &transx);
|
|
|
|
if(board_->get_at(cmpy, cmpx, &c) < 0){
|
|
|
|
if(transy < 0 || transy >= board_->get_dim_y() || transx < 0 || transx >= board_->get_dim_x()){
|
|
|
|
throw TetrisNotcursesErr("get_at()");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!c.is_simple()){
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
columns[x] = true;
|
|
|
|
if(board_->get_at(transy, transx, &b) < 0){
|
|
|
|
if(++checked == dimx){
|
|
|
|
throw TetrisNotcursesErr("get_at()");
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!b.is_simple()){
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
board_->release(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|