/* * Someone tells, that Qt can to build this */ #include "include/hotseatgame/gamemanager.h" #include "cell.h" #include 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; 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(); } } int isEven = 1; for (int col = 0; col < col_table_size_; ++col) { 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]); } if (row != 0) { game_table_[col][row]->setleft(game_table_[col][row - 1]); } if (col != col_table_size_ - 1 && row != 0 -isEven) { game_table_[col][row]->setleftDown(game_table_[col + 1][row - 1 +isEven]); } if (col != 0 && row != row_table_size_ -isEven) { game_table_[col][row]->setrightUp(game_table_[col - 1][row +isEven]); } if (row != row_table_size_ - 1) { game_table_[col][row]->setright(game_table_[col][row + 1]); } if (col != col_table_size_ - 1 && row != row_table_size_ -isEven) { game_table_[col][row]->setrightDown(game_table_[col + 1][row +isEven]); } } } 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) { auto cell = game_table_[col][row]; double center_x = cell->getXCoordinate(); double center_y = cell->getYCoordinate(); if (center_x == -1 && center_y == -1) continue; auto verticles = cell->getPoints(cell_radius_, 0.0); 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)); } } } } UnitsQueue* GameManager::getTurnQueue() { return &turn_queue_; } void GameManager::AddToUnitQueue(Unit* unit) { turn_queue_.add(unit); } void GameManager::RmFromUnitQueue(Unit* unit) { turn_queue_.remove(unit); } int GameManager::getCurPlayerId() { return cur_player_id_; } Player* GameManager::getCurrentPlayer() { return player_manager_->getPlayer(cur_player_id_); }