gamemanager.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. UnitsQueue* GameManager::getTurnQueue(){
  48. return &turn_queue_;
  49. }
  50. void GameManager::AddToUnitQueue(Unit* unit){
  51. turn_queue_.add(unit);
  52. }
  53. void GameManager::RmFromUnitQueue(Unit* unit){
  54. turn_queue_.remove(unit);
  55. }
  56. int GameManager::getCurPlayerId(){
  57. return cur_player_id_;
  58. };
  59. Player* GameManager::getCurrentPlayer(){
  60. return player_manager_->getPlayer(cur_player_id_);
  61. }