|
@@ -3,51 +3,50 @@
|
|
|
*/
|
|
|
#include "include/hotseatgame/gamemanager.h"
|
|
|
#include "cell.h"
|
|
|
+#include "hotseatgame/gameproperties.h"
|
|
|
#include <iostream>
|
|
|
+#include <cmath>
|
|
|
|
|
|
GameManager::GameManager(QObject *parent) : QObject(parent) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-void GameManager::buildGameTable(int colSize, int rowSize, double radius,
|
|
|
- double start_x_coordinate, double start_y_coordinate) {
|
|
|
- col_table_size_ = colSize;
|
|
|
- row_table_size_ = rowSize;
|
|
|
- cell_radius_ = radius;
|
|
|
+void GameManager::buildGameTable(double start_x_coordinate, double start_y_coordinate) {
|
|
|
start_x_coordinate_ = start_x_coordinate;
|
|
|
start_y_coordinate_ = start_y_coordinate;
|
|
|
generateTable();
|
|
|
}
|
|
|
|
|
|
void GameManager::generateTable() {
|
|
|
- game_table_.assign(col_table_size_, std::vector< Cell* >(row_table_size_, nullptr));
|
|
|
- for (int col = 0; col < col_table_size_; ++col) {
|
|
|
- for (int row = 0; row < row_table_size_; ++row) {
|
|
|
- game_table_[col][row] = new Cell();
|
|
|
+ game_table_.assign(GameProperties::FIELD_COLUMNS_NUMBER, std::vector< Cell* >(GameProperties::FIELD_ROWS_NUMBER, nullptr));
|
|
|
+ for (unsigned row = 0; row < GameProperties::FIELD_ROWS_NUMBER; ++row) {
|
|
|
+ for (unsigned col = 0; col < GameProperties::FIELD_COLUMNS_NUMBER; ++col) {
|
|
|
+ game_table_[col][row] = new Cell(nullptr);
|
|
|
}
|
|
|
}
|
|
|
- int isEven = 1;
|
|
|
- for (int col = 0; col < col_table_size_; ++col) {
|
|
|
+
|
|
|
+ unsigned isEven = 1;
|
|
|
+ for (unsigned row = 0; row < GameProperties::FIELD_ROWS_NUMBER; ++row) {
|
|
|
isEven ^= 1;
|
|
|
- for (int row = 0; row < row_table_size_; ++row) {
|
|
|
- if (col != 0 && row != 0 -isEven) {
|
|
|
- game_table_[col][row]->setleftUp(game_table_[col - 1][row - 1 +isEven]);
|
|
|
+ for (unsigned col = 0; col < GameProperties::FIELD_COLUMNS_NUMBER; ++col) {
|
|
|
+ if (row != 0 && col != 0 - isEven) {
|
|
|
+ game_table_[col][row]->setleftUp(game_table_[col - 1 +isEven][row - 1]);
|
|
|
}
|
|
|
- if (row != 0) {
|
|
|
- game_table_[col][row]->setleft(game_table_[col][row - 1]);
|
|
|
+ if (col != 0) {
|
|
|
+ game_table_[col][row]->setleft(game_table_[col - 1][row]);
|
|
|
}
|
|
|
- if (col != col_table_size_ - 1 && row != 0 -isEven) {
|
|
|
- game_table_[col][row]->setleftDown(game_table_[col + 1][row - 1 +isEven]);
|
|
|
+ if (row != GameProperties::FIELD_ROWS_NUMBER - 1 && col != 0 -isEven) {
|
|
|
+ game_table_[col][row]->setleftDown(game_table_[col - 1 +isEven][row + 1]);
|
|
|
}
|
|
|
|
|
|
- if (col != 0 && row != row_table_size_ -isEven) {
|
|
|
- game_table_[col][row]->setrightUp(game_table_[col - 1][row +isEven]);
|
|
|
+ if (row != 0 && col != GameProperties::FIELD_COLUMNS_NUMBER -isEven) {
|
|
|
+ game_table_[col][row]->setrightUp(game_table_[col +isEven][row - 1]);
|
|
|
}
|
|
|
- if (row != row_table_size_ - 1) {
|
|
|
- game_table_[col][row]->setright(game_table_[col][row + 1]);
|
|
|
+ if (col != GameProperties::FIELD_COLUMNS_NUMBER - 1) {
|
|
|
+ game_table_[col][row]->setright(game_table_[col + 1][row]);
|
|
|
}
|
|
|
- if (col != col_table_size_ - 1 && row != row_table_size_ -isEven) {
|
|
|
- game_table_[col][row]->setrightDown(game_table_[col + 1][row +isEven]);
|
|
|
+ if (row != GameProperties::FIELD_ROWS_NUMBER - 1 && col != GameProperties::FIELD_COLUMNS_NUMBER -isEven) {
|
|
|
+ game_table_[col][row]->setrightDown(game_table_[col +isEven][row + 1]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -55,26 +54,54 @@ void GameManager::generateTable() {
|
|
|
game_table_[0][0]->setXCoordinate(start_x_coordinate_);
|
|
|
game_table_[0][0]->setYCoordinate(start_y_coordinate_);
|
|
|
|
|
|
- for (int col = 0; col < col_table_size_; ++col) {
|
|
|
- for (int row = 0; row < row_table_size_; ++row) {
|
|
|
+ for (unsigned row = 0; row < GameProperties::FIELD_ROWS_NUMBER; ++row) {
|
|
|
+ for (unsigned col = 0; col < GameProperties::FIELD_COLUMNS_NUMBER; ++col) {
|
|
|
auto cell = game_table_[col][row];
|
|
|
|
|
|
- double center_x = cell->getXCoordinate();
|
|
|
- double center_y = cell->getYCoordinate();
|
|
|
+ auto verticles = cell->getPoints(GameProperties::CELL_MIN_RADIUS * 2, 30.0);
|
|
|
+
|
|
|
+ if (cell->getrightUp()) {
|
|
|
+ cell->getrightUp()->setXCoordinate(cell->getXCoordinate() + verticles[0].first );
|
|
|
+ cell->getrightUp()->setYCoordinate(cell->getYCoordinate() + verticles[0].second);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cell->getright()) {
|
|
|
+ cell->getright()->setXCoordinate(cell->getXCoordinate() + verticles[1].first );
|
|
|
+ cell->getright()->setYCoordinate(cell->getYCoordinate() + verticles[1].second);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cell->getrightDown()) {
|
|
|
+ cell->getrightDown()->setXCoordinate(cell->getXCoordinate() + verticles[2].first );
|
|
|
+ cell->getrightDown()->setYCoordinate(cell->getYCoordinate() + verticles[2].second);
|
|
|
+ }
|
|
|
|
|
|
- if (center_x == -1 && center_y == -1)
|
|
|
- continue;
|
|
|
+ if (cell->getleftDown()) {
|
|
|
+ cell->getleftDown()->setXCoordinate(cell->getXCoordinate() + verticles[3].first );
|
|
|
+ cell->getleftDown()->setYCoordinate(cell->getYCoordinate() + verticles[3].second);
|
|
|
+ }
|
|
|
|
|
|
- auto verticles = cell->getPoints(cell_radius_, 0.0);
|
|
|
+ if (cell->getleft()) {
|
|
|
+ cell->getleft()->setXCoordinate(cell->getXCoordinate() + verticles[4].first );
|
|
|
+ cell->getleft()->setYCoordinate(cell->getYCoordinate() + verticles[4].second);
|
|
|
+ }
|
|
|
|
|
|
- if (cell->getleft() && cell->getleft()->getXCoordinate() == -1 && cell->getleft()->getYCoordinate() == -1) {
|
|
|
- cell->getleft()->setXCoordinate(center_x + 2 * (verticles[0].first - center_x));
|
|
|
- cell->getleft()->setYCoordinate(center_y + 2 * (verticles[0].second - center_y));
|
|
|
+ if (cell->getleftUp()) {
|
|
|
+ cell->getleftUp()->setXCoordinate(cell->getXCoordinate() + verticles[5].first );
|
|
|
+ cell->getleftUp()->setYCoordinate(cell->getYCoordinate() + verticles[5].second);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ for (unsigned row = 0; row < GameProperties::FIELD_ROWS_NUMBER; ++row) {
|
|
|
+ for (unsigned col = 0; col < GameProperties::FIELD_COLUMNS_NUMBER; ++col) {
|
|
|
+ auto cell = game_table_[col][row];
|
|
|
+ std::cout << "(" << cell->getXCoordinate() << "," << cell->getYCoordinate() << ") ";
|
|
|
+ }
|
|
|
+ std::cout << std::endl;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
UnitsQueue* GameManager::getTurnQueue() {
|
|
|
return &turn_queue_;
|
|
|
}
|
|
@@ -91,6 +118,11 @@ int GameManager::getCurPlayerId() {
|
|
|
return cur_player_id_;
|
|
|
}
|
|
|
|
|
|
+std::vector<std::vector<Cell *> > GameManager::getGameField()
|
|
|
+{
|
|
|
+ return game_table_;
|
|
|
+}
|
|
|
+
|
|
|
Player* GameManager::getCurrentPlayer() {
|
|
|
return player_manager_->getPlayer(cur_player_id_);
|
|
|
}
|