diff --git a/src/localGameDialog/localGameDialog.cpp b/src/localGameDialog/localGameDialog.cpp index 7012264..30f0a12 100644 --- a/src/localGameDialog/localGameDialog.cpp +++ b/src/localGameDialog/localGameDialog.cpp @@ -11,6 +11,26 @@ LocalGameDialog::~LocalGameDialog() { delete ui; } +LocalGameConfig LocalGameDialog::config() const { + LocalGameConfig config; + config.gameSpeed = ui->spinBox_gameSpeed->value(); + config.enableSounds = ui->checkBox_enableSounds->isChecked(); + config.showAnalysis = ui->checkBox_showAnalysis->isChecked(); + config.mapName = ui->comboBox_gameMap->currentText(); + config.mapWidth = ui->spinBox_mapWidth->value(); + config.mapHeight = ui->spinBox_mapHeight->value(); + int numPlayers = ui->spinBox_numPlayers->value(); + auto& players = config.players; + players.resize(numPlayers); + QLayout* layout = ui->groupBox_players->layout(); + for(int i = 0; i < numPlayers; ++i) { + QWidget* playerWidget = layout->itemAt(i + 1)->widget(); + players[i].name = playerWidget->findChild()->currentText(); + players[i].visible = playerWidget->findChild()->isChecked(); + } + return config; +} + void LocalGameDialog::on_btnStartGame_clicked() { this->done(QDialog::Accepted); } diff --git a/src/localGameDialog/localGameDialog.h b/src/localGameDialog/localGameDialog.h index cf8314f..03113ac 100644 --- a/src/localGameDialog/localGameDialog.h +++ b/src/localGameDialog/localGameDialog.h @@ -9,6 +9,18 @@ namespace Ui { } QT_END_NAMESPACE +struct LocalGameConfig { + int gameSpeed; + bool enableSounds, showAnalysis; + QString mapName; + int mapWidth, mapHeight; + struct PlayerConfig { + QString name; + bool visible; + }; + QVector players; +}; + class LocalGameDialog : public QDialog { Q_OBJECT @@ -16,6 +28,8 @@ class LocalGameDialog : public QDialog { LocalGameDialog(QWidget* parent = nullptr); ~LocalGameDialog(); + LocalGameConfig config() const; + public slots: void on_btnStartGame_clicked(); void on_btnCancel_clicked(); diff --git a/src/localGameWindow/localGameWindow.cpp b/src/localGameWindow/localGameWindow.cpp index 95b8ba2..6f8a71b 100644 --- a/src/localGameWindow/localGameWindow.cpp +++ b/src/localGameWindow/localGameWindow.cpp @@ -1,10 +1,10 @@ #include "localGameWindow.h" #include -LocalGameWindow::LocalGameWindow(QWidget* parent) : - QDialog(parent), gameMap(nullptr) { +LocalGameWindow::LocalGameWindow(QWidget* parent, const LocalGameConfig& config) : + QDialog(parent) { setWindowTitle("Local Game"); - gameMap = new MapWidget(this); + gameMap = new MapWidget(this, config.mapWidth, config.mapHeight); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(gameMap); setLayout(layout); diff --git a/src/localGameWindow/localGameWindow.h b/src/localGameWindow/localGameWindow.h index bab42b9..999fe33 100644 --- a/src/localGameWindow/localGameWindow.h +++ b/src/localGameWindow/localGameWindow.h @@ -3,12 +3,13 @@ #include #include "../mapWidget/mapWidget.h" +#include "../localGameDialog/localGameDialog.h" class LocalGameWindow : public QDialog { Q_OBJECT public: - LocalGameWindow(QWidget* parent = nullptr); + explicit LocalGameWindow(QWidget* parent, const LocalGameConfig& config); ~LocalGameWindow(); private: diff --git a/src/mainWindow/mainWindow.cpp b/src/mainWindow/mainWindow.cpp index e7c7dd0..b41143d 100644 --- a/src/mainWindow/mainWindow.cpp +++ b/src/mainWindow/mainWindow.cpp @@ -16,7 +16,7 @@ void MainWindow::on_btnLocalGame_clicked() { LocalGameDialog* dialog = new LocalGameDialog(this); int result = dialog->exec(); if(result == QDialog::Accepted) { - LocalGameWindow* window = new LocalGameWindow(this); + LocalGameWindow* window = new LocalGameWindow(this, dialog->config()); window->exec(); } } diff --git a/src/mainWindow/mainWindow.h b/src/mainWindow/mainWindow.h index 2272725..11b871e 100644 --- a/src/mainWindow/mainWindow.h +++ b/src/mainWindow/mainWindow.h @@ -13,7 +13,7 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(QWidget* parent = nullptr); + explicit MainWindow(QWidget* parent = nullptr); ~MainWindow(); public slots: diff --git a/src/mapWidget/mapWidget.cpp b/src/mapWidget/mapWidget.cpp index d8b76d2..fc25b6e 100644 --- a/src/mapWidget/mapWidget.cpp +++ b/src/mapWidget/mapWidget.cpp @@ -4,9 +4,8 @@ #include #include -MapWidget::MapWidget(QWidget* parent) : - QWidget(parent), scale(1.0), offset(0, 0), isDragging(false) { - // setFixedSize(800, 600); +MapWidget::MapWidget(QWidget* parent, int w, int h) : + QWidget(parent), scale(1.0), offset(0, 0), isDragging(false), width(w), height(h) { setMouseTracking(true); } @@ -19,12 +18,11 @@ void MapWidget::paintEvent(QPaintEvent* event) { painter.translate(offset); painter.scale(scale, scale); - const int gridSize = 20; - const qreal cellSize = 300.0 / gridSize; + const qreal cellWidth = 300.0 / width, cellHeight = 300.0 / height; - for(int i = 0; i < gridSize; ++i) { - for(int j = 0; j < gridSize; ++j) { - QRectF cell(i * cellSize, j * cellSize, cellSize, cellSize); + for(int i = 0; i < width; ++i) { + for(int j = 0; j < height; ++j) { + QRectF cell(i * cellWidth, j * cellHeight, cellWidth, cellHeight); painter.drawRect(cell); int randomNumber = QRandomGenerator::global()->bounded(10); diff --git a/src/mapWidget/mapWidget.h b/src/mapWidget/mapWidget.h index eed4fef..b27792e 100644 --- a/src/mapWidget/mapWidget.h +++ b/src/mapWidget/mapWidget.h @@ -8,8 +8,9 @@ class MapWidget : public QWidget { Q_OBJECT public: - explicit MapWidget(QWidget* parent = nullptr); + explicit MapWidget(QWidget* parent, int w, int h); ~MapWidget(); + const int width, height; protected: void paintEvent(QPaintEvent* event) override;