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.
 
 
 
 

211 lines
5.9 KiB

#include "UserInterface.hpp"
#include "Game.hpp"
const int UserInterface::maxDay = 28;
const int UserInterface::maxMonth = 12;
const int UserInterface::maxYear = 100;
int UserInterface::day = 1;
int UserInterface::month = 1;
int UserInterface::year = 90;
std::vector<std::string> UserInterface::dayName = {
"Morndas",
"Tirdas",
"Middas",
"Turdas",
"Fredas",
"Loredas",
"Sundas",
};
std::vector<std::string> 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, int interval)
{
std::cout << msg << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
}
void UserInterface::println(std::string msg, int interval)
{
std::cout << msg << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
}
void UserInterface::printByChar(std::string msg, int interval)
{
for (size_t i = 0; i < msg.size(); i++)
{
std::cout << msg.at(i) << std::flush;
std::this_thread::sleep_for(std::chrono::milliseconds(interval));
}
}
void UserInterface::welcomeMessage()
{
std::cout << "+++++++++++++++++++++++++++++++++++\n"
<< "+ Welcome to Spell-Warz-Again !!! +\n"
<< "+++++++++++++++++++++++++++++++++++\n"
<< std::flush;
}
Character *UserInterface::characterCreation()
{
std::string buffer;
std::cout << "Who should we call you?\n"
<< ">" << std::flush;
std::cin >> buffer;
std::cout << "Now pick your elements: \n";
std::map<std::string, Element>::iterator it;
int i = 0;
int max = Game::Elements.size() - 2;
for (it = Game::Elements.begin(); i < max; ++it)
{
std::cout << "[" << i++ << "] " << it->second.getName() << '\n';
}
int element = UserInterface::getNumber("#", 0, max);
return new Character(buffer, Game::Elements.begin() + element);
}
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<Character *> &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)
{
day = 1;
if (UserInterface::month++ >= UserInterface::maxMonth)
{
month = 1;
if (UserInterface::year++ >= UserInterface::maxYear)
{
exit(0);
}
}
}
}
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;
}