GameManager.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. }
  10. void GameManager::buildGameTable(int colSize, int rowSize){
  11. col_table_size_ = colSize;
  12. row_table_size_ = rowSize;
  13. generateTable();
  14. }
  15. void GameManager::generateTable() {
  16. game_table_.assign(col_table_size_, std::vector< Cell* >(row_table_size_, nullptr));
  17. for (int col = 0; col < col_table_size_; ++col) {
  18. for (int row = 0; row < row_table_size_; ++row) {
  19. game_table_[col][row] = new Cell(nullptr);
  20. }
  21. }
  22. int isEven = 1;
  23. for (int col = 0; col < col_table_size_; ++col) {
  24. isEven ^= 1;
  25. for (int row = 0; row < row_table_size_; ++row) {
  26. if (col != 0 && row != 0 -isEven) {
  27. game_table_[col][row]->setleftUp(game_table_[col - 1][row - 1 +isEven]);
  28. }
  29. if (row != 0) {
  30. game_table_[col][row]->setleft(game_table_[col][row - 1]);
  31. }
  32. if (col != col_table_size_ - 1 && row != 0 -isEven) {
  33. game_table_[col][row]->setleftDown(game_table_[col + 1][row - 1 +isEven]);
  34. }
  35. if (col != 0 && row != row_table_size_ -isEven) {
  36. game_table_[col][row]->setrightUp(game_table_[col - 1][row +isEven]);
  37. }
  38. if (row != row_table_size_ - 1) {
  39. game_table_[col][row]->setright(game_table_[col][row + 1]);
  40. }
  41. if (col != col_table_size_ - 1 && row != row_table_size_ -isEven) {
  42. game_table_[col][row]->setrightDown(game_table_[col + 1][row +isEven]);
  43. }
  44. }
  45. }
  46. }
  47. void GameManager::printAll() {
  48. game_table_[0][0]->RecalculateTableWithCenterThisPoint();
  49. for (int col = 0; col < col_table_size_; ++col) {
  50. for (int row = 0; row < row_table_size_; ++row) {
  51. game_table_[col][row]->print();
  52. }
  53. std::cout << std::endl;
  54. }
  55. }
  56. UnitsQueue* GameManager::getTurnQueue(){
  57. return &turn_queue_;
  58. }
  59. void GameManager::AddToUnitQueue(Unit* unit){
  60. turn_queue_.add(unit);
  61. }
  62. void GameManager::RmFromUnitQueue(Unit* unit){
  63. turn_queue_.remove(unit);
  64. }
  65. int GameManager::getCurPlayerId(){
  66. return cur_player_id_;
  67. };
  68. Player* GameManager::getCurrentPlayer(){
  69. return player_manager_->getPlayer(cur_player_id_);
  70. }