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.
 
 

99 lines
2.2 KiB

  1. #include "inputoutput.h"
  2. #include "maingame.h"
  3. #include "mainmenu.h"
  4. #include "player.h"
  5. #include "window.h"
  6. void MainMenu::initialize() {
  7. int rows;
  8. int cols;
  9. Window::getMaXYZ(stdscr, rows, cols);
  10. this->window = new Window(rows, cols, 0, 0);
  11. this->titleScreen = true;
  12. this->player = new Player*[PLAYER_SIZE] { nullptr };
  13. }
  14. void MainMenu::update() {
  15. if (this->titleScreen) {
  16. IO::update();
  17. if (IO::getKeyName() == " ") {
  18. this->titleScreen = false;
  19. }
  20. }
  21. else {
  22. int y;
  23. int x;
  24. std::string tmpStr;
  25. unsigned char colors[PLAYER_SIZE] = { PAIR_RED_BLACK, PAIR_BLUE_BLACK };
  26. for (int i = 0; i < PLAYER_SIZE; i++) {
  27. if (this->player[i] == nullptr) {
  28. this->window->getYX(y, x);
  29. tmpStr = "";
  30. while (tmpStr == "") {
  31. tmpStr = IO::trim(this->window->getStr());
  32. this->window->setYX(y, x);
  33. }
  34. this->player[i] = new Player();
  35. this->player[i]->setName(tmpStr);
  36. this->player[i]->setColor(colors[i]);
  37. break;
  38. }
  39. if (i == PLAYER_SIZE - 1) {
  40. gameStateManager.setState(new MainGame(this->player));
  41. }
  42. }
  43. }
  44. }
  45. void MainMenu::render() {
  46. this->window->clear();
  47. this->window->update();
  48. this->window->setWindow(this->window->getMaxRows(), this->window->getMaxCols(), 0, 0);
  49. this->window->resize();
  50. if (this->titleScreen) {
  51. this->window->printSide("", "Rick van Vonderen");
  52. this->window->setYX(1, 0);
  53. this->window->printSide("", "0945444");
  54. this->window->setYX(2, 0);
  55. this->window->printSide("", "TI2B");
  56. this->window->setYX(this->window->getRows() / 2 - 1, 0);
  57. this->window->printCenter("--- Space Walk ---");
  58. this->window->setYX(this->window->getRows() - 4, 0);
  59. this->window->printCenter("Press <Space> to walk..");
  60. }
  61. else {
  62. int x = this->window->getCols() / 2 - 11 ;
  63. int y = this->window->getRows() / 2;
  64. std::string tmp;
  65. for (int i = 0; i < PLAYER_SIZE; i++) {
  66. tmp = std::string("Enter Player ") + std::to_string(i + 1) + std::string(" name: ");
  67. if (this->player[i] != nullptr) {
  68. tmp += this->player[i]->getName();
  69. }
  70. this->window->print(tmp, y, x);
  71. y++;
  72. if (this->player[i] == nullptr) {
  73. break;
  74. }
  75. }
  76. }
  77. this->window->render();
  78. }
  79. void MainMenu::destroy() {
  80. delete this->window;
  81. }