From c01b6fddb4861df9153b6adb7381e16736e26fff Mon Sep 17 00:00:00 2001 From: Isabell Pflug Date: Fri, 26 May 2023 14:05:35 +0200 Subject: [PATCH] :construction: Added provisional "Game over" status text --- ThinkPink/mainwindow.cpp | 23 +++++++++++++++++++++++ ThinkPink/mainwindow.h | 1 + 2 files changed, 24 insertions(+) diff --git a/ThinkPink/mainwindow.cpp b/ThinkPink/mainwindow.cpp index f7ba897..bc71472 100644 --- a/ThinkPink/mainwindow.cpp +++ b/ThinkPink/mainwindow.cpp @@ -44,6 +44,22 @@ void MainWindow::checkColumn(int column) { } } +bool MainWindow::checkLeftoverMoves() { + for(int row = 0; row < rows; row++) { + for(int column = 0; column < columns; column++) + { + if (game->getCell(row,column) != "none") { + std::set> tset; + game->getConnected(&tset, game->getCell(row,column), row, column); + if (tset.size() > 1) { + return true; + } + } + } + } + return false; +} + void MainWindow::bubbleRight(int column) { if (column < columns-1) { for (int row = 0; row < rows; row++) { @@ -92,9 +108,13 @@ void MainWindow::buttonPressed(int row, int column) { ui->statusBar->showMessage("Only friends get Stars!", 2000); } MainWindow::setEnabled(true); + if (!checkLeftoverMoves()) { + ui->statusBar->showMessage("Game over."); + } } void MainWindow::newGame() { + ui->statusBar->clearMessage(); MainWindow::setEnabled(false); QMessageBox newGameDialog; newGameDialog.setText("Do you really want to start a new game?"); @@ -105,6 +125,9 @@ void MainWindow::newGame() { ui->lcdScore->display(0); } MainWindow::setEnabled(true); + if (!checkLeftoverMoves()) { + ui->statusBar->showMessage("Game over."); + } } // initialisation functions diff --git a/ThinkPink/mainwindow.h b/ThinkPink/mainwindow.h index a8d32fa..7d21385 100644 --- a/ThinkPink/mainwindow.h +++ b/ThinkPink/mainwindow.h @@ -34,6 +34,7 @@ public: void refreshButtonGrid(); void refreshSizes(); void checkColumn(int column); + bool checkLeftoverMoves(); void bubbleRight(int column); void bubbleUp(int row, int column); void bubbleBoxes(std::set> *connected);