Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

227 rindas
5.9 KiB

pirms 5 gadiem
pirms 5 gadiem
pirms 5 gadiem
  1. #include "UserInterface.hpp"
  2. const int UserInterface::INTERVAL = 0;
  3. const int UserInterface::MINI_INTERVAL = 0;
  4. const int UserInterface::MAX_DAY = 28;
  5. const int UserInterface::MAX_MONTH = 12;
  6. const int UserInterface::MAX_YEAR = 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(const char *msg)
  40. {
  41. std::cout << msg << std::flush;
  42. std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::INTERVAL));
  43. }
  44. void UserInterface::println(std::string msg)
  45. {
  46. std::cout << msg << std::endl;
  47. std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::INTERVAL));
  48. }
  49. void UserInterface::println(const char *msg)
  50. {
  51. std::cout << msg << std::endl;
  52. std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::INTERVAL));
  53. }
  54. void UserInterface::printByChar(const char *msg)
  55. {
  56. int len = strlen(msg);
  57. for (size_t i = 0; i < len; i++)
  58. {
  59. std::cout << msg[i] << std::flush;
  60. std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::MINI_INTERVAL));
  61. }
  62. }
  63. void UserInterface::welcomeMessage()
  64. {
  65. std::cout << "+++++++++++++++++++++++++++++++++++++++++\n"
  66. << "+ Welcome to Spell-Warz-Again-Final !!! +\n"
  67. << "+++++++++++++++++++++++++++++++++++++++++\n"
  68. << std::flush;
  69. }
  70. const char *UserInterface::chooseName(char *buffer)
  71. {
  72. char choice = 0;
  73. while (choice != 'y' && choice != 'Y')
  74. {
  75. printf("Who should we call you?\n>");
  76. fflush(stdout);
  77. scanf("%63s", buffer);
  78. printf("So you are a young mage named \"%s\" correct? (y/N)\n>", buffer);
  79. fflush(stdout);
  80. scanf("%1s", &choice);
  81. }
  82. return buffer;
  83. }
  84. void UserInterface::epilogue()
  85. {
  86. UserInterface::printByChar(
  87. "I'm tired of making epilogue...\n"
  88. "You are a young mage, defeat the damn arch-mage...\n"
  89. "F*ck, I'm tired of this...\n"
  90. "Do you know I just finished this sh*t at October 10th?\n"
  91. "Good luck and defeat the arch-mage.\n"
  92. "Trust me, you gonna need the \'Good Luck\' ...\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 = 1; 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::MAX_DAY)
  178. {
  179. day = 1;
  180. if (UserInterface::month++ >= UserInterface::MAX_MONTH)
  181. {
  182. month = 1;
  183. if (UserInterface::year++ >= UserInterface::MAX_YEAR)
  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. }