Advertisement
Guest User

Combat System

a guest
Mar 18th, 2019
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.44 KB | None | 0 0
  1.   #include <iostream>
  2.     #include <cstdlib>
  3.     #include <cmath>
  4.     #include <ctime>
  5.  
  6.     using namespace std;
  7.  
  8.     int main()
  9.     {
  10.       int eHealth = 100; // initial Enemy Health(based on enemy)
  11.       int pHealth = 100; // initial Player Health
  12.       int eAttack = 0; // Enemy Attack Strength(based on enemy)
  13.       int pAttack = 0; // Player Attack Strength(based on level and items)
  14.       int selection = 0; // Selection Variable for Battle Menu
  15.       int hPower = 0; // Healing power Variable(random number)
  16.       int eSelection = 0; // Enemies battle menu selection variable
  17.       int counter = 0; // Counter to establish whos turn it is
  18.       int itemSelect = 0; // Item inventory selection
  19.       int eMagic = 50; // Enemies magic meter
  20.       int pMagic = 50; // Players magic meter
  21.       num1
  22.       num2
  23.       int attackselect = 0;
  24.  
  25.       cout << "Health: "; // Player name
  26.       cout << pHealth << " " << eHealth << endl; // player and enemy health levels
  27.       cout << "Mana: "; // Player's Magic
  28.       cout << pMagic << " " << eMagic << endl; // player and enemy magic levels
  29.       cout << endl;
  30.       cout << endl;
  31.       cout << "1.Basic Attack" << endl; // lines 31-33 are the battle menu appears
  32.                                         // frequently throught game
  33.       cout << "2.Special Attack" << endl;
  34.       cout << "3.Item" << endl;
  35.       do // start of post test loop that runs the game until somebody is dead
  36.       {
  37.         if (counter == 0) // if the counter variable is 0 it is the players turn
  38.         {
  39.           cin >> selection;
  40.           srand(static_cast<int>(time(0))); // randomize all the random variables
  41.           switch (selection)
  42.           {
  43.           case 1: // player chooses to Basic Attack
  44.             pAttack = 1 + rand() % (35 - 1 + 1); // attack power can be between 1-35
  45.             cout << "Basic Attack" << pAttack << endl;
  46.             eHealth = eHealth - pAttack;
  47.             cout << pHealth << " " << eHealth << endl;
  48.             cout << pMagic << " " << eMagic << endl;
  49.             cout << endl;
  50.             cout << endl;
  51.             cout << "1.Basic Attack" << endl;
  52.             cout << "2.Special Attack" << endl;
  53.             cout << "3.Item" << endl;
  54.             break;
  55.           case 2: // if player chooses to use special attack system
  56.             cout << "Attack WEAPONS" << endl;
  57.             cout << "1. Forks - 15 TO 20 HP Damage - 10 MP Used" << endl;
  58.             pAttack = 1 + rand() % (20 - 15 + 15);
  59.             eHealth = eHealth - pAttack;
  60.            pHealth=pHealth+hPower;
  61.            pMagic=pMagic-10;
  62.             cout << endl;
  63.             cout << endl;
  64.             cout << "1.Basic Attack" << endl;
  65.             cout << "2.Special Attack" << endl;
  66.             cout << "3.Item" << endl;
  67.             break;
  68.            
  69.  
  70.            
  71.             cout << "2. Plastic Knives - 20 TO 30 HP Damage - 15 MP Used" << endl;
  72.             pAttack = 1 + rand() % (30 - 20 + 20 );
  73.             eHealth = eHealth - pAttack;
  74.            pHealth=pHealth+hPower;
  75.            pMagic=pMagic-15;
  76.             cout << endl;
  77.             cout << endl;
  78.             cout << "1.Basic Attack" << endl;
  79.             cout << "2.Special Attack" << endl;
  80.             cout << "3.Item" << endl;
  81.             break;
  82.          
  83.  
  84.            
  85.             cout << "3. Bow and Arrows - 10 TO 15 HP Damage - 5 MP Used"  << endl;
  86.             pAttack = 1 + rand() % (15 - 10 + 10 );
  87.             eHealth = eHealth - pAttack;
  88.            pHealth=pHealth+hPower;
  89.            pMagic=pMagic-15;
  90.             cout << endl;
  91.             cout << endl;
  92.             cout << "1.Basic Attack" << endl;
  93.             cout << "2.Special Attack" << endl;
  94.             cout << "3.Item" << endl;
  95.             break;
  96.            
  97.  
  98.              
  99.             cout << "4. Axes - 50 HP Damage - 35 MP Used" << endl;
  100.              pAttack = 1 + rand() % (50 - 50 + 50 );
  101.             eHealth = eHealth - pAttack;
  102.            pHealth=pHealth+hPower;
  103.            pMagic=pMagic-35;
  104.             cout << endl;
  105.             cout << endl;
  106.             cout << "1.Basic Attack" << endl;
  107.             cout << "2.Special Attack" << endl;
  108.             cout << "3.Item" << endl;
  109.             break;
  110.              
  111.              
  112.              
  113.              
  114.              
  115.              
  116.              
  117.             cout << "5. Ice Swords - Freezes oponent for 1 Turn - 30 TO 35 HP Damage - 40 MP Used" << endl;
  118.              pAttack = 1 + rand() % (35 - 30 + 30 );
  119.             eHealth = eHealth - pAttack;
  120.             srand (static_cast <unsigned int>(time(0)));
  121.             num1 = 1 + rand() % 6;
  122.             num2 = 1 + rand() % 12;
  123.            pHealth=pHealth+hPower;
  124.            pMagic=pMagic-40;
  125.             cout << endl;
  126.             cout << endl;
  127.             cout << "1.Basic Attack" << endl;
  128.             cout << "2.Special Attack" << endl;
  129.             cout << "3.Item" << endl;
  130.             break;
  131.              
  132.              
  133.              
  134.              
  135.              
  136.              
  137.             cin >> selection;
  138.             switch (selection)
  139.             {
  140.             case 1:
  141.               eHealth = eHealth - 15;
  142.               cout << pHealth << " " << eHealth << endl;
  143.               cout << pMagic << " " << eMagic << endl;
  144.               cout << endl;
  145.               cout << endl;
  146.               cout << "1.Basic Attack" << endl;
  147.               cout << "2.Special Attack" << endl;
  148.               cout << "3.Item" << endl;
  149.               break;
  150.             case 2:
  151.               break;
  152.             } // endSpecial AttackSwitch
  153.           } // endSelectionSwitch
  154.           counter = 1; // advances the counter to 1 to allow the enemies turn
  155.         } // endif
  156.  
  157.         eSelection = rand() % 2 + 1;
  158.         switch (eSelection)
  159.  
  160.                 case 3:// if player chooses to use item inventory system
  161.                 cout<<"ITEM INVENTORY"<<endl;
  162.                 cout<<"1.Gatorade            Restores 50 HP"<<endl;
  163.                 cout<<"2.Ice Coffee             Restores 50 MP"<<endl;
  164.                 cout<<"3.Bomb              Causes Damage to Player"<<endl;
  165.  
  166.  
  167.                 cin>>itemSelect;
  168.                     switch(itemSelect){
  169.                         case 1:
  170.                             pHealth=pHealth+50;
  171.                             cout<<pHealth<<"        "<<eHealth<<endl;
  172.                             cout<<pMagic<<"        "<<eMagic<<endl;
  173.                             cout<<endl;
  174.                             cout<<endl;
  175.                             cout<<"1.Basic Attack"<<endl;
  176.                             cout<<"2.Special Attack"<<endl;
  177.                             cout<<"3.Item"<<endl;
  178.                             break;
  179.                         case 2:
  180.                             pMagic=pMagic+50;
  181.                             cout<<pHealth<<"        "<<eHealth<<endl;
  182.                             cout<<pMagic<<"        "<<eMagic<<endl;
  183.                             cout<<endl;
  184.                             cout<<endl;
  185.                             cout<<"1.Basic Attack"<<endl;
  186.                             cout<<"2.Special Attack"<<endl;
  187.                             cout<<"3.Item"<<endl;
  188.                             break;
  189.                         case 3:
  190.                             pHealth=pHealth-10;
  191.                             eHealth=eHealth-30;
  192.                             cout<<pHealth<<"       "<<eHealth<<endl;
  193.                             cout<<pMagic<<"        "<<eMagic<<endl;
  194.                             cout<<endl;
  195.                             cout<<endl;
  196.                             cout<<"1.Basic Attack"<<endl;
  197.                             cout<<"2.Special Attack"<<endl;
  198.                             cout<<"3.Item"<<endl;
  199.                             break;
  200.                             }//endItemSwitch        
  201.             }while//endSelectionSwitch
  202.         (counter=1);// advances the counter to 1 to allow the enemies turn
  203.     {//endif
  204.             eSelection=rand() % 2+1;
  205.                 switch(eSelection)
  206.                 {
  207.                     case 1:
  208.                     eAttack=1+rand()%(35-1+1);
  209.                     cout<<"ENEMY ATTACKED PLAYER FOR "<<eAttack<<endl;
  210.                     pHealth=pHealth-eAttack;
  211.                     cout<<pHealth<<"        "<<eHealth<<endl;
  212.                     cout<<pMagic<<"        "<<eMagic<<endl;
  213.                     cout<<endl;
  214.                     cout<<endl;
  215.                     cout<<"1.Basic Attack"<<endl;
  216.                     cout<<"2.Special Attack"<<endl;
  217.                     cout<<"3.Item"<<endl;
  218.                 break; case 2:
  219.  
  220.                     if(eMagic>10)
  221.                     {
  222.                        hPower=1+rand()%(35-1+1);
  223.                        cout<<"ENEMY HEALED FOR "<<hPower<<endl;
  224.                        eMagic=eMagic-10;
  225.                        eHealth=eHealth+hPower;
  226.                        cout<<pHealth<<"        "<<eHealth<<endl;
  227.                        cout<<pMagic<<"        "<<eMagic<<endl;
  228.                        cout<<endl;
  229.                        cout<<endl;
  230.                        cout<<"1.Basic Attack"<<endl;
  231.                        cout<<"2.Special Attack"<<endl;
  232.                        cout<<"3.Item"<<endl;
  233.                     }
  234.                 break;
  235.             }//endeSelectionSwitch
  236.                 counter=0;
  237.     }while(eHealth > 1 && pHealth > 1);//loops while both players life is over 1 ends postest loop when players life or enemies falls below 1
  238.  
  239.    
  240.     return 0;
  241.     }
  242.  
  243.  
  244.  
  245.  
  246.  
  247. //Why are Special & Items Conflicting each other?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement