🐛 Fixed checking of empty columns

main
Isabell Pflug 1 year ago
parent f8d9eb1a50
commit 643939180d

@ -14,7 +14,6 @@ void MainWindow::clearConnected(std::set<std::vector<int>> *connected) {
qApp->processEvents(); qApp->processEvents();
usleep(550000); usleep(550000);
for (auto i = connected->begin(); i != connected->end(); i++) { for (auto i = connected->begin(); i != connected->end(); i++) {
//buttonGrid[(*i)[0]][(*i)[1]]->setEnabled(false);
game->deleteCell((*i)[0], (*i)[1]); game->deleteCell((*i)[0], (*i)[1]);
} }
refreshButtonGrid(); refreshButtonGrid();
@ -34,6 +33,19 @@ void MainWindow::refreshButtonGrid() {
ui->gameGridLayout->addWidget(buttonGrid[i][j], i, j); ui->gameGridLayout->addWidget(buttonGrid[i][j], i, j);
} }
} }
qApp->processEvents();
}
void MainWindow::checkColumn(int column) {
bool isEmpty;
isEmpty = true;
for (int row = 0; row < rows; row++) {
if (game->getCell(row, column) != "")
isEmpty = false;
}
if (isEmpty) {
bubbleRight(column);
}
} }
void MainWindow::bubbleRight(int column) { void MainWindow::bubbleRight(int column) {
@ -61,15 +73,12 @@ void MainWindow::bubbleBoxes(std::set<std::vector<int>> *connected) {
for (auto i = connected->begin(); i != connected->end(); i++) { for (auto i = connected->begin(); i != connected->end(); i++) {
bubbleUp((*i)[0], (*i)[1]); bubbleUp((*i)[0], (*i)[1]);
} }
bool isEmpty; refreshButtonGrid();
qApp->processEvents();
usleep(400000);
for (int j = 0; j < columns; j++) { for (int j = 0; j < columns; j++) {
isEmpty = true; for (int x = 0; x < columns; x++)
for (int i = 0; i < rows; i++) { checkColumn(j);
if (game->getCell(i, j) != "")
isEmpty = false;
}
if (isEmpty)
bubbleRight(j);
} }
refreshButtonGrid(); refreshButtonGrid();
} }
@ -82,9 +91,9 @@ void MainWindow::buttonPressed(int row, int column) {
if ( connected.size() > 1) { if ( connected.size() > 1) {
clearConnected(&connected); clearConnected(&connected);
bubbleBoxes(&connected); bubbleBoxes(&connected);
} } else
} else ui->statusBar->showMessage("Only friends get Stars!", 2000);
ui->statusBar->showMessage("Only friends get Stars!", 2000); }
} }
void MainWindow::newGame() { void MainWindow::newGame() {

@ -32,6 +32,7 @@ public:
void clearConnected(std::set<std::vector<int>> *connected); void clearConnected(std::set<std::vector<int>> *connected);
void refreshButtonGrid(); void refreshButtonGrid();
void refreshSizes(); void refreshSizes();
void checkColumn(int column);
void bubbleRight(int column); void bubbleRight(int column);
void bubbleUp(int row, int column); void bubbleUp(int row, int column);
void bubbleBoxes(std::set<std::vector<int>> *connected); void bubbleBoxes(std::set<std::vector<int>> *connected);

Loading…
Cancel
Save