allow resetting games

This commit is contained in:
2025-03-01 19:13:49 +01:00
parent 03281a6d70
commit d443b25de1
10 changed files with 97 additions and 14 deletions

View File

@@ -16,11 +16,7 @@ Board::Board(int width, int height) :
this->emptyRow.push_back(NOTHING);
}
// initialize grid
this->grid.clear();
for (int j = 0; j < height; j++) {
this->grid.push_back(this->emptyRow);
}
this->clearBoard();
}
void Board::changeBlock(const Position& position, Block block) {
@@ -76,6 +72,13 @@ int Board::clearRows() {
return clearedLines;
}
void Board::clearBoard() {
this->grid.clear();
for (int j = 0; j < height; j++) {
this->grid.push_back(this->emptyRow);
}
}
Block Board::getBlock(const Position& position) const {
if (position.x < 0 || position.x >= this->width || position.y < 0) return OUT_OF_BOUNDS;