diff --git a/assignments/06/ThinkPink/mainwindow.cpp b/assignments/06/ThinkPink/mainwindow.cpp index 534b722..3bc05d1 100644 --- a/assignments/06/ThinkPink/mainwindow.cpp +++ b/assignments/06/ThinkPink/mainwindow.cpp @@ -18,11 +18,22 @@ void MainWindow::initialiseGameGrid() { qDebug() << colors.value(i); } + double max_width = MainWindow::width(); + double max_height = MainWindow::height() - ui->menuBar->height() - ui->labelScore->height(); + + qDebug() << "gameGridLayout width: " << max_width << " height: " << max_height; + + QSize button_size(max_width/n_columns, max_height/n_rows); + + qDebug() << "Width: " << button_size.width() << " Height: " << button_size.height(); + for(int i = 0; i < n_columns; i++) { for(int j = 0; j < n_rows; j++) { QPushButton * button = new QPushButton(this); + button->setFixedSize(button_size); + button->setStyleSheet("background-color: " + gameMatrix[j][i] + "; border: none;"); ui->gameGridLayout->addWidget(button, j, i); // Set size text etc. for each button @@ -34,6 +45,28 @@ void MainWindow::initialiseGameGrid() { } } +void MainWindow::initialiseGameMatrix() { + gameMatrix = std::vector>(); + + srand (time(NULL)); + std::vector t_row; + for (int i = 0; i < n_rows; i++) { + t_row.clear(); + for (int j = 0; j < n_columns; j++) { + // wähle zufällige Farbe aus den verfügbaren Farben + t_row.push_back( colors[rand() % colors.size()] ); + } + gameMatrix.push_back(std::move(t_row)); + } + + for (int i = 0; i < n_rows; i++) { + qDebug() << "row: " << i; + for (int j = 0; j < n_columns; j++) { + qDebug() << gameMatrix[i][j]; + } + } +} + void MainWindow::initialiseWindow() { MainWindow::setWindowTitle("ThinkPink | SameGame in PINK by Isifluff"); MainWindow::setWindowIcon(QIcon(":/icons/ThinkPink.png")); @@ -42,7 +75,6 @@ void MainWindow::initialiseWindow() { void MainWindow::initialiseMenuBar() { ui->menuPlay->addAction(QIcon(":/icons/game.png"), "New Game"); ui->menuPlay->addSeparator(); - //ui->menuPlay->addAction("Brag"); } MainWindow::MainWindow(QWidget *parent) @@ -54,6 +86,7 @@ MainWindow::MainWindow(QWidget *parent) { ui->setupUi(this); + initialiseGameMatrix(); initialiseGameGrid(); initialiseWindow(); initialiseMenuBar(); diff --git a/assignments/06/ThinkPink/mainwindow.h b/assignments/06/ThinkPink/mainwindow.h index f7a1bc1..1269dcf 100644 --- a/assignments/06/ThinkPink/mainwindow.h +++ b/assignments/06/ThinkPink/mainwindow.h @@ -1,10 +1,11 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H - -#include +#include +#include #include #include +#include #include #include #include @@ -22,6 +23,7 @@ public: ~MainWindow(); // initialisation functions void initialiseGameGrid(); + void initialiseGameMatrix(); void initialiseWindow(); void initialiseMenuBar(); @@ -33,5 +35,8 @@ private: const int n_rows; const int n_columns; const QStringList colors; + + // mein Instinkt sagt mir, dass das hier hässlich ist: + std::vector> gameMatrix; }; #endif // MAINWINDOW_H diff --git a/assignments/06/ThinkPink/mainwindow.ui b/assignments/06/ThinkPink/mainwindow.ui index 4484055..57ee56e 100644 --- a/assignments/06/ThinkPink/mainwindow.ui +++ b/assignments/06/ThinkPink/mainwindow.ui @@ -14,106 +14,100 @@ MainWindow - - - - 0 - 0 - 801 - 441 - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - <html><head/><body><p><span style=" font-size:20pt;">Score</span></p></body></html> - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - false - - - 5 - - - QLCDNumber::Dec - - - QLCDNumber::Flat - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + <html><head/><body><p><span style=" font-size:20pt;">Score</span></p></body></html> + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + false + + + 5 + + + QLCDNumber::Dec + + + QLCDNumber::Flat + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +