fixed game logic
This commit is contained in:
@@ -55,6 +55,8 @@ void Game::initialize() {
|
||||
void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
if (this->lost || this->hasWon()) return;
|
||||
|
||||
bool pieceJustLocked = false;
|
||||
|
||||
if (this->started) {
|
||||
bool AREJustEnded = (this->leftARETime == 1);
|
||||
if (this->leftARETime > 0) {
|
||||
@@ -84,13 +86,14 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
|
||||
if (this->lost) {
|
||||
if (initialRotation == NONE) {
|
||||
this->lost = (!this->board.rotate(initialRotation));
|
||||
this->board.rotate(NONE);
|
||||
this->lost = this->board.activePieceInWall();
|
||||
if (this->lost) {
|
||||
this->framesPassed++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this->lost) {
|
||||
this->framesPassed++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* HOLD */
|
||||
if (playerActions.contains(HOLD) && (!this->heldActions.contains(HOLD))) {
|
||||
@@ -158,6 +161,7 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
this->score += HARD_DROP_SCORE;
|
||||
}
|
||||
this->lockPiece();
|
||||
pieceJustLocked = true;
|
||||
}
|
||||
// no need to apply gravity and lock delay if the piece was hard dropped
|
||||
else {
|
||||
@@ -187,6 +191,7 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
|
||||
if ((this->totalLockDelay > this->parameters.getLockDelay()) || (this->totalForcedLockDelay > this->parameters.getForcedLockDelay())) {
|
||||
this->lockPiece();
|
||||
pieceJustLocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,11 +206,11 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
}
|
||||
}
|
||||
|
||||
this->heldActions = playerActions;
|
||||
|
||||
if ((!this->started) || this->leftARETime > 0) {
|
||||
for (Action action : playerActions) {
|
||||
this->initialActions.insert(action);
|
||||
if ((!pieceJustLocked) && (!heldActions.contains(action))) {
|
||||
this->initialActions.insert(action);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->heldDAS >= 0) {
|
||||
@@ -219,6 +224,8 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
else this->heldDAS = 0;
|
||||
}
|
||||
}
|
||||
|
||||
this->heldActions = playerActions;
|
||||
}
|
||||
|
||||
void Game::resetPiece(bool newPiece) {
|
||||
@@ -302,6 +309,11 @@ void Game::lockPiece() {
|
||||
if (this->leftARETime == 0) {
|
||||
this->lost = this->board.spawnNextPiece();
|
||||
this->resetPiece(true);
|
||||
|
||||
if (this->lost) {
|
||||
this->board.rotate(NONE);
|
||||
this->lost = this->board.activePieceInWall();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user