|
|
|
@ -3,30 +3,33 @@
|
|
|
|
|
|
|
|
|
|
extern std::unique_ptr<QSettings> settings;
|
|
|
|
|
|
|
|
|
|
// event functions
|
|
|
|
|
// slots
|
|
|
|
|
void MainWindow::buttonPressed(QPushButton *button) {
|
|
|
|
|
QString text = "\u2605";
|
|
|
|
|
button->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// initialisation functions
|
|
|
|
|
void MainWindow::initialiseGameGrid() {
|
|
|
|
|
double max_width = MainWindow::width();
|
|
|
|
|
double max_height = MainWindow::height() - ui->menuBar->height() - ui->labelScore->height();
|
|
|
|
|
|
|
|
|
|
qDebug() << "gameGridLayout width: " << max_width << " height: " << max_height;
|
|
|
|
|
void MainWindow::newGame() {
|
|
|
|
|
initialiseGame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize button_size(max_width/n_columns, max_height/n_rows);
|
|
|
|
|
// initialisation functions
|
|
|
|
|
void MainWindow::initialiseGame() {
|
|
|
|
|
game->initialiseGameMatrix(rows, columns);
|
|
|
|
|
initialiseGameGrid();
|
|
|
|
|
ui->lcdScore->display(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qDebug() << "Width: " << button_size.width() << " Height: " << button_size.height();
|
|
|
|
|
void MainWindow::initialiseGameGrid() {
|
|
|
|
|
QSize button_size(max_width/columns, max_height/rows);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < n_columns; i++)
|
|
|
|
|
for(int i = 0; i < columns; i++)
|
|
|
|
|
{
|
|
|
|
|
for(int j = 0; j < n_rows; j++)
|
|
|
|
|
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;");
|
|
|
|
|
button->setStyleSheet("background-color: " + game->getCell(i,j) + "; border: none;");
|
|
|
|
|
ui->gameGridLayout->addWidget(button, j, i);
|
|
|
|
|
|
|
|
|
|
// Set size text etc. for each button
|
|
|
|
@ -44,26 +47,31 @@ void MainWindow::initialiseWindow() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::initialiseMenuBar() {
|
|
|
|
|
ui->menuPlay->addAction(QIcon(":/icons/game.png"), "New Game");
|
|
|
|
|
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)
|
|
|
|
|
, n_rows(settings->value("size/rows", 9).toInt())
|
|
|
|
|
, n_columns(settings->value("size/columns", 9).toInt())
|
|
|
|
|
, game(n_rows, n_columns)
|
|
|
|
|
, rows(settings->value("size/rows", 9).toInt())
|
|
|
|
|
, columns(settings->value("size/columns", 9).toInt())
|
|
|
|
|
, max_width(800)
|
|
|
|
|
, max_height(544)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
|
|
initialiseGameGrid();
|
|
|
|
|
game = new SameGame(rows, columns);
|
|
|
|
|
initialiseGame();
|
|
|
|
|
initialiseWindow();
|
|
|
|
|
initialiseMenuBar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete game;
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|