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.

88 lines
2.7 KiB

  1. #include "src/interface/battle.hpp"
  2. #include <iostream>
  3. #include <unistd.h>
  4. bool Battle::win = false;
  5. bool Battle::Won()
  6. {
  7. return win;
  8. }
  9. bool Battle::Lose()
  10. {
  11. return !win;
  12. }
  13. void Battle::Start(Player *player, Monster *monster)
  14. {
  15. std::cout << " ===== BATTLE INFO ===== \n"
  16. << player->getName() << " Lv." << player->getLevel() << ":\n"
  17. << " HP : " << player->getCurrentHP() << "/" << player->getMaxHP() << "\n"
  18. << " Atk : " << player->getAtk() << "\n"
  19. << " Def : " << player->getDef() << "\n"
  20. << " VS \n"
  21. << monster->getName() << "\n"
  22. << " HP : " << monster->getCurrentHP() << "/" << monster->getMaxHP() << "\n"
  23. << " Atk : " << monster->getAtk() << "\n"
  24. << " Def : " << monster->getDef() << "\n"
  25. << " Drop: " << monster->getBounty() << "\n"
  26. << std::endl;
  27. std::cout << " ===== BATTLE START ===== " << std::endl;
  28. while (player->isAlive() && monster->isAlive())
  29. {
  30. std::cout << player->getName() << " attacked " << monster->getName() << "!" << std::endl;
  31. usleep(200000);
  32. int monsterDmg = monster->defend(player->getAtk());
  33. if (monsterDmg > 0)
  34. {
  35. std::cout << monster->getName() << " got hit by " << monsterDmg << " points!" << std::endl;
  36. }
  37. else
  38. {
  39. std::cout << monster->getName() << " blocked the attack!" << std::endl;
  40. }
  41. usleep(200000);
  42. if (monster->isAlive())
  43. {
  44. std::cout << monster->getName() << " attacked " << player->getName() << "!" << std::endl;
  45. usleep(200000);
  46. int playerDmg = player->defend(monster->getAtk());
  47. if (playerDmg > 0)
  48. {
  49. std::cout << player->getName() << " got hit by " << playerDmg << " points!" << std::endl;
  50. }
  51. else
  52. {
  53. std::cout << player->getName() << " blocked the attack!" << std::endl;
  54. }
  55. usleep(200000);
  56. }
  57. }
  58. if (player->isAlive())
  59. {
  60. std::cout << "YOU WIN !!!\n"
  61. << "Got " << monster->getBounty() << " points of experience.\n"
  62. << std::flush;
  63. player->takeExperience(monster->getBounty());
  64. if (player->checkLevelup())
  65. {
  66. std::cout << "You leveled up!" << std::endl;
  67. player->levelUp();
  68. }
  69. else
  70. {
  71. std::cout << player->expToLevelUp() << " points left to level up.\n"
  72. << std::flush;
  73. }
  74. win = true;
  75. }
  76. else
  77. {
  78. std::cout << "YOU LOSE !!!!!" << std::endl;
  79. win = false;
  80. }
  81. }