|
|
|
@ -18,23 +18,51 @@ void MainWindow::clearConnected(std::set<std::vector<int>> *connected) {
|
|
|
|
|
game->deleteCell((*i)[0], (*i)[1]);
|
|
|
|
|
}
|
|
|
|
|
refreshButtonGrid();
|
|
|
|
|
qApp->processEvents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::refreshButtonGrid() {
|
|
|
|
|
QSize button_size(max_width/columns, max_height/rows);
|
|
|
|
|
QLayoutItem *wItem;
|
|
|
|
|
while ((wItem = ui->gameGridLayout->takeAt(0)) != 0)
|
|
|
|
|
delete wItem;
|
|
|
|
|
for (int i = 0; i < rows; i++) {
|
|
|
|
|
for (int j = 0; j < columns; j++) {
|
|
|
|
|
buttonGrid[i][j]->setStyleSheet("color: #FFFFFF; Font : 30pt; background-color: " + game->getCell(i,j) + "; border: none;");
|
|
|
|
|
buttonGrid[i][j]->setText("");
|
|
|
|
|
buttonGrid[i][j]->setFixedSize(button_size);
|
|
|
|
|
ui->gameGridLayout->addWidget(buttonGrid[i][j], i, j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::bubbleUp(int row, int column) {
|
|
|
|
|
if (row > 0) {
|
|
|
|
|
QPushButton *tbutton = std::move(buttonGrid[row][column]);
|
|
|
|
|
buttonGrid[row][column] = std::move(buttonGrid[row-1][column]);
|
|
|
|
|
buttonGrid[row-1][column] = std::move(tbutton);
|
|
|
|
|
|
|
|
|
|
QString tcolor = game->getCell(row, column);
|
|
|
|
|
game->setCell(row, column, game->getCell(row-1, column));
|
|
|
|
|
game->setCell(row-1, column, tcolor);
|
|
|
|
|
bubbleUp(row-1, column);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void MainWindow::bubbleBoxes(std::set<std::vector<int>> *connected) {
|
|
|
|
|
usleep(400000);
|
|
|
|
|
for (auto i = connected->begin(); i != connected->end(); i++) {
|
|
|
|
|
bubbleUp((*i)[0], (*i)[1]);
|
|
|
|
|
}
|
|
|
|
|
refreshButtonGrid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// slots
|
|
|
|
|
void MainWindow::buttonPressed(int row, int column) {
|
|
|
|
|
std::set<std::vector<int>> connected;
|
|
|
|
|
game->getConnected(&connected, game->getCell(row, column), row, column);
|
|
|
|
|
if ( connected.size() > 1) {
|
|
|
|
|
clearConnected(&connected);
|
|
|
|
|
bubbleBoxes(&connected);
|
|
|
|
|
} else
|
|
|
|
|
ui->statusBar->showMessage("Only friends get Stars!", 2000);
|
|
|
|
|
}
|
|
|
|
@ -87,22 +115,31 @@ void MainWindow::initialiseWindow() {
|
|
|
|
|
|
|
|
|
|
void MainWindow::initialiseMenuBar() {
|
|
|
|
|
QAction *new_game_action = ui->menuPlay->addAction("New Game");
|
|
|
|
|
|
|
|
|
|
connect(new_game_action, SIGNAL(triggered()), this, SLOT(newGame()));
|
|
|
|
|
ui->menuPlay->addSeparator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::refreshSizes() {
|
|
|
|
|
max_width = MainWindow::width();
|
|
|
|
|
max_height = MainWindow::height() - ui->menuBar->height() - ui->lcdScore->height() - ui->statusBar->height();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
, max_height(519)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
this->setStyleSheet("color: #DB7093;");
|
|
|
|
|
|
|
|
|
|
QPalette pal = QPalette();
|
|
|
|
|
pal.setColor(QPalette::Window, 0xfff0f3);
|
|
|
|
|
pal.setColor(QPalette::Text, 0xa4133c);
|
|
|
|
|
this->setPalette(pal);
|
|
|
|
|
ui->menuPlay->setPalette(pal);
|
|
|
|
|
ui->menuBar->setStyleSheet("QMenuBar::item {color: #a4133c}");
|
|
|
|
|
refreshSizes();
|
|
|
|
|
game = new SameGame(rows, columns);
|
|
|
|
|
initialiseGame();
|
|
|
|
|
initialiseWindow();
|
|
|
|
|