gamemanager.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Someone tells, that Qt can to build this
  3. */
  4. #include "include/hotseatgame/gamemanager.h"
  5. #include "cell.h"
  6. #include <iostream>
  7. GameManager::GameManager(QObject *parent) : QObject(parent) {
  8. }
  9. void GameManager::buildGameTable(int colSize, int rowSize, double radius,
  10. double start_x_coordinate, double start_y_coordinate) {
  11. col_table_size_ = colSize;
  12. row_table_size_ = rowSize;
  13. cell_radius_ = radius;
  14. start_x_coordinate_ = start_x_coordinate;
  15. start_y_coordinate_ = start_y_coordinate;
  16. generateTable();
  17. }
  18. void GameManager::generateTable() {
  19. game_table_.assign(col_table_size_, std::vector< Cell* >(row_table_size_, nullptr));
  20. for (int col = 0; col < col_table_size_; ++col) {
  21. for (int row = 0; row < row_table_size_; ++row) {
  22. game_table_[col][row] = new Cell();
  23. }
  24. }
  25. int isEven = 1;
  26. for (int col = 0; col < col_table_size_; ++col) {
  27. isEven ^= 1;
  28. for (int row = 0; row < row_table_size_; ++row) {
  29. if (col != 0 && row != 0 -isEven) {
  30. game_table_[col][row]->setleftUp(game_table_[col - 1][row - 1 +isEven]);
  31. }
  32. if (row != 0) {
  33. game_table_[col][row]->setleft(game_table_[col][row - 1]);
  34. }
  35. if (col != col_table_size_ - 1 && row != 0 -isEven) {
  36. game_table_[col][row]->setleftDown(game_table_[col + 1][row - 1 +isEven]);
  37. }
  38. if (col != 0 && row != row_table_size_ -isEven) {
  39. game_table_[col][row]->setrightUp(game_table_[col - 1][row +isEven]);
  40. }
  41. if (row != row_table_size_ - 1) {
  42. game_table_[col][row]->setright(game_table_[col][row + 1]);
  43. }
  44. if (col != col_table_size_ - 1 && row != row_table_size_ -isEven) {
  45. game_table_[col][row]->setrightDown(game_table_[col + 1][row +isEven]);
  46. }
  47. }
  48. }
  49. game_table_[0][0]->setXCoordinate(start_x_coordinate_);
  50. game_table_[0][0]->setYCoordinate(start_y_coordinate_);
  51. for (int col = 0; col < col_table_size_; ++col) {
  52. for (int row = 0; row < row_table_size_; ++row) {
  53. auto cell = game_table_[col][row];
  54. double center_x = cell->getXCoordinate();
  55. double center_y = cell->getYCoordinate();
  56. if (center_x == -1 && center_y == -1)
  57. continue;
  58. auto verticles = cell->getPoints(cell_radius_, 0.0);
  59. if (cell->getleft() && cell->getleft()->getXCoordinate() == -1 && cell->getleft()->getYCoordinate() == -1) {
  60. cell->getleft()->setXCoordinate(center_x + 2 * (verticles[0].first - center_x));
  61. cell->getleft()->setYCoordinate(center_y + 2 * (verticles[0].second - center_y));
  62. }
  63. }
  64. }
  65. }
  66. UnitsQueue* GameManager::getTurnQueue() {
  67. return &turn_queue_;
  68. }
  69. void GameManager::AddToUnitQueue(Unit* unit) {
  70. turn_queue_.add(unit);
  71. }
  72. void GameManager::RmFromUnitQueue(Unit* unit) {
  73. turn_queue_.remove(unit);
  74. }
  75. int GameManager::getCurPlayerId() {
  76. return cur_player_id_;
  77. }
  78. Player* GameManager::getCurrentPlayer() {
  79. return player_manager_->getPlayer(cur_player_id_);
  80. }