You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.9 KiB
C++
100 lines
2.9 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
extern std::unique_ptr<QSettings> settings;
|
|
|
|
// event functions
|
|
void MainWindow::buttonPressed(QPushButton *button) {
|
|
QString text = "owo";
|
|
button->setText(text);
|
|
}
|
|
|
|
// initialisation functions
|
|
void MainWindow::initialiseGameGrid() {
|
|
qDebug() << "Number of rows: " << n_rows;
|
|
qDebug() << "Number of columns: " << n_columns;
|
|
qDebug() << "Colors: ";
|
|
for (long long i = 0; i < colors.size(); i++) {
|
|
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
|
|
|
|
connect(button, &QPushButton::clicked, [=](){
|
|
buttonPressed(button);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::initialiseGameMatrix() {
|
|
gameMatrix = std::vector<std::vector<QString>>();
|
|
|
|
srand (time(NULL));
|
|
std::vector<QString> 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"));
|
|
}
|
|
|
|
void MainWindow::initialiseMenuBar() {
|
|
ui->menuPlay->addAction(QIcon(":/icons/game.png"), "New Game");
|
|
ui->menuPlay->addSeparator();
|
|
}
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, n_rows(settings->value("size/rows", 9).toInt())
|
|
, n_columns(settings->value("size/columns", 9).toInt())
|
|
, colors(settings->value("colors/colors", QStringList() << "0xBD005E" << "0xFFC0CB" << "0xDB7093" << "0xF7A8B8" << "0x660033").toStringList())
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
initialiseGameMatrix();
|
|
initialiseGameGrid();
|
|
initialiseWindow();
|
|
initialiseMenuBar();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|