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.
83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
extern std::unique_ptr<QSettings> settings;
|
|
|
|
// slots
|
|
void MainWindow::buttonPressed(QPushButton *button) {
|
|
QString text = "\u2605";
|
|
button->setText(text);
|
|
}
|
|
|
|
void MainWindow::newGame() {
|
|
QMessageBox newGameDialog;
|
|
newGameDialog.setText("Do you really want to start a new game?");
|
|
newGameDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
|
if (newGameDialog.exec() == QMessageBox::Yes) {
|
|
initialiseGame();
|
|
}
|
|
}
|
|
|
|
// initialisation functions
|
|
void MainWindow::initialiseGame() {
|
|
game->initialiseGameMatrix(rows, columns);
|
|
initialiseGameGrid();
|
|
ui->lcdScore->display(0);
|
|
}
|
|
|
|
void MainWindow::initialiseGameGrid() {
|
|
QSize button_size(max_width/columns, max_height/rows);
|
|
|
|
for(int i = 0; i < columns; i++)
|
|
{
|
|
for(int j = 0; j < rows; j++)
|
|
{
|
|
QPushButton * button = new QPushButton(this);
|
|
button->setFixedSize(button_size);
|
|
button->setStyleSheet("background-color: " + game->getCell(i,j) + "; border: none;");
|
|
ui->gameGridLayout->addWidget(button, j, i);
|
|
|
|
// Set size text etc. for each button
|
|
|
|
connect(button, &QPushButton::clicked, [=](){
|
|
buttonPressed(button);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::initialiseWindow() {
|
|
MainWindow::setWindowTitle("ThinkPink | SameGame in PINK by Isifluff");
|
|
MainWindow::setWindowIcon(QIcon(":/icons/ThinkPink.png"));
|
|
}
|
|
|
|
void MainWindow::initialiseMenuBar() {
|
|
QAction *new_game_action = ui->menuPlay->addAction(QIcon(":/icons/game.png"), "New Game");
|
|
|
|
connect(new_game_action, SIGNAL(triggered()), this, SLOT(newGame()));
|
|
ui->menuPlay->addSeparator();
|
|
}
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, rows(settings->value("size/rows", 9).toInt())
|
|
, columns(settings->value("size/columns", 9).toInt())
|
|
, max_width(800)
|
|
, max_height(544)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
game = new SameGame(rows, columns);
|
|
initialiseGame();
|
|
initialiseWindow();
|
|
initialiseMenuBar();
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete game;
|
|
delete ui;
|
|
}
|
|
|