Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tetris/src/game/tetromino.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,25 @@ void Tetromino::moveRight(std::vector<std::vector<std::string>> grid)

void Tetromino::hardDrop(const std::vector<Coords>& boardBaseline)
{
// Trim empty rows at bottom of the 4x4 bounding box
std::int16_t pieceBottom = y.begin;
for (auto row = y.begin; row <= y.end; ++row) {
for (auto col = x.begin; col <= x.end; ++col) {
if (matrix[row - y.begin][col - x.begin] != " ") {
pieceBottom = row;
break;
}
}
}
std::int16_t pieceHeight = pieceBottom - y.begin + 1;

std::int16_t highestY = boardBaseline[0].y;
for (const auto& coord : boardBaseline)
{
if (coord.y < highestY) highestY = coord.y;
}
y.end = highestY;
y.begin = static_cast<std::int16_t>(y.end - matrix.size() + 1);
y.begin = static_cast<std::int16_t>(y.end - pieceHeight + 1);
}

void Tetromino::softDrop()
Expand Down