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.

134 lines
4.9 KiB

  1. #include <fstream>
  2. #include <map>
  3. #include <unistd.h>
  4. #include "lib/Character.hpp"
  5. #include "lib/Spell.hpp"
  6. #include "lib/Element.hpp"
  7. #include "lib/UserInterface.hpp"
  8. #include "lib/BattleInterface.hpp"
  9. #include "lib/Game.hpp"
  10. std::string loadFlag()
  11. {
  12. std::string flagString;
  13. std::ifstream flagFile("flag.txt");
  14. flagFile >> flagString;
  15. flagFile.close();
  16. return flagString;
  17. }
  18. int main()
  19. {
  20. alarm(600);
  21. srand(time(0));
  22. std::string flag = loadFlag();
  23. Game::init();
  24. UserInterface::welcomeMessage();
  25. UserInterface::epilogue();
  26. Game::PlayerParty.push_back(UserInterface::characterCreation());
  27. while (player->isAlive() && !UserInterface::isGameOver())
  28. {
  29. int choiceInt = -1;
  30. char choiceChar = -1;
  31. UserInterface::menu();
  32. choiceInt = UserInterface::getNumber(
  33. "What are you gonna do today?\n>",
  34. 0, 6);
  35. switch (choiceInt)
  36. {
  37. case 0:
  38. UserInterface::print("You commit sudoku...\n");
  39. UserInterface::print("Was it supposed to be seppuku?\n");
  40. UserInterface::print("Nevermind, you killed yourself.\n");
  41. player->kill();
  42. break;
  43. case 1:
  44. UserInterface::print("You spend the whole day sleeping...\n");
  45. UserInterface::print("HP and MP restored.\n");
  46. player->rest();
  47. break;
  48. case 2:
  49. UserInterface::print("You practice your magic in the yard...\n");
  50. UserInterface::print("You gained some experience.\n");
  51. player->increaseExperience((random() % player->getLevel()) + 1);
  52. break;
  53. case 3:
  54. UserInterface::print("List of your classmates:\n");
  55. UserInterface::enemiesInfo(enemies);
  56. choiceInt = UserInterface::getNumber("Who would you prefer to train with?\n>", 0, enemies.size());
  57. UserInterface::print("You are going to spar with:\n");
  58. UserInterface::characterInfo(enemies.at(choiceInt));
  59. UserInterface::print("Are you sure? (y/N)\n>");
  60. std::cin >> choiceChar;
  61. if (choiceChar == 'y' || choiceChar == 'Y')
  62. {
  63. enemy = new Character(*enemies.at(choiceInt));
  64. battle = BattleInterface(player, enemy);
  65. battle.start();
  66. if (battle.getWinner() == player)
  67. {
  68. UserInterface::print("You win, you get more experience...\n");
  69. player->increaseExperience(enemies.at(choiceInt)->getLevel());
  70. }
  71. else
  72. {
  73. UserInterface::print("You lose, but you still get some experience...\n");
  74. player->revive();
  75. player->increaseExperience(enemies.at(choiceInt)->getLevel() / 2);
  76. }
  77. delete enemy;
  78. }
  79. else
  80. {
  81. UserInterface::print("On second thought, you decide to sleep in your room instead...\n");
  82. player->rest();
  83. }
  84. break;
  85. case 4:
  86. UserInterface::print("You are going to challenge the Arch-Mage...\n");
  87. UserInterface::print("Are you sure? (y/N)\n>");
  88. std::cin >> choiceChar;
  89. if (choiceChar == 'y' || choiceChar == 'Y')
  90. {
  91. battle = BattleInterface(player, archMage);
  92. battle.start();
  93. if (battle.getWinner() == player)
  94. {
  95. UserInterface::print("You win, you get more experience...\n");
  96. player->increaseExperience(enemies.at(choiceInt)->getLevel());
  97. UserInterface::print("You win against the Arch-Mage!\n");
  98. UserInterface::print("He let you take a glimpse to the scroll that you always wanted...\n");
  99. UserInterface::print("Turns out the content is just some meaningless word...\n");
  100. UserInterface::print("Here is the content:\n");
  101. UserInterface::print(flag + "\n");
  102. }
  103. else
  104. {
  105. UserInterface::print("You lose...\n");
  106. UserInterface::print("Sadly his spell was to powerful,\n");
  107. UserInterface::print("You got killed by the arch-mage...\n");
  108. }
  109. }
  110. else
  111. {
  112. UserInterface::print("On second thought, you decide to sleep in your room instead...\n");
  113. player->rest();
  114. }
  115. break;
  116. case 5:
  117. UserInterface::print("You found some info about the arch-mage:\n");
  118. UserInterface::characterInfo(archMage);
  119. break;
  120. case 6:
  121. UserInterface::print("You meditate and got some insight to your ability:\n");
  122. UserInterface::characterInfo(player);
  123. break;
  124. }
  125. UserInterface::nextDay();
  126. }
  127. }