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.

222 lines
6.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #include "UserInterface.hpp"
  2. const int UserInterface::interval = 0; // in ms
  3. const int UserInterface::miniInterval = 0; // in ms
  4. const int UserInterface::maxDay = 28;
  5. const int UserInterface::maxMonth = 4;
  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. while (choice != 'y' && choice != 'Y')
  70. {
  71. std::cout << "Who should we call you?\n"
  72. << ">" << std::flush;
  73. std::cin >> buffer;
  74. std::cout << "So you are a young mage named \"" << buffer << "\" correct? (y/N)\n"
  75. << ">";
  76. std::cin >> choice;
  77. }
  78. return new Character(
  79. buffer, 1, 0, 10, 10, 5, 5);
  80. }
  81. void UserInterface::epilogue()
  82. {
  83. UserInterface::printByChar(
  84. "You are just a young mage in a mage school,\n"
  85. "When you witnessed your arch-mage got defeated by your senior...\n"
  86. "He was mumbling about some flag inside a scroll,\n"
  87. "he also mentioned something about a competition called CTF...\n"
  88. "You thought to yourself: \"What the f*ck is a CTF?\"\n"
  89. "Nevertheless, you want that scroll, you want that flag!\n"
  90. "Defeat the new arch-mage that was once your senior to get a glimpse of that scroll!\n"
  91. "Note: You need to do this in 10 year of in-game, otherwise you would graduate first...\n");
  92. }
  93. std::string UserInterface::dateString()
  94. {
  95. char date[5] = {0};
  96. if (UserInterface::day < 21)
  97. {
  98. switch (UserInterface::day)
  99. {
  100. case 1:
  101. sprintf(date, "1st");
  102. break;
  103. case 2:
  104. sprintf(date, "2nd");
  105. break;
  106. case 3:
  107. sprintf(date, "3rd");
  108. break;
  109. default:
  110. sprintf(date, "%dth", UserInterface::day);
  111. break;
  112. }
  113. }
  114. else
  115. {
  116. switch (UserInterface::day % 10)
  117. {
  118. case 1:
  119. sprintf(date, "%dst", UserInterface::day);
  120. break;
  121. case 2:
  122. sprintf(date, "%dnd", UserInterface::day);
  123. break;
  124. case 3:
  125. sprintf(date, "%drd", UserInterface::day);
  126. break;
  127. default:
  128. sprintf(date, "%dth", UserInterface::day);
  129. break;
  130. }
  131. }
  132. return std::string(
  133. UserInterface::dayName.at(((UserInterface::day - 1) % 7)) + ", " +
  134. date + " of " + UserInterface::monthName.at(UserInterface::month - 1) +
  135. ", Year " + std::to_string(UserInterface::year));
  136. }
  137. void UserInterface::menu()
  138. {
  139. std::cout << "=======================================\n"
  140. << UserInterface::dateString() << "\n"
  141. << "=======================================\n"
  142. << "Available action:\n"
  143. << "[1] Take a rest\n"
  144. << "[2] Practice magic\n"
  145. << "[3] Spar against classmate\n"
  146. << "[4] Challenge the new Arch-Mage\n"
  147. << "[5] Gather info about the new Arch-Mage\n"
  148. << "[6] Meditate to your inner-self\n"
  149. << "[0] Commit sudoku\n"
  150. << std::flush;
  151. }
  152. void UserInterface::enemiesInfo(std::vector<Character *> &enemies)
  153. {
  154. for (int i = 0; i < enemies.size(); i++)
  155. {
  156. std::cout << "[" << i << "] " << enemies.at(i)->getName() << " (Lv." << enemies.at(i)->getLevel() << ")\n";
  157. }
  158. std::cout << std::flush;
  159. }
  160. int UserInterface::getNumber(std::string msg, int min, int max)
  161. {
  162. int buffer = max + 1;
  163. do
  164. {
  165. std::cout << msg << std::flush;
  166. if (std::cin.failbit || std::cin.eofbit)
  167. {
  168. std::cin.clear();
  169. std::cin.ignore(1);
  170. }
  171. } while (std::cin >> buffer && !(buffer <= max && buffer >= min));
  172. return buffer;
  173. }
  174. void UserInterface::nextDay()
  175. {
  176. if (UserInterface::day++ >= UserInterface::maxDay)
  177. {
  178. if (UserInterface::month++ >= UserInterface::maxMonth)
  179. {
  180. if (UserInterface::year++ >= UserInterface::maxYear)
  181. {
  182. UserInterface::gameOver = true;
  183. }
  184. month = 1;
  185. }
  186. day = 1;
  187. }
  188. }
  189. bool UserInterface::isGameOver()
  190. {
  191. return gameOver;
  192. }
  193. void UserInterface::characterInfo(Character *c)
  194. {
  195. std::cout << "++++++++++++++++++++++++"
  196. << "\nName: " << c->getName()
  197. << "\n HP: " << c->getCurHP() << "/" << c->getMaxHP()
  198. << "\n MP: " << c->getCurMP() << "/" << c->getMaxMP()
  199. << "\n Lv: " << c->getLevel()
  200. << "\n Xp: " << c->getExperience()
  201. << "\n next: " << c->toNextLevel()
  202. << "\n++++++++++++++++++++++++" << std::endl;
  203. }