Advertisement
Guest User

Error

a guest
Apr 14th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <random>
  4. #include <chrono>
  5. #include <cmath>
  6. #include <stdio.h>
  7.  
  8. struct Move {
  9.     std::string move; // move name
  10.     int base_dam; // base damage
  11. };
  12. struct Monster {
  13.     std::string name;
  14.     int lvl;
  15.     int hp;
  16.     int attack;
  17.     int defence;
  18.     int speed;
  19.     Move moveset[4];
  20. };
  21.  
  22. Monster rat{ "rat", 1 ,40 , 7 , 8 , 10, {{"Bite", 5}, {"Tail whip", 6}, {"Pounce", 9}} };
  23. Monster bat{ "bat", 1 ,50 , 6 , 4 , 13, {{"Wing attack", 7}, {"Sonic scream", 5}, {"Leech Life", 9}} };
  24. Monster imp{ "imp", 1 ,60 , 7 , 7 , 10, {{"Ember", 7}, {"Magic attack", 5}, {"Fire spin", 9}} };
  25. Monster kobold{ "kobold", 1 ,80, 18 , 15 , 18 , {{"Shortsword Slash", 10}, {"Sneak Attack", 15}, {"Quick Strike", 12}, {"Poison Dart", 14}} };
  26. Monster Goblin{ "Goblin" , 1, 60 , 10 , 13, 15, {{"Club Attack", 6 }, {"Heavy Attack", 9}, {"Head smash", 10}, {"slam", 7}} };
  27. Monster Skeleton{ "skeleton", 1 ,50 , 18 , 8 , 10, {{"Piercing arrow", 10 }, {"Poison arrow",10}, {"Bone arrow", 12}, {"Multi_shot" , 15}} };
  28. Monster Spider{ "spider", 1 ,80 , 8 , 15 , 18, { {"String shot", 9}, {"Poison Bite", 10}, {"Sharp Claw", 8}, {"Scratch", 6}} };
  29. Monster Slime{ "Slime" , 1 ,100 , 8 , 18 , 5, {{"Spikes", 6}, {"Gunk shout", 10}, {"Poison gas" , 8}, {"Toxic", 7}} };
  30. Monster* Mon_info;
  31.  
  32. void print(std::string statement, int index) { // print(narrator , 0);
  33.  
  34.     std::cout << statement << std::fflush;
  35.     // std::this_thread::sleep_for(std::chrono::microseconds(100000));
  36.  
  37.  
  38. }
  39.  
  40. void battle(Monster* mon1, Monster& mon2)
  41. {
  42.     int input, dmg_taken, dmg_taken2;
  43.     while (mon1->hp > 0 && mon2.hp > 0) {
  44.  
  45.         std::cout << "Your lvl : " << mon1->lvl << "\t " << mon2.lvl << " lvl : " << mon2.lvl << std::endl;
  46.         std::cout << "Your HP : " << mon1->hp << "\t" << mon2.name << " HP : " << mon2.hp << std::endl;
  47.         std::cout << "What do you want to do?? \t" << " 1. Attack  2. Info\n";
  48.         std::cin >> input;
  49.         switch (input) {
  50.         case 1:
  51.             std::cout << "Choose your attack" << "\n";
  52.             for (int i{ 0 }; i < 4; i++) {
  53.                 std::cout << i + 1 << "." << mon1->moveset[i].move << "[" << mon1->moveset[i].base_dam << "]" << std::endl;
  54.             }
  55.             std::cin >> input;
  56.             std::cout << "You used " << mon1->moveset[input - 1].move << "\n";
  57.             dmg_taken = static_cast<int>(1.5 * (mon1->moveset[input - 1]).base_dam * static_cast<double>(mon1->attack) / mon2.defence);
  58.             std::cout << "You did " << dmg_taken << std::endl;
  59.             mon2.hp = mon2.hp - dmg_taken;
  60.             if (mon2.hp > 0) {
  61.                 std::mt19937 rn{ static_cast<unsigned int>(
  62.                     std::chrono::high_resolution_clock::now().time_since_epoch().count()
  63.                 ) };
  64.                 std::uniform_int_distribution<int> die4{ 1 , 3 };
  65.                 std::cout << "Monster" << " used " << mon2.moveset[die4(rn)].move << std::endl;
  66.                 dmg_taken2 = static_cast<int>(1.5 * mon1->moveset[input - 1].base_dam * static_cast<double>(mon2.attack) / mon1->defence);
  67.                 std::cout << "You lost " << dmg_taken2 << " hp" << std::endl;
  68.                 mon1->hp = mon1->hp - dmg_taken2;
  69.             }
  70.             if (mon1->hp == 0) {
  71.                 std::cout << "you lost lmao\n";
  72.             }
  73.  
  74.             break;
  75.         case 2:
  76.             std::cout << "Stats" << std::endl;
  77.             std::cout << "HP       : " << mon1->hp << "\n";
  78.             std::cout << "Attack   : " << mon1->attack << "\n";
  79.             std::cout << "Defence  : " << mon1->defence << "\n";
  80.             std::cout << "Speed    : " << mon1->speed << "\n";
  81.         }
  82.     }
  83.  
  84. }
  85.  
  86.  
  87. int main() {
  88.     Monster Mon_info;
  89.     int input;
  90.     std::string narrator;
  91.     char input2;
  92.     std::string m_race, P_name; // monster race and player name
  93.     narrator = "Welcome Traveler!!";
  94.     std::cout << narrator << std::endl;
  95. start:
  96.     narrator = "Please choose your monster race";
  97.     print(narrator, 0);
  98.     std::cout << std::endl;
  99.     narrator = "1. Goblin   2. Slime   3.Spider   4.Skeleton";
  100.     print(narrator, 0);
  101.     std::cout << "\n";
  102.     std::cin >> input;
  103.     switch (input) {
  104.     case 1:
  105.         std::cout << "Would you like to know more about Goblin??" << "\n";
  106.         std::cin >> input2;
  107.         if ((input2 != 'Y') && (input2 != 'y')) {
  108.             goto start;
  109.         }
  110.         else {
  111.             narrator = "Goblins are a common fantasy creature often depicted as small,"
  112.                 "green-skinned humanoids with pointy ears, sharp teeth, and a mischievous or malevolent nature. "
  113.                 "They are typically portrayed as being weak and cowardly in combat, but make up for it with their"
  114.                 "intelligence and cunning.";
  115.             print(narrator, 0);
  116.             std::cout << std::endl;
  117.             std::cout << "Would you like to be a Goblin??" << "\n";
  118.             std::cin >> input2;
  119.             if ((input2 != 'Y') && (input2 != 'y')) {
  120.                 goto start;
  121.             }
  122.             else {
  123.                 m_race = "goblin";
  124.                 Monster* Mon_info{ &Goblin };
  125.             }
  126.         }
  127.         break;
  128.  
  129.  
  130.  
  131.     case 2:
  132.         std::cout << "Would you like to know more about the slime??" << "\n";
  133.         std::cin >> input2;
  134.         if ((input2 != 'Y') && (input2 != 'y')) {
  135.             goto start;
  136.         }
  137.         else {
  138.             narrator = "Slimes are often depicted as gelatinous creatures with a simple, blob-like shape."
  139.                 "They are typically very weak and slow, but may have some unique abilities such as splitting into smaller slimes or leaving a trail of acid behind them.";
  140.             print(narrator, 0);
  141.             std::cout << std::endl;
  142.             std::cout << "Would you like to be a slime??" << "\n";
  143.             std::cin >> input2;
  144.             if ((input2 != 'Y') && (input2 != 'y')) {
  145.                 goto start;
  146.             }
  147.             else {
  148.                 m_race = "slime";
  149.                 Monster* Mon_info{ &Slime };
  150.             }
  151.         }
  152.         break;
  153.  
  154.  
  155.  
  156.     case 3:
  157.         std::cout << "Would you like to know more about the spider??" << "\n";
  158.         std::cin >> input2;
  159.         if ((input2 != 'Y') && (input2 != 'y')) {
  160.             goto start;
  161.         }
  162.         else {
  163.             narrator = "Spiders are arachnids with eight legs and two body segments, typically depicted in games as large, aggressive creatures with venomous bites."
  164.                 "They may be able to climb walls or shoot webs to immobilize the player."
  165.                 "Different types of spiders may have different abilities or weaknesses, such as resistance to poison or vulnerability to fire.";
  166.             print(narrator, 0);
  167.             std::cout << std::endl;
  168.             std::cout << "Would you like to be a spider??" << "\n";
  169.             std::cin >> input2;
  170.             if ((input2 != 'Y') && (input2 != 'y')) {
  171.                 goto start;
  172.             }
  173.             else {
  174.                 m_race = "spider";
  175.                 Monster* Mon_info{ &Spider };
  176.  
  177.             }
  178.         }
  179.         break;
  180.  
  181.  
  182.  
  183.  
  184.     case 4:
  185.         std::cout << "Would you like to know more about the skeleton??" << "\n";
  186.         std::cin >> input2;
  187.         if ((input2 != 'Y') && (input2 != 'y')) {
  188.             goto start;
  189.         }
  190.         else {
  191.             narrator = "Skeletons are undead creatures typically depicted as animated skeletons, either armed with weapons or using their own bones as weapons."
  192.                 "They are often weak to blunt damage but resistant to piercing and slashing attacks.";
  193.             print(narrator, 0);
  194.             std::cout << std::endl;
  195.             std::cout << "Would you like to be a Skeleton??" << "\n";
  196.             std::cin >> input2;
  197.             if ((input2 != 'Y') && (input2 != 'y')) {
  198.                 goto start;
  199.             }
  200.             else {
  201.                 m_race = "skeleton";
  202.                 Monster* Mon_info{ &Skeleton };
  203.             }       std::cout << "You are a " << m_race << " now";
  204.             std::cout << "Your states are :";
  205.             std::cout << "Hp " << Mon_info.attack << std::endl;
  206.             break;
  207.         }
  208.     }
  209.  
  210.  
  211.     std::string M_encounter;
  212.     std::cout << "Traveler, Please enter your name\n";
  213.     std::cin >> P_name;
  214.     std::cout << "All set, Entering the world..........." << "\n";
  215. start2:
  216.     std::cout << "B-Town" << "\n";
  217.     std::cout << "Gorgon :- Hurry!! The village is under attack, please do something" << "\n";
  218.     std::cout << "Harpy :- Hurry, we have to fight, The village leader is fighting to save the village " << "\n";
  219.     std::cout << "narrator :- While having conversation, one enters your house\n";
  220.     std::mt19937 mt{ static_cast<unsigned int>(
  221.         std::chrono::high_resolution_clock::now().time_since_epoch().count()
  222.     ) };
  223.  
  224.     std::uniform_int_distribution<int> MonNum{ 1 , 4 };
  225.     int Num = MonNum(mt);
  226.     if (Num == 1) {
  227.         M_encounter = "Rat";
  228.         battle(Mon_info, rat);
  229.     }
  230.     else if (Num == 2) {
  231.         M_encounter = "Bat";
  232.         battle(Mon_info, bat);
  233.     }
  234.     else if (Num == 3) {
  235.         M_encounter = "Imp";
  236.         battle(Mon_info, imp);
  237.     }
  238.     else {
  239.         M_encounter = "Kobold";
  240.         battle(Mon_info, kobold);
  241.  
  242.     }
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.     system("pause");
  250.     return 0;
  251. }
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
Tags: C++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement