Commit 96dbf1fd authored by Frederik Schwarzer's avatar Frederik Schwarzer

Merge two methods, they are shorter that way.

parent 956a62bf
...@@ -222,39 +222,30 @@ void Board::applyGravity() ...@@ -222,39 +222,30 @@ void Board::applyGravity()
if (!m_gravityFlag) { if (!m_gravityFlag) {
return; return;
} }
for (int i = 0; i < xTiles(); ++i) { for (int column = 0; column < xTiles(); ++column) {
if (applyGravity(i)) { int rptr = yTiles() - 1;
if (Prefs::sounds()) { int wptr = yTiles() - 1;
m_soundFall.start(); while (rptr >= 0) {
} if (field(TilePos(column, wptr)) != EMPTY) {
}
}
}
bool Board::applyGravity(int column)
{
bool isAffected = false;
int rptr = yTiles() - 1;
int wptr = yTiles() - 1;
while (rptr >= 0) {
if (field(TilePos(column, wptr)) != EMPTY) {
--rptr;
--wptr;
} else {
if (field(TilePos(column, rptr)) != EMPTY) {
setField(TilePos(column, wptr), field(TilePos(column, rptr)));
setField(TilePos(column, rptr), EMPTY);
updateField(TilePos(column, rptr));
updateField(TilePos(column, wptr));
--wptr;
--rptr; --rptr;
isAffected = true; --wptr;
} else { } else {
--rptr; if (field(TilePos(column, rptr)) != EMPTY) {
setField(TilePos(column, wptr), field(TilePos(column, rptr)));
setField(TilePos(column, rptr), EMPTY);
updateField(TilePos(column, rptr));
updateField(TilePos(column, wptr));
--wptr;
--rptr;
if (Prefs::sounds()) {
m_soundFall.start();
}
} else {
--rptr;
}
} }
} }
} }
return isAffected;
} }
void Board::unmarkTile() void Board::unmarkTile()
......
...@@ -266,12 +266,6 @@ private: // functions ...@@ -266,12 +266,6 @@ private: // functions
*/ */
void applyGravity(); void applyGravity();
/** Applies gravity to the given column and returns whether it was affected.
* @param column The column to check
* @return If column was affected.
*/
bool applyGravity(int column);
/** Returns True if @p tilePos is a valid position on Board. /** Returns True if @p tilePos is a valid position on Board.
* @return Wether @p tiePos is valid. * @return Wether @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