Space Walk board game
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

85 lines
1.9 KiB

  1. #include "board.h"
  2. #include "boardwindow.h"
  3. #include "maingame.h"
  4. #include "spaceship.h"
  5. BoardWindow::BoardWindow(int height, int width, Board *board) :
  6. height(height),
  7. width(width),
  8. board(board) {
  9. }
  10. BoardWindow::~BoardWindow() {
  11. }
  12. void BoardWindow::update() {
  13. Window::update();
  14. this->resize();
  15. int twoThirds = (this->getRows() / 3) * 2;
  16. int halfCols = this->getCols() / 2;
  17. int y = (twoThirds / 2) - 12;
  18. int x = halfCols - 4 - 1;
  19. // Print black hole
  20. this->printBlackHole(y, x, 0);
  21. y += 6;
  22. x = (this->getCols() / 2) - (46 / 2) - 1;
  23. // Print all planets
  24. for (int i = 1; i < BOARD_SIZE - 1; i++) {
  25. this->printPlanet(y, x, i);
  26. x += 8;
  27. if (i == (BOARD_SIZE - 2) / 2) {
  28. x = (this->getCols() / 2) - (46 / 2) - 1;
  29. y += 6;
  30. }
  31. }
  32. y += 6;
  33. x = halfCols - 4 - 1;
  34. // Print black hole
  35. this->printBlackHole(y, x, BOARD_SIZE - 1);
  36. }
  37. void BoardWindow::resize() {
  38. int rows = this->getMaxRows() - this->height;
  39. int cols = this->getMaxCols() - this->width;
  40. this->setWindow(rows, cols, 0, 0);
  41. Window::resize();
  42. }
  43. void BoardWindow::printBlackHole(int y, int x, int planet) {
  44. this->print("+------+", y, x);
  45. this->print("| |", y + 1, x);
  46. this->print("| |", y + 2, x);
  47. this->print("| |", y + 3, x);
  48. this->print("+------+", y + 4, x);
  49. this->printSpaceShip(y + 1, x + 1, planet, 6);
  50. }
  51. void BoardWindow::printPlanet(int y, int x, int planet) {
  52. this->print("+----+", y, x);
  53. this->print("| |", y + 1, x);
  54. this->print("| |", y + 2, x);
  55. this->print("| |", y + 3, x);
  56. this->print("+----+", y + 4, x);
  57. this->printSpaceShip(y + 1, x + 1, planet, 4);
  58. }
  59. void BoardWindow::printSpaceShip(int y, int x, int planet, int width) {
  60. auto tmp = this->board->getShips(planet);
  61. int size = (int)tmp->size() + 1;
  62. for (int i = 1; i < size; i++) {
  63. tmp->at(i - 1)->render(this, y, x, false);
  64. x++;
  65. if (i != 1 && i % width == 0) {
  66. y++;
  67. x -= width;
  68. }
  69. }
  70. }