Added button matrix to keep track of the game boxes

main
Isabell Pflug 2 years ago
parent 89d36717d5
commit c05fdd2265

@ -4,9 +4,10 @@
extern std::unique_ptr<QSettings> settings; extern std::unique_ptr<QSettings> settings;
// slots // slots
void MainWindow::buttonPressed(QPushButton *button) { void MainWindow::buttonPressed(QPushButton *button, int row, int column) {
QString text = "\u2605"; QString text = "\u2605";
button->setText(text); button->setText(text);
//buttonGrid[row][column+1 % columns]->setText(text);
} }
void MainWindow::newGame() { void MainWindow::newGame() {
@ -28,21 +29,24 @@ void MainWindow::initialiseGame() {
void MainWindow::initialiseGameGrid() { void MainWindow::initialiseGameGrid() {
QSize button_size(max_width/columns, max_height/rows); QSize button_size(max_width/columns, max_height/rows);
for(int i = 0; i < columns; i++) for(int i = 0; i < rows; i++)
{ {
for(int j = 0; j < rows; j++) std::vector<QPushButton *> button_row;
for(int j = 0; j < columns; j++)
{ {
QPushButton * button = new QPushButton(this); QPushButton * button = new QPushButton(this);
button->setFixedSize(button_size); button->setFixedSize(button_size);
button->setStyleSheet("color: #FFFFFF; Font : 30pt; background-color: " + game->getCell(i,j) + "; border: none;"); button->setStyleSheet("color: #FFFFFF; Font : 30pt; background-color: " + game->getCell(i,j) + "; border: none;");
ui->gameGridLayout->addWidget(button, j, i); ui->gameGridLayout->addWidget(button, i, j);
button_row.push_back(button);
// Set size text etc. for each button // Set size text etc. for each button
connect(button, &QPushButton::clicked, [=](){ connect(button, &QPushButton::clicked, [=](){
buttonPressed(button); buttonPressed(button, i, j);
}); });
} }
buttonGrid.push_back(std::move(button_row));
} }
} }

@ -31,7 +31,7 @@ public:
void initialiseMenuBar(); void initialiseMenuBar();
private slots: private slots:
void buttonPressed(QPushButton *button); void buttonPressed(QPushButton *button, int row, int column);
void newGame(); void newGame();
private: private:
@ -41,5 +41,6 @@ private:
const double max_width; const double max_width;
const double max_height; const double max_height;
SameGame *game; SameGame *game;
std::vector<std::vector<QPushButton *>> buttonGrid;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

Loading…
Cancel
Save