Commit e92b0159 authored by Frederik Schwarzer's avatar Frederik Schwarzer
Browse files

Apply gravity on all columns again.

Restricting gravitiy to those columns with removed tiles only breaks if slides are involved.
parent ed3bb889
......@@ -217,17 +217,12 @@ int Board::field(TilePos const & tilePos) const
return m_field.at(tilePos.y() * xTiles() + tilePos.x());
}
void Board::applyGravity(TilePos const tilePos1, TilePos const tilePos2)
void Board::applyGravity()
{
if (!m_gravityFlag) {
return;
}
// If both removed tiles are in the same column, we iterate over the same
// column twice but all ideas I had to prevent that from happening seemed
// more complex than living with that second iteration once in a while.
// Maybe later ... (schwarzer)
std::array<int, 2> const affectedColumns {{tilePos1.x(), tilePos2.x()}};
for (auto const column : affectedColumns) {
for (decltype(xTiles()) column = 0; column < xTiles(); ++column) {
auto rptr = yTiles() - 1;
auto wptr = yTiles() - 1;
while (rptr >= 0) {
......@@ -1325,7 +1320,7 @@ void Board::undrawConnection()
if (m_tileRemove1.x() != -1) {
setField(m_tileRemove1, EMPTY);
setField(m_tileRemove2, EMPTY);
applyGravity(m_tileRemove1, m_tileRemove2);
applyGravity();
m_tileRemove1.setX(-1);
update();
emit tileCountChanged();
......@@ -1656,7 +1651,7 @@ void Board::redo()
setField(TilePos(move->x2(), move->y2()), EMPTY);
repaintTile(TilePos(move->x1(), move->y1()));
repaintTile(TilePos(move->x2(), move->y2()));
applyGravity(TilePos(move->x1(), move->y1()), TilePos(move->x2(), move->y2()));
applyGravity();
m_undo.push_back(move);
emit changed();
}
......
......@@ -275,11 +275,8 @@ private: // functions
void marked(TilePos const & tilePos);
void madeMove(TilePos const & tilePos1, TilePos const & tilePos2, Slide slide = Slide());
/** Applies gravity to all columns.
* @param tilePos1 coordinates of the first tile
* @param tilePos2 coordinates of the second tile
*/
void applyGravity(TilePos const tilePos1, TilePos const tilePos2);
/// Applies gravity to all columns.
void applyGravity();
/** Returns True if @p tilePos is a valid position on Board.
* @return Whether @p tiePos is valid.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment