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.

225 lines
6.1 KiB

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