Added deletion of clicked cells after getting scored

main
Isabell Pflug 1 year ago
parent 8e4d58372f
commit 6927789f1b

@ -3,18 +3,38 @@
extern std::unique_ptr<QSettings> settings; extern std::unique_ptr<QSettings> settings;
void MainWindow::clearConnected(std::set<std::vector<int>> *connected) {
QString text = "\u2605";
int n = connected->size();
int new_score = ui->lcdScore->intValue() + (n * (n-1));
ui->lcdScore->display(new_score);
for (auto i = connected->begin(); i != connected->end(); i++) {
buttonGrid[(*i)[0]][(*i)[1]]->setText(text);
}
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();
}
void MainWindow::refreshButtonGrid() {
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("");
}
}
}
// slots // slots
void MainWindow::buttonPressed(int row, int column) { void MainWindow::buttonPressed(int row, int column) {
QString text = "\u2605";
std::set<std::vector<int>> connected; std::set<std::vector<int>> connected;
game->getConnected(&connected, game->getCell(row, column), row, column); game->getConnected(&connected, game->getCell(row, column), row, column);
if ( connected.size() > 1) { if ( connected.size() > 1) {
int n = connected.size(); clearConnected(&connected);
int new_score = ui->lcdScore->intValue() + (n * (n-1));
ui->lcdScore->display(new_score);
for (auto i = connected.begin(); i != connected.end(); i++) {
buttonGrid[(*i)[0]][(*i)[1]]->setText(text);
}
} else } else
ui->statusBar->showMessage("Only friends get Stars!", 2000); ui->statusBar->showMessage("Only friends get Stars!", 2000);
} }

@ -29,6 +29,8 @@ public:
void initialiseGameGrid(); void initialiseGameGrid();
void initialiseWindow(); void initialiseWindow();
void initialiseMenuBar(); void initialiseMenuBar();
void clearConnected(std::set<std::vector<int>> *connected);
void refreshButtonGrid();
private slots: private slots:
void buttonPressed(int row, int column); void buttonPressed(int row, int column);

@ -41,6 +41,10 @@ void SameGame::checkNeighbour(std::set<std::vector<int>> *connectedSet, QString
} }
} }
void SameGame::deleteCell(int row, int column) {
gameMatrix[row][column] = "";
}
void SameGame::getConnected(std::set<std::vector<int>> *connectedSet, QString color, int row, int column) { void SameGame::getConnected(std::set<std::vector<int>> *connectedSet, QString color, int row, int column) {
std::vector<int> cellCoords; std::vector<int> cellCoords;
cellCoords.push_back(row); cellCoords.push_back(row);

@ -17,6 +17,7 @@ public:
QString getCell(int row, int column); QString getCell(int row, int column);
void checkNeighbour(std::set<std::vector<int>> *connectedSet, QString color, int row, int column); void checkNeighbour(std::set<std::vector<int>> *connectedSet, QString color, int row, int column);
void getConnected(std::set<std::vector<int>> *connectedSet, QString color, int row, int column); void getConnected(std::set<std::vector<int>> *connectedSet, QString color, int row, int column);
void deleteCell(int row, int column);
}; };
#endif // SAMEGAME_H #endif // SAMEGAME_H

Loading…
Cancel
Save