diff --git a/ThinkPink/mainwindow.cpp b/ThinkPink/mainwindow.cpp index 0515f5f..f5d0e8f 100644 --- a/ThinkPink/mainwindow.cpp +++ b/ThinkPink/mainwindow.cpp @@ -4,9 +4,10 @@ extern std::unique_ptr settings; // slots -void MainWindow::buttonPressed(QPushButton *button) { +void MainWindow::buttonPressed(QPushButton *button, int row, int column) { QString text = "\u2605"; button->setText(text); + //buttonGrid[row][column+1 % columns]->setText(text); } void MainWindow::newGame() { @@ -28,21 +29,24 @@ void MainWindow::initialiseGame() { void MainWindow::initialiseGameGrid() { 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 button_row; + for(int j = 0; j < columns; j++) { QPushButton * button = new QPushButton(this); button->setFixedSize(button_size); 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 connect(button, &QPushButton::clicked, [=](){ - buttonPressed(button); + buttonPressed(button, i, j); }); } + buttonGrid.push_back(std::move(button_row)); } } diff --git a/ThinkPink/mainwindow.h b/ThinkPink/mainwindow.h index 10ab5b8..73fc6ab 100644 --- a/ThinkPink/mainwindow.h +++ b/ThinkPink/mainwindow.h @@ -31,7 +31,7 @@ public: void initialiseMenuBar(); private slots: - void buttonPressed(QPushButton *button); + void buttonPressed(QPushButton *button, int row, int column); void newGame(); private: @@ -41,5 +41,6 @@ private: const double max_width; const double max_height; SameGame *game; + std::vector> buttonGrid; }; #endif // MAINWINDOW_H