Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

210 lignes
5.9 KiB

il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
il y a 4 ans
  1. #include "UserInterface.hpp"
  2. #include "Game.hpp"
  3. const int UserInterface::maxDay = 28;
  4. const int UserInterface::maxMonth = 12;
  5. const int UserInterface::maxYear = 100;
  6. int UserInterface::day = 1;
  7. int UserInterface::month = 1;
  8. int UserInterface::year = 90;
  9. std::vector<std::string> UserInterface::dayName = {
  10. "Morndas",
  11. "Tirdas",
  12. "Middas",
  13. "Turdas",
  14. "Fredas",
  15. "Loredas",
  16. "Sundas",
  17. };
  18. std::vector<std::string> UserInterface::monthName = {
  19. "Morning Star",
  20. "Sun's Dawn",
  21. "First Seed",
  22. "Rain's Hand",
  23. "Second Seed",
  24. "Mid Year",
  25. "Sun's Height",
  26. "Last Seed",
  27. "Hearthfire",
  28. "Frostfall",
  29. "Sun's Dusk",
  30. "Evening Star",
  31. };
  32. void UserInterface::print(std::string msg, int interval)
  33. {
  34. std::cout << msg << std::flush;
  35. std::this_thread::sleep_for(std::chrono::milliseconds(interval));
  36. }
  37. void UserInterface::println(std::string msg, int interval)
  38. {
  39. std::cout << msg << std::endl;
  40. std::this_thread::sleep_for(std::chrono::milliseconds(interval));
  41. }
  42. void UserInterface::printByChar(std::string msg, int interval)
  43. {
  44. for (size_t i = 0; i < msg.size(); i++)
  45. {
  46. std::cout << msg.at(i) << std::flush;
  47. std::this_thread::sleep_for(std::chrono::milliseconds(interval));
  48. }
  49. }
  50. void UserInterface::welcomeMessage()
  51. {
  52. std::cout << "+++++++++++++++++++++++++++++++++++\n"
  53. << "+ Welcome to Spell-Warz-Again !!! +\n"
  54. << "+++++++++++++++++++++++++++++++++++\n"
  55. << std::flush;
  56. }
  57. Character *UserInterface::characterCreation()
  58. {
  59. std::string buffer;
  60. std::cout << "Who should we call you?\n"
  61. << ">" << std::flush;
  62. std::cin >> buffer;
  63. std::cout << "Now pick your elements: \n";
  64. std::map<std::string, Element>::iterator it;
  65. int i = 0;
  66. int max = Game::Elements.size() - 2;
  67. for (it = Game::Elements.begin(); i < max; ++it)
  68. {
  69. std::cout << "[" << i++ << "] " << it->second.getName() << '\n';
  70. }
  71. int element = UserInterface::getNumber("#", 0, max);
  72. return new Character(buffer, Game::Elements.begin() + element);
  73. }
  74. void UserInterface::epilogue()
  75. {
  76. UserInterface::printByChar(
  77. "You are just a young mage in a mage school,\n"
  78. "When you witnessed your arch-mage got defeated by your senior...\n"
  79. "He was mumbling about some flag inside a scroll,\n"
  80. "he also mentioned something about a competition called CTF...\n"
  81. "You thought to yourself: \"What the f*ck is a CTF?\"\n"
  82. "Nevertheless, you want that scroll, you want that flag!\n"
  83. "Defeat the new arch-mage that was once your senior to get a glimpse of that scroll!\n"
  84. "Note: You need to do this in 10 year of in-game, otherwise you would graduate first...\n");
  85. }
  86. std::string UserInterface::dateString()
  87. {
  88. char date[5] = {0};
  89. if (UserInterface::day < 21)
  90. {
  91. switch (UserInterface::day)
  92. {
  93. case 1:
  94. sprintf(date, "1st");
  95. break;
  96. case 2:
  97. sprintf(date, "2nd");
  98. break;
  99. case 3:
  100. sprintf(date, "3rd");
  101. break;
  102. default:
  103. sprintf(date, "%dth", UserInterface::day);
  104. break;
  105. }
  106. }
  107. else
  108. {
  109. switch (UserInterface::day % 10)
  110. {
  111. case 1:
  112. sprintf(date, "%dst", UserInterface::day);
  113. break;
  114. case 2:
  115. sprintf(date, "%dnd", UserInterface::day);
  116. break;
  117. case 3:
  118. sprintf(date, "%drd", UserInterface::day);
  119. break;
  120. default:
  121. sprintf(date, "%dth", UserInterface::day);
  122. break;
  123. }
  124. }
  125. return std::string(
  126. UserInterface::dayName.at(((UserInterface::day - 1) % 7)) + ", " +
  127. date + " of " + UserInterface::monthName.at(UserInterface::month - 1) +
  128. ", Year " + std::to_string(UserInterface::year));
  129. }
  130. void UserInterface::menu()
  131. {
  132. std::cout << "=======================================\n"
  133. << UserInterface::dateString() << "\n"
  134. << "=======================================\n"
  135. << "Available action:\n"
  136. << "[1] Take a rest\n"
  137. << "[2] Practice magic\n"
  138. << "[3] Spar against classmate\n"
  139. << "[4] Challenge the new Arch-Mage\n"
  140. << "[5] Gather info about the new Arch-Mage\n"
  141. << "[6] Meditate to your inner-self\n"
  142. << "[0] Commit sudoku\n"
  143. << std::flush;
  144. }
  145. void UserInterface::enemiesInfo(std::vector<Character *> &enemies)
  146. {
  147. for (int i = 0; i < enemies.size(); i++)
  148. {
  149. std::cout << "[" << i << "] " << enemies.at(i)->getName() << " (Lv." << enemies.at(i)->getLevel() << ")\n";
  150. }
  151. std::cout << std::flush;
  152. }
  153. int UserInterface::getNumber(std::string msg, int min, int max)
  154. {
  155. int buffer = max + 1;
  156. do
  157. {
  158. std::cout << msg << std::flush;
  159. if (std::cin.failbit || std::cin.eofbit)
  160. {
  161. std::cin.clear();
  162. std::cin.ignore(1);
  163. }
  164. } while (std::cin >> buffer && !(buffer <= max && buffer >= min));
  165. return buffer;
  166. }
  167. void UserInterface::nextDay()
  168. {
  169. if (UserInterface::day++ >= UserInterface::maxDay)
  170. {
  171. day = 1;
  172. if (UserInterface::month++ >= UserInterface::maxMonth)
  173. {
  174. month = 1;
  175. if (UserInterface::year++ >= UserInterface::maxYear)
  176. {
  177. exit(0);
  178. }
  179. }
  180. }
  181. }
  182. void UserInterface::characterInfo(Character *c)
  183. {
  184. std::cout << "++++++++++++++++++++++++"
  185. << "\nName: " << c->getName()
  186. << "\n HP: " << c->getCurHP() << "/" << c->getMaxHP()
  187. << "\n MP: " << c->getCurMP() << "/" << c->getMaxMP()
  188. << "\n Lv: " << c->getLevel()
  189. << "\n Xp: " << c->getExperience()
  190. << "\n next: " << c->toNextLevel()
  191. << "\n++++++++++++++++++++++++" << std::endl;
  192. }