{
if (event->timerId() == timer.timerId()) {
if (isWaitingAfterLine) {
isWaitingAfterLine = false;
newPiece();
timer.start(timeoutTime(), this);
} else {
oneLineDown();
}
} else {
QFrame::timerEvent(event);
}
}
void HTetrisBoard::clearBoard()
{
for (int i = 0; i < HTetrisBoardHeight * HTetrisBoardWidth; ++i)
board[i] = HTetrisPieceShapeNone;
}
void HTetrisBoard::dropDown()
{
int dropHeight = 0;
int newY = curY;
while (newY > 0) {
if (!tryMove(curPiece, curX, newY - 1))
break;
--newY;
++dropHeight;
}
pieceDropped(dropHeight);
}
void HTetrisBoard::oneLineDown()
{
if (!tryMove(curPiece, curX, curY - 1))
pieceDropped(0);
}
void HTetrisBoard::pieceDropped(int dropHeight)
{
for (int i = 0; i < 4; ++i) {
int x = curX + curPiece.x(i);
int y = curY - curPiece.y(i);
shapeAt(x, y) = curPiece.shape();
}
exp += 1;
score += dropHeight+1;
emit scoreChanged(score);
removeFullLines();
if(exp%50 == 0){
level++;
timer.start(timeoutTime(), this);
emit levelChanged(level);
}
if (!isWaitingAfterLine)
热门文档