From e6db1caa2ba8a1aff79870e18a93d35e95e6475d Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Fri, 26 May 2023 00:13:50 +0200 Subject: [PATCH] :bug: Fixed duplicated overlaying button glitch --- ThinkPink/mainwindow.cpp | 17 ++++++++--------- ThinkPink/samegame.cpp | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ThinkPink/mainwindow.cpp b/ThinkPink/mainwindow.cpp index 7ada52f..de7ac91 100644 --- a/ThinkPink/mainwindow.cpp +++ b/ThinkPink/mainwindow.cpp @@ -16,21 +16,18 @@ void MainWindow::clearConnected(std::set> *connected) { for (auto i = connected->begin(); i != connected->end(); i++) { game->deleteCell((*i)[0], (*i)[1]); } + usleep(5000); // paranoia refreshButtonGrid(); qApp->processEvents(); } void MainWindow::refreshButtonGrid() { - QSize button_size(max_width/columns, max_height/rows); - QLayoutItem *wItem; - while ((wItem = ui->gameGridLayout->takeAt(0)) != 0) - delete wItem; + //QSize button_size(max_width/columns, max_height/rows); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { buttonGrid[i][j]->setStyleSheet("color: #FFFFFF; Font : 30pt; background-color: " + game->getCell(i,j) + "; border: none;"); buttonGrid[i][j]->setText(""); - buttonGrid[i][j]->setFixedSize(button_size); - ui->gameGridLayout->addWidget(buttonGrid[i][j], i, j); + //buttonGrid[i][j]->setFixedSize(button_size); } } qApp->processEvents(); @@ -40,7 +37,7 @@ void MainWindow::checkColumn(int column) { bool isEmpty; isEmpty = true; for (int row = 0; row < rows; row++) { - if (game->getCell(row, column) != "") + if (game->getCell(row, column) != "none") isEmpty = false; } if (isEmpty) { @@ -85,7 +82,7 @@ void MainWindow::bubbleBoxes(std::set> *connected) { // slots void MainWindow::buttonPressed(int row, int column) { - if(game->getCell(row, column) != "") { + if(game->getCell(row, column) != "none") { std::set> connected; game->getConnected(&connected, game->getCell(row, column), row, column); if ( connected.size() > 1) { @@ -101,7 +98,9 @@ void MainWindow::newGame() { newGameDialog.setText("Do you really want to start a new game?"); newGameDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); if (newGameDialog.exec() == QMessageBox::Yes) { - initialiseGame(); + game->initialiseGameMatrix(rows, columns); + refreshButtonGrid(); + ui->lcdScore->display(0); } } diff --git a/ThinkPink/samegame.cpp b/ThinkPink/samegame.cpp index d95b07b..27a9b4c 100644 --- a/ThinkPink/samegame.cpp +++ b/ThinkPink/samegame.cpp @@ -46,7 +46,7 @@ void SameGame::checkNeighbour(std::set> *connectedSet, QString } void SameGame::deleteCell(int row, int column) { - gameMatrix[row][column] = ""; + gameMatrix[row][column] = "none"; } void SameGame::getConnected(std::set> *connectedSet, QString color, int row, int column) {