No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

151 líneas
5.4 KiB

hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
  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("GOLDEN PIG", 1000000, 1, 1),
  31. Character("Uraneus", 1),
  32. Character("Ekey", 2),
  33. Character("Wekius", 3),
  34. Character("Dhemaex", 4),
  35. Character("Uravras", 5),
  36. };
  37. UserInterface::welcomeMessage();
  38. UserInterface::epilogue();
  39. while (player.isAlive() && !UserInterface::isGameOver())
  40. {
  41. int choiceInt = -1;
  42. char choiceChar = -1;
  43. UserInterface::menu();
  44. choiceInt = UserInterface::getNumber(
  45. "What are you gonna do today?\n>",
  46. 0, 6);
  47. if (choiceInt == 0)
  48. {
  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. }
  54. else if (choiceInt == 1)
  55. {
  56. UserInterface::print("You spend the whole day sleeping...\n");
  57. UserInterface::print("HP and MP restored.\n");
  58. player.rest();
  59. }
  60. else if (choiceInt == 2)
  61. {
  62. UserInterface::print("You practice your magic in the yard...\n");
  63. UserInterface::print("You gained some experience.\n");
  64. printf("%ld\n", player.getLevel());
  65. fflush(stdout);
  66. player.increaseExperience((rand() % player.getLevel()) + 1);
  67. }
  68. else if (choiceInt == 3)
  69. {
  70. UserInterface::print("List of your classmates:\n");
  71. UserInterface::enemiesInfo(enemies);
  72. choiceInt = UserInterface::getNumber("Who would you prefer to train with?\n>", 0, enemies.size());
  73. UserInterface::print("You are going to spar with:\n");
  74. UserInterface::characterInfo(enemies.at(choiceInt));
  75. UserInterface::print("Are you sure? (y/N)\n>");
  76. std::cin >> choiceChar;
  77. if (choiceChar == 'y' || choiceChar == 'Y')
  78. {
  79. Character enemy = Character(enemies.at(choiceInt));
  80. Battle battle = Battle(player, enemy);
  81. battle.start();
  82. if (battle.getWinner() == 1)
  83. {
  84. UserInterface::print("You win, you get more experience...\n");
  85. player.increaseExperience(enemies.at(choiceInt).getLevel());
  86. }
  87. else
  88. {
  89. UserInterface::print("You lose, but you still get some experience...\n");
  90. player.revive();
  91. player.increaseExperience(enemies.at(choiceInt).getLevel() / 2);
  92. }
  93. }
  94. else
  95. {
  96. UserInterface::print("On second thought, you decide to sleep in your room instead...\n");
  97. player.rest();
  98. }
  99. }
  100. else if (choiceInt == 4)
  101. {
  102. UserInterface::print("You are going to challenge the Arch-Mage...\n");
  103. UserInterface::print("Are you sure? (y/N)\n>");
  104. std::cin >> choiceChar;
  105. if (choiceChar == 'y' || choiceChar == 'Y')
  106. {
  107. Battle battle = Battle(player, archMage);
  108. battle.start();
  109. if (battle.getWinner() == 1)
  110. {
  111. UserInterface::print("You win, you get more experience...\n");
  112. player.increaseExperience(enemies.at(choiceInt).getLevel());
  113. UserInterface::print("You win against the Arch-Mage!\n");
  114. UserInterface::print("He let you take a glimpse to the scroll that you always wanted...\n");
  115. UserInterface::print("Turns out the content is just some meaningless word...\n");
  116. UserInterface::print("Here is the content:\n");
  117. UserInterface::print(flag + "\n");
  118. }
  119. else
  120. {
  121. UserInterface::print("You lose...\n");
  122. UserInterface::print("Sadly his spell was to powerful,\n");
  123. UserInterface::print("You got killed by the arch-mage...\n");
  124. }
  125. }
  126. else
  127. {
  128. UserInterface::print("On second thought, you decide to sleep in your room instead...\n");
  129. player.rest();
  130. }
  131. }
  132. else if (choiceInt == 5)
  133. {
  134. UserInterface::print("You found some info about the arch-mage:\n");
  135. UserInterface::characterInfo(archMage);
  136. }
  137. else if (choiceInt == 6)
  138. {
  139. UserInterface::print("You meditate and got some insight to your ability:\n");
  140. UserInterface::characterInfo(player);
  141. }
  142. UserInterface::nextDay();
  143. }
  144. }