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.

147 lines
5.3 KiB

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