From 643939180d4be7561793f235943230ff5d8febf6 Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Thu, 25 May 2023 23:55:33 +0200 Subject: [PATCH] :bug: Fixed checking of empty columns --- ThinkPink/mainwindow.cpp | 33 +++++++++++++++++++++------------ ThinkPink/mainwindow.h | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ThinkPink/mainwindow.cpp b/ThinkPink/mainwindow.cpp index e075ff5..7ada52f 100644 --- a/ThinkPink/mainwindow.cpp +++ b/ThinkPink/mainwindow.cpp @@ -14,7 +14,6 @@ void MainWindow::clearConnected(std::set> *connected) { qApp->processEvents(); usleep(550000); for (auto i = connected->begin(); i != connected->end(); i++) { - //buttonGrid[(*i)[0]][(*i)[1]]->setEnabled(false); game->deleteCell((*i)[0], (*i)[1]); } refreshButtonGrid(); @@ -34,6 +33,19 @@ void MainWindow::refreshButtonGrid() { 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) { @@ -61,15 +73,12 @@ void MainWindow::bubbleBoxes(std::set> *connected) { for (auto i = connected->begin(); i != connected->end(); i++) { bubbleUp((*i)[0], (*i)[1]); } - bool isEmpty; + refreshButtonGrid(); + qApp->processEvents(); + usleep(400000); for (int j = 0; j < columns; j++) { - isEmpty = true; - for (int i = 0; i < rows; i++) { - if (game->getCell(i, j) != "") - isEmpty = false; - } - if (isEmpty) - bubbleRight(j); + for (int x = 0; x < columns; x++) + checkColumn(j); } refreshButtonGrid(); } @@ -82,9 +91,9 @@ void MainWindow::buttonPressed(int row, int column) { if ( connected.size() > 1) { clearConnected(&connected); bubbleBoxes(&connected); - } - } else - ui->statusBar->showMessage("Only friends get Stars!", 2000); + } else + ui->statusBar->showMessage("Only friends get Stars!", 2000); + } } void MainWindow::newGame() { diff --git a/ThinkPink/mainwindow.h b/ThinkPink/mainwindow.h index d8481ec..e834f8c 100644 --- a/ThinkPink/mainwindow.h +++ b/ThinkPink/mainwindow.h @@ -32,6 +32,7 @@ public: void clearConnected(std::set> *connected); void refreshButtonGrid(); void refreshSizes(); + void checkColumn(int column); void bubbleRight(int column); void bubbleUp(int row, int column); void bubbleBoxes(std::set> *connected);