MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QFont f("Helvetica",10); this->setFont(f); LifeField = 0; OptionGroup = 0; GroupLayout = 0; isSimulationOn = false; LifeCount = 0; IterationCount = 0; WindowLayout= new QHBoxLayout; QWidget * mycentralwidget = new QWidget; mycentralwidget->setLayout(WindowLayout); this->setCentralWidget(mycentralwidget); this->setWindowTitle("Gra w Życie"); connect(this, SIGNAL(CellsChanged(int,int)), &Algorithm, SLOT(NewDimension(int,int))); connect(&Algorithm, SIGNAL(CellChanged(int,int,bool)),this, SLOT(FeedCell(int,int,bool))); connect(&Algorithm, SIGNAL(ChangeStatus(int,int)), this, SLOT(StatusUpdate(int,int))); connect(this, SIGNAL(CellsChanged(int,int,bool)), &Algorithm, SLOT(CellModified(int,int,bool))); connect(this, SIGNAL(FeedsChanger(int)), &Algorithm, SLOT(FeedsStatus(int))); //connect(&Algorithm, SIGNAL(Clear()),this, SLOT(CleanNow())); InitLifeField(); InitGroupBox(); RowsChanged(); ColumnsChanged(); this->setMinimumSize(700, 480); connect(ColumnChanger, SIGNAL(valueChanged(int)), this, SLOT(ColumnsChanged())); connect(RowChanger, SIGNAL(valueChanged(int)), this, SLOT(RowsChanged())); connect(Quiter, SIGNAL(clicked()), qApp, SLOT(quit())); connect(Generator, SIGNAL(clicked()),this, SLOT(GenerateField()) ); connect(Cleaner, SIGNAL(clicked()),this, SLOT(CleanNow())); connect(LifeField, SIGNAL(cellClicked(int, int)), this, SLOT(FeedCell(int, int))); connect(Starter,SIGNAL(clicked()),this ,SLOT(SimulationTrigger())); connect(OneMove,SIGNAL(clicked()),&Algorithm ,SLOT(SingleStep())); connect(comboBox, SIGNAL(activated(QString)), this, SLOT(Prepared(QString))); connect(this,SIGNAL(StartSimulation()), &Algorithm, SLOT(SetTimer())); connect(this, SIGNAL(StopSimulation()),&Algorithm, SLOT(StopTimer())); qsrand(QTime::currentTime().msecsTo(QTime(0,0,0,0))); }
//useful constructor, generates minefield and places mines minefield::minefield(int w, int h, int m) { srand(time(NULL)); width = w; height = h; num_mines = m; num_revealed = 0; field.resize(w); for (int i=0; i<w; ++i) { field[i].resize(h); } GenerateField(); }