#include "UserInterface.hpp" const int UserInterface::interval = 0; // in ms const int UserInterface::miniInterval = 0; // in ms const int UserInterface::maxDay = 28; const int UserInterface::maxMonth = 4; const int UserInterface::maxYear = 100; int UserInterface::day = 1; int UserInterface::month = 1; int UserInterface::year = 90; bool UserInterface::gameOver = false; std::vector UserInterface::dayName = { "Morndas", "Tirdas", "Middas", "Turdas", "Fredas", "Loredas", "Sundas", }; std::vector UserInterface::monthName = { "Morning Star", "Sun's Dawn", "First Seed", "Rain's Hand", "Second Seed", "Mid Year", "Sun's Height", "Last Seed", "Hearthfire", "Frostfall", "Sun's Dusk", "Evening Star", }; void UserInterface::print(std::string msg) { std::cout << msg << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval)); } void UserInterface::print(char *msg) { std::cout << msg << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval)); } void UserInterface::print(const char *msg) { std::cout << msg << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::interval)); } void UserInterface::printByChar(const char *msg) { int len = strlen(msg); for (size_t i = 0; i < len; i++) { std::cout << msg[i] << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(UserInterface::miniInterval)); } } void UserInterface::welcomeMessage() { std::cout << "+++++++++++++++++++++++++++++++++++\n" << "+ Welcome to Spell-Warz-Again !!! +\n" << "+++++++++++++++++++++++++++++++++++\n" << std::flush; } Character *UserInterface::characterCreation() { char buffer[128] = {0}; char choice = 0; while (choice != 'y' && choice != 'Y') { std::cout << "Who should we call you?\n" << ">" << std::flush; std::cin >> buffer; std::cout << "So you are a young mage named \"" << buffer << "\" correct? (y/N)\n" << ">"; std::cin >> choice; } return new Character( buffer, 1, 0, 10, 10, 5, 5); } void UserInterface::epilogue() { UserInterface::printByChar( "You are just a young mage in a mage school,\n" "When you witnessed your arch-mage got defeated by your senior...\n" "He was mumbling about some flag inside a scroll,\n" "he also mentioned something about a competition called CTF...\n" "You thought to yourself: \"What the f*ck is a CTF?\"\n" "Nevertheless, you want that scroll, you want that flag!\n" "Defeat the new arch-mage that was once your senior to get a glimpse of that scroll!\n" "Note: You need to do this in 10 year of in-game, otherwise you would graduate first...\n"); } std::string UserInterface::dateString() { char date[5] = {0}; if (UserInterface::day < 21) { switch (UserInterface::day) { case 1: sprintf(date, "1st"); break; case 2: sprintf(date, "2nd"); break; case 3: sprintf(date, "3rd"); break; default: sprintf(date, "%dth", UserInterface::day); break; } } else { switch (UserInterface::day % 10) { case 1: sprintf(date, "%dst", UserInterface::day); break; case 2: sprintf(date, "%dnd", UserInterface::day); break; case 3: sprintf(date, "%drd", UserInterface::day); break; default: sprintf(date, "%dth", UserInterface::day); break; } } return std::string( UserInterface::dayName.at(((UserInterface::day - 1) % 7)) + ", " + date + " of " + UserInterface::monthName.at(UserInterface::month - 1) + ", Year " + std::to_string(UserInterface::year)); } void UserInterface::menu() { std::cout << "=======================================\n" << UserInterface::dateString() << "\n" << "=======================================\n" << "Available action:\n" << "[1] Take a rest\n" << "[2] Practice magic\n" << "[3] Spar against classmate\n" << "[4] Challenge the new Arch-Mage\n" << "[5] Gather info about the new Arch-Mage\n" << "[6] Meditate to your inner-self\n" << "[0] Commit sudoku\n" << std::flush; } void UserInterface::enemiesInfo(std::vector &enemies) { for (int i = 0; i < enemies.size(); i++) { std::cout << "[" << i << "] " << enemies.at(i)->getName() << " (Lv." << enemies.at(i)->getLevel() << ")\n"; } std::cout << std::flush; } int UserInterface::getNumber(std::string msg, int min, int max) { int buffer = max + 1; do { std::cout << msg << std::flush; if (std::cin.failbit || std::cin.eofbit) { std::cin.clear(); std::cin.ignore(1); } } while (std::cin >> buffer && !(buffer <= max && buffer >= min)); return buffer; } void UserInterface::nextDay() { if (UserInterface::day++ >= UserInterface::maxDay) { if (UserInterface::month++ >= UserInterface::maxMonth) { if (UserInterface::year++ >= UserInterface::maxYear) { UserInterface::gameOver = true; } month = 1; } day = 1; } } bool UserInterface::isGameOver() { return gameOver; } void UserInterface::characterInfo(Character *c) { std::cout << "++++++++++++++++++++++++" << "\nName: " << c->getName() << "\n HP: " << c->getCurHP() << "/" << c->getMaxHP() << "\n MP: " << c->getCurMP() << "/" << c->getMaxMP() << "\n Lv: " << c->getLevel() << "\n Xp: " << c->getExperience() << "\n next: " << c->toNextLevel() << "\n++++++++++++++++++++++++" << std::endl; }