#include "src/interface/battle.hpp"
|
|
|
|
#include <iostream>
|
|
#include <unistd.h>
|
|
|
|
bool Battle::win = false;
|
|
|
|
bool Battle::Won()
|
|
{
|
|
return win;
|
|
}
|
|
|
|
bool Battle::Lose()
|
|
{
|
|
return !win;
|
|
}
|
|
|
|
void Battle::Start(Player *player, Monster *monster)
|
|
{
|
|
std::cout << " ===== BATTLE INFO ===== \n"
|
|
<< player->getName() << " Lv." << player->getLevel() << ":\n"
|
|
<< " HP : " << player->getCurrentHP() << "/" << player->getMaxHP() << "\n"
|
|
<< " Atk : " << player->getAtk() << "\n"
|
|
<< " Def : " << player->getDef() << "\n"
|
|
<< " VS \n"
|
|
<< monster->getName() << "\n"
|
|
<< " HP : " << monster->getCurrentHP() << "/" << monster->getMaxHP() << "\n"
|
|
<< " Atk : " << monster->getAtk() << "\n"
|
|
<< " Def : " << monster->getDef() << "\n"
|
|
<< " Drop: " << monster->getBounty() << "\n"
|
|
<< std::endl;
|
|
|
|
std::cout << " ===== BATTLE START ===== " << std::endl;
|
|
while (player->isAlive() && monster->isAlive())
|
|
{
|
|
std::cout << player->getName() << " attacked " << monster->getName() << "!" << std::endl;
|
|
usleep(200000);
|
|
int monsterDmg = monster->defend(player->getAtk());
|
|
if (monsterDmg > 0)
|
|
{
|
|
std::cout << monster->getName() << " got hit by " << monsterDmg << " points!" << std::endl;
|
|
}
|
|
else
|
|
{
|
|
std::cout << monster->getName() << " blocked the attack!" << std::endl;
|
|
}
|
|
usleep(200000);
|
|
|
|
if (monster->isAlive())
|
|
{
|
|
std::cout << monster->getName() << " attacked " << player->getName() << "!" << std::endl;
|
|
usleep(200000);
|
|
int playerDmg = player->defend(monster->getAtk());
|
|
if (playerDmg > 0)
|
|
{
|
|
std::cout << player->getName() << " got hit by " << playerDmg << " points!" << std::endl;
|
|
}
|
|
else
|
|
{
|
|
std::cout << player->getName() << " blocked the attack!" << std::endl;
|
|
}
|
|
usleep(200000);
|
|
}
|
|
}
|
|
|
|
if (player->isAlive())
|
|
{
|
|
std::cout << "YOU WIN !!!\n"
|
|
<< "Got " << monster->getBounty() << " points of experience.\n"
|
|
<< std::flush;
|
|
player->takeExperience(monster->getBounty());
|
|
if (player->checkLevelup())
|
|
{
|
|
std::cout << "You leveled up!" << std::endl;
|
|
player->levelUp();
|
|
}
|
|
else
|
|
{
|
|
std::cout << player->expToLevelUp() << " points left to level up.\n"
|
|
<< std::flush;
|
|
}
|
|
win = true;
|
|
}
|
|
else
|
|
{
|
|
std::cout << "YOU LOSE !!!!!" << std::endl;
|
|
win = false;
|
|
}
|
|
}
|