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()
if (!m_gravityFlag) {
return;
}
for (int i = 0; i < xTiles(); ++i) {
if (applyGravity(i)) {
if (Prefs::sounds()) {
m_soundFall.start();
}
}
}
}
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;
for (int column = 0; column < xTiles(); ++column) {
int rptr = yTiles() - 1;
int wptr = yTiles() - 1;
while (rptr >= 0) {
if (field(TilePos(column, wptr)) != EMPTY) {
--rptr;
isAffected = true;
--wptr;
} 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()
......
......@@ -266,12 +266,6 @@ private: // functions
*/
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.
* @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