From f8d9eb1a5021452a9e7bc350e5814ead26ac4408 Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Thu, 25 May 2023 22:48:34 +0200 Subject: [PATCH] :tada: Added previously forgotten bubbleRight function. Now it seems to be really done! --- ThinkPink/mainwindow.cpp | 25 +++++++++++++++++++++---- ThinkPink/mainwindow.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ThinkPink/mainwindow.cpp b/ThinkPink/mainwindow.cpp index 4c19b3e..e075ff5 100644 --- a/ThinkPink/mainwindow.cpp +++ b/ThinkPink/mainwindow.cpp @@ -36,12 +36,19 @@ void MainWindow::refreshButtonGrid() { } } +void MainWindow::bubbleRight(int column) { + if (column < columns-1) { + for (int row = 0; row < rows; row++) { + QString tcolor = game->getCell(row, column); + game->setCell(row, column, game->getCell(row, column+1)); + game->setCell(row, column+1, tcolor); + } + bubbleRight(column+1); + } +} + void MainWindow::bubbleUp(int row, int column) { if (row > 0) { - /*QPushButton *tbutton = std::move(buttonGrid[row][column]); - buttonGrid[row][column] = std::move(buttonGrid[row-1][column]); - buttonGrid[row-1][column] = std::move(tbutton);*/ - QString tcolor = game->getCell(row, column); game->setCell(row, column, game->getCell(row-1, column)); game->setCell(row-1, column, tcolor); @@ -54,6 +61,16 @@ void MainWindow::bubbleBoxes(std::set> *connected) { for (auto i = connected->begin(); i != connected->end(); i++) { bubbleUp((*i)[0], (*i)[1]); } + bool isEmpty; + 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); + } refreshButtonGrid(); } diff --git a/ThinkPink/mainwindow.h b/ThinkPink/mainwindow.h index 56ddd8e..d8481ec 100644 --- a/ThinkPink/mainwindow.h +++ b/ThinkPink/mainwindow.h @@ -32,6 +32,7 @@ public: void clearConnected(std::set> *connected); void refreshButtonGrid(); void refreshSizes(); + void bubbleRight(int column); void bubbleUp(int row, int column); void bubbleBoxes(std::set> *connected);