màj diagrammes

This commit is contained in:
2025-03-01 23:15:58 +01:00
parent f525c00662
commit 857f90d646
11 changed files with 27 additions and 24 deletions

View File

@@ -38,7 +38,7 @@ void GameBoard::initialize() {
}
bool GameBoard::moveLeft() {
if (this->isActivePieceInWall(Position{-1, 0})) {
if (this->activePieceInWall(Position{-1, 0})) {
return false;
}
else {
@@ -49,7 +49,7 @@ bool GameBoard::moveLeft() {
}
bool GameBoard::moveRight() {
if (this->isActivePieceInWall(Position{1, 0})) {
if (this->activePieceInWall(Position{1, 0})) {
return false;
}
else {
@@ -60,7 +60,7 @@ bool GameBoard::moveRight() {
}
bool GameBoard::moveDown() {
if (this->isActivePieceInWall(Position{0, -1})) {
if (this->activePieceInWall(Position{0, -1})) {
return false;
}
else {
@@ -75,7 +75,7 @@ bool GameBoard::rotate(Rotation rotation) {
this->rotate(rotation);
// before trying to kick, check if the piece can rotate without kicking
if (!this->isActivePieceInWall()) {
if (!this->activePieceInWall()) {
this->isLastMoveKick = false;
return true;
}
@@ -123,11 +123,11 @@ bool GameBoard::tryKicking(bool testingBottom, const std::set<Position>& safePos
// check right before right arbitrarly, we don't decide this with rotations since it would still be arbitrary with 180° rotations
if (overlapsRight) {
Position shift{+i, j};
if (!this->activePieceOverlapsOnePosition(safePositions, shift)) {
if (!this->activePieceOverlaps(safePositions, shift)) {
overlapsLeft = false;
}
else {
if (!this->isActivePieceInWall(shift)) {
if (!this->activePieceInWall(shift)) {
this->activePiecePosition += shift;
return true;
}
@@ -137,11 +137,11 @@ bool GameBoard::tryKicking(bool testingBottom, const std::set<Position>& safePos
// do the same on the left side
if (overlapsLeft) {
Position shift{-i, j};
if (!this->activePieceOverlapsOnePosition(safePositions, shift)) {
if (!this->activePieceOverlaps(safePositions, shift)) {
overlapsLeft = false;
}
else {
if (!this->isActivePieceInWall(shift)) {
if (!this->activePieceInWall(shift)) {
this->activePiecePosition += shift;
return true;
}
@@ -181,11 +181,11 @@ bool GameBoard::hold(Rotation initialRotation) {
this->rotate(initialRotation);
// if the piece can't spawn, abort initial rotation
if (this->isActivePieceInWall()) {
if (this->activePieceInWall()) {
this->activePiece = std::make_shared<Piece>(stored);
// if the piece still can't spawn, abort holding
if (this->isActivePieceInWall()) {
if (this->activePieceInWall()) {
if (isFirstTimeHolding) {
this->activePiece = nullptr;
}
@@ -219,16 +219,16 @@ bool GameBoard::spawnNextPiece() {
// this piece has done nothing yet
this->isLastMoveKick = false;
return !this->isActivePieceInWall();
return !this->activePieceInWall();
}
bool GameBoard::touchesGround() {
return this->isActivePieceInWall(Position{0, -1});
return this->activePieceInWall(Position{0, -1});
}
LineClear GameBoard::lockPiece() {
bool isLockedInPlace = (this->isActivePieceInWall(Position{0, 1}) && this->isActivePieceInWall(Position{1, 0})
&& this->isActivePieceInWall(Position{-1, 0}) && this->isActivePieceInWall(Position{0, -1}));
bool isLockedInPlace = (this->activePieceInWall(Position{0, 1}) && this->activePieceInWall(Position{1, 0})
&& this->activePieceInWall(Position{-1, 0}) && this->activePieceInWall(Position{0, -1}));
for (Position position : this->activePiece->getPositions()) {
this->board.changeBlock(position + this->activePiecePosition, this->activePiece->getBlockType());
@@ -268,14 +268,14 @@ std::vector<Piece> GameBoard::getNextPieces() const {
return this->nextQueue;
}
bool GameBoard::isActivePieceInWall(const Position& shift) const {
bool GameBoard::activePieceInWall(const Position& shift) const {
for (Position position : this->activePiece->getPositions()) {
if (this->board.getBlock(position + this->activePiecePosition + shift) != NOTHING) return true;
}
return false;
}
bool GameBoard::activePieceOverlapsOnePosition(const std::set<Position>& safePositions, const Position& shift) const {
bool GameBoard::activePieceOverlaps(const std::set<Position>& safePositions, const Position& shift) const {
for (Position position : this->activePiece->getPositions()) {
if (safePositions.contains(position + this->activePiecePosition + shift)) return true;
}