ajouté interface textuelle
This commit is contained in:
@@ -25,7 +25,7 @@ Game::Game(Gamemode gamemode, const Player& controls, int boardWidth, int boardH
|
||||
|
||||
void Game::start() {
|
||||
this->started = true;
|
||||
this->lost = this->board.spawnNextPiece();
|
||||
this->leftARETime = 1;
|
||||
}
|
||||
|
||||
void Game::reset() {
|
||||
@@ -48,7 +48,6 @@ void Game::initialize() {
|
||||
this->heldDAS = 0;
|
||||
this->heldARR = 0;
|
||||
this->subVerticalPosition = 0;
|
||||
this->leftARETime = 0;
|
||||
this->totalLockDelay = 0;
|
||||
this->totalForcedLockDelay = 0;
|
||||
}
|
||||
@@ -64,14 +63,14 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
|
||||
if (this->leftARETime == 0) {
|
||||
if (AREJustEnded) {
|
||||
this->board.spawnNextPiece();
|
||||
this->lost = this->board.spawnNextPiece();
|
||||
}
|
||||
|
||||
/* IRS and IHS */
|
||||
Rotation initialRotation = NONE
|
||||
+ (this->initialActions.contains(ROTATE_CW)) ? CLOCKWISE : NONE
|
||||
+ (this->initialActions.contains(ROTATE_180)) ? DOUBLE : NONE
|
||||
+ (this->initialActions.contains(ROTATE_CCW)) ? COUNTERCLOCKWISE : NONE;
|
||||
+ ((this->initialActions.contains(ROTATE_CW)) ? CLOCKWISE : NONE)
|
||||
+ ((this->initialActions.contains(ROTATE_180)) ? DOUBLE : NONE)
|
||||
+ ((this->initialActions.contains(ROTATE_CCW)) ? COUNTERCLOCKWISE : NONE);
|
||||
|
||||
if (this->initialActions.contains(HOLD)) {
|
||||
if (this->board.hold(initialRotation)) {
|
||||
@@ -79,13 +78,35 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
this->totalLockDelay = 0;
|
||||
this->heldARR = 0;
|
||||
}
|
||||
else {
|
||||
this->lost = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (initialRotation != NONE) {
|
||||
this->board.rotate(initialRotation);
|
||||
if (initialRotation != NONE || this->initialActions.contains(ROTATE_0)) {
|
||||
Position before = this->board.getActivePiecePosition();
|
||||
if (this->board.rotate(initialRotation)) {
|
||||
this->totalLockDelay = 0;
|
||||
if (before != this->board.getActivePiecePosition()) {
|
||||
this->subVerticalPosition = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->lost = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->lost) {
|
||||
if (initialRotation == NONE && (!this->initialActions.contains(ROTATE_0))) {
|
||||
this->board.rotate(NONE);
|
||||
}
|
||||
}
|
||||
if (this->lost) {
|
||||
this->framesPassed++;
|
||||
return;
|
||||
}
|
||||
|
||||
/* HOLD */
|
||||
if (playerActions.contains(HOLD) && (!this->heldActions.contains(HOLD))) {
|
||||
if (this->board.hold()) {
|
||||
@@ -96,25 +117,48 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
}
|
||||
|
||||
/* MOVE LEFT/RIGHT */
|
||||
Position before = this->board.getActivePiecePosition();
|
||||
|
||||
if (playerActions.contains(MOVE_LEFT)) {
|
||||
this->movePiece(-1, (this->heldDAS >= 0));
|
||||
this->movePiece(-1);
|
||||
}
|
||||
if (playerActions.contains(MOVE_RIGHT)) {
|
||||
this->movePiece(1, (this->heldDAS <= 0));
|
||||
else if (playerActions.contains(MOVE_RIGHT)) {
|
||||
this->movePiece(1);
|
||||
}
|
||||
else {
|
||||
this->heldDAS = 0;
|
||||
}
|
||||
|
||||
if (before != this->board.getActivePiecePosition()) {
|
||||
this->totalLockDelay = 0;
|
||||
}
|
||||
|
||||
/* ROTATIONS */
|
||||
before = this->board.getActivePiecePosition();
|
||||
|
||||
if (playerActions.contains(ROTATE_0) && (!this->heldActions.contains(ROTATE_0))) {
|
||||
if (this->board.rotate(NONE)) {
|
||||
this->totalLockDelay = 0;
|
||||
}
|
||||
}
|
||||
if (playerActions.contains(ROTATE_CW) && (!this->heldActions.contains(ROTATE_CW))) {
|
||||
this->board.rotate(CLOCKWISE);
|
||||
if (this->board.rotate(CLOCKWISE)) {
|
||||
this->totalLockDelay = 0;
|
||||
}
|
||||
}
|
||||
if (playerActions.contains(ROTATE_180) && (!this->heldActions.contains(ROTATE_180))) {
|
||||
this->board.rotate(DOUBLE);
|
||||
if (this->board.rotate(DOUBLE)) {
|
||||
this->totalLockDelay = 0;
|
||||
}
|
||||
}
|
||||
if (playerActions.contains(ROTATE_CCW) && (!this->heldActions.contains(ROTATE_CCW))) {
|
||||
this->board.rotate(COUNTERCLOCKWISE);
|
||||
if (this->board.rotate(COUNTERCLOCKWISE)) {
|
||||
this->totalLockDelay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (before != this->board.getActivePiecePosition()) {
|
||||
this->subVerticalPosition = 0;
|
||||
}
|
||||
|
||||
/* SOFT DROP */
|
||||
@@ -149,7 +193,7 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
else {
|
||||
/* GRAVITY */
|
||||
// parameters.getGravity() gives the gravity for an assumed 20-line high board
|
||||
int appliedGravity = this->parameters.getGravity() * (this->board.getBoard().getBaseHeight() / 20.0);
|
||||
int appliedGravity = this->parameters.getGravity() * std::max((double) this->board.getBoard().getBaseHeight() / 20.0, 1.0);
|
||||
|
||||
this->subVerticalPosition += appliedGravity;
|
||||
while (this->subVerticalPosition >= SUBPX_PER_ROW) {
|
||||
@@ -171,16 +215,18 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
}
|
||||
}
|
||||
|
||||
// remove initial actions only once they've been applied
|
||||
if (AREJustEnded) {
|
||||
this->initialActions.clear();
|
||||
}
|
||||
}
|
||||
|
||||
this->framesPassed++;
|
||||
if (this->lost) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// update remembered actions
|
||||
// update remembered actions for next frame
|
||||
if ((!this->started) || this->leftARETime > 0) {
|
||||
for (Action action : playerActions) {
|
||||
this->initialActions.insert(action);
|
||||
@@ -189,19 +235,24 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
|
||||
|
||||
this->heldActions = playerActions;
|
||||
|
||||
if (playerActions.contains(MOVE_LEFT)) {
|
||||
this->heldDAS = std::min(-1, this->heldDAS - 1);
|
||||
}
|
||||
if (playerActions.contains(MOVE_RIGHT)) {
|
||||
this->heldDAS = std::max(1, this->heldDAS + 1);
|
||||
}
|
||||
else {
|
||||
this->heldDAS = 0;
|
||||
if (this->leftARETime > 0) {
|
||||
if (playerActions.contains(MOVE_LEFT)) {
|
||||
this->heldDAS = std::min(-1, this->heldDAS - 1);
|
||||
}
|
||||
else if (playerActions.contains(MOVE_RIGHT)) {
|
||||
this->heldDAS = std::max(1, this->heldDAS + 1);
|
||||
}
|
||||
else {
|
||||
this->heldDAS = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::movePiece(int movement, bool resetDirection) {
|
||||
if (resetDirection) {
|
||||
void Game::movePiece(int movement) {
|
||||
int appliedDAS = this->parameters.getDAS();
|
||||
int appliedARR = this->parameters.getARR();
|
||||
|
||||
if ((this->heldDAS * movement) <= 0) {
|
||||
this->heldDAS = movement;
|
||||
this->heldARR = 0;
|
||||
}
|
||||
@@ -209,9 +260,12 @@ void Game::movePiece(int movement, bool resetDirection) {
|
||||
this->heldDAS += movement;
|
||||
}
|
||||
|
||||
if (abs(this->heldDAS) > this->parameters.getDAS()) {
|
||||
int appliedARR = this->parameters.getARR();
|
||||
if (abs(this->heldDAS) == appliedDAS + 1) {
|
||||
if (movement == -1) this->board.moveLeft();
|
||||
if (movement == 1) this->board.moveRight();
|
||||
}
|
||||
|
||||
if (abs(this->heldDAS) > appliedDAS + 1) {
|
||||
// ARR=0 -> instant movement
|
||||
if (appliedARR == 0) {
|
||||
if (movement == -1) while (this->board.moveLeft());
|
||||
@@ -233,7 +287,6 @@ void Game::lockPiece() {
|
||||
LineClear clear = this->board.lockPiece();
|
||||
this->parameters.clearLines(clear.lines);
|
||||
|
||||
// update B2B and score
|
||||
bool B2BConditionsAreMet = ((clear.lines > B2B_MIN_LINE_NUMBER) || clear.isSpin || clear.isMiniSpin);
|
||||
if (clear.lines > 0) {
|
||||
/* clearing one more line is worth 2x more
|
||||
@@ -246,16 +299,14 @@ void Game::lockPiece() {
|
||||
}
|
||||
this->B2BChain = B2BConditionsAreMet;
|
||||
|
||||
// reset active piece
|
||||
this->subVerticalPosition = 0;
|
||||
this->totalLockDelay = 0;
|
||||
this->totalForcedLockDelay = 0;
|
||||
this->heldARR = 0;
|
||||
|
||||
// check for ARE
|
||||
this->leftARETime = this->parameters.getARE();
|
||||
if (this->leftARETime == 0) {
|
||||
this->board.spawnNextPiece();
|
||||
this->lost = this->board.spawnNextPiece();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,22 +342,26 @@ bool Game::areBlocksBones() const {
|
||||
return this->parameters.getBoneBlocks();
|
||||
}
|
||||
|
||||
Board Game::getBoard() const {
|
||||
Position Game::ghostPiecePosition() const {
|
||||
return this->board.lowestPosition();
|
||||
}
|
||||
|
||||
const Board& Game::getBoard() const {
|
||||
return this->board.getBoard();
|
||||
}
|
||||
|
||||
Piece Game::getActivePiece() const {
|
||||
const std::shared_ptr<Piece>& Game::getActivePiece() const {
|
||||
return this->board.getActivePiece();
|
||||
}
|
||||
|
||||
Position Game::getActivePiecePosition() const {
|
||||
const Position& Game::getActivePiecePosition() const {
|
||||
return this->board.getActivePiecePosition();
|
||||
}
|
||||
|
||||
Piece Game::getHeldPiece() const {
|
||||
const std::shared_ptr<Piece>& Game::getHeldPiece() const {
|
||||
return this->board.getHeldPiece();
|
||||
}
|
||||
|
||||
std::vector<Piece> Game::getNextPieces() const {
|
||||
const std::vector<Piece>& Game::getNextPieces() const {
|
||||
return this->board.getNextPieces();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user