gamemanager.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. }
  50. void GameManager::printAll() {
  51. game_table_[0][0]->RecalculateTableWithCenterThisPoint();
  52. for (int col = 0; col < col_table_size_; ++col) {
  53. for (int row = 0; row < row_table_size_; ++row) {
  54. game_table_[col][row]->print();
  55. }
  56. std::cout << std::endl;
  57. }
  58. }
  59. UnitsQueue* GameManager::getTurnQueue() {
  60. return &turn_queue_;
  61. }
  62. void GameManager::AddToUnitQueue(Unit* unit) {
  63. turn_queue_.add(unit);
  64. }
  65. void GameManager::RmFromUnitQueue(Unit* unit) {
  66. turn_queue_.remove(unit);
  67. }
  68. int GameManager::getCurPlayerId() {
  69. return cur_player_id_;
  70. }
  71. Player* GameManager::getCurrentPlayer() {
  72. return player_manager_->getPlayer(cur_player_id_);
  73. }