GameManager.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Someone tells, that Qt can to build this
  3. */
  4. #include "Cell.h"
  5. #include "GameManager.h"
  6. #include <iostream>
  7. GameManager::GameManager(int colSize, int rowSize):col_table_size_(colSize), row_table_size_(rowSize) {
  8. generate_table_();
  9. }
  10. void GameManager::generate_table_() {
  11. game_table_.assign(col_table_size_, std::vector< Cell* >(row_table_size_, nullptr));
  12. for (int col = 0; col < col_table_size_; ++col) {
  13. for (int row = 0; row < row_table_size_; ++row) {
  14. game_table_[col][row] = new Cell(nullptr);
  15. }
  16. }
  17. int isEven = 1;
  18. for (int col = 0; col < col_table_size_; ++col) {
  19. isEven ^= 1;
  20. for (int row = 0; row < row_table_size_; ++row) {
  21. if (col != 0 && row != 0 -isEven) {
  22. game_table_[col][row]->setleftUp(game_table_[col - 1][row - 1 +isEven]);
  23. }
  24. if (row != 0) {
  25. game_table_[col][row]->setleft(game_table_[col][row - 1]);
  26. }
  27. if (col != col_table_size_ - 1 && row != 0 -isEven) {
  28. game_table_[col][row]->setleftDown(game_table_[col + 1][row - 1 +isEven]);
  29. }
  30. if (col != 0 && row != row_table_size_ -isEven) {
  31. game_table_[col][row]->setrightUp(game_table_[col - 1][row +isEven]);
  32. }
  33. if (row != row_table_size_ - 1) {
  34. game_table_[col][row]->setright(game_table_[col][row + 1]);
  35. }
  36. if (col != col_table_size_ - 1 && row != row_table_size_ -isEven) {
  37. game_table_[col][row]->setrightDown(game_table_[col + 1][row +isEven]);
  38. }
  39. }
  40. }
  41. }
  42. void GameManager::print_all() {
  43. game_table_[0][0]->RecalculateTableWithCenterThisPoint();
  44. for (int col = 0; col < col_table_size_; ++col) {
  45. for (int row = 0; row < row_table_size_; ++row) {
  46. game_table_[col][row]->print();
  47. }
  48. std::cout << std::endl;
  49. }
  50. }