Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 22nd, 2012  |  syntax: None  |  size: 8.73 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <stdlib.h>
  5. using namespace std;
  6. struct player {
  7.        int hp;
  8.        int hpmax;
  9.        int agi;
  10.        int str;
  11.        string name;
  12.        string abilities[2];
  13.        bool dead;
  14.        int ct;
  15.        string ally;
  16. };
  17. void checkabi(struct player *players, int i, int target, int input) {
  18.                         if(players[target].hp+players[i].str <= players[target].hpmax) {
  19.                         if(players[i].abilities[input] == "Attack") {
  20.                                         cout << players[i].name << " attacks " << players[target].name << " with " << players[i].str << " dmg" << endl;
  21.                                         players[target].hp += players[i].str;
  22.                         }
  23.                         if(players[i].abilities[input] == "Heal") {
  24.                                         cout << players[i].name << " heals " << players[target].name << " with " << "500"<< " restored hp " << endl;
  25.                                         players[target].hp += 500;
  26.                         }
  27.                         if(players[i].abilities[input] == "HellFire") {
  28.                                         cout << players[i].name << " Casts HellFire " << players[target].name << " with " << players[i].str*2 << " dmg" << endl;
  29.                                         players[target].hp += players[i].str*2;
  30.                         }
  31.                         if(players[i].abilities[input] == "Heal") {
  32.                                         cout << players[i].name << " Heals " << players[target].name << " with " << players[i].str << " restored hp" << endl;
  33.                                         players[target].hp += 100;
  34.                         }
  35.                         if(players[i].abilities[input] == "Cross Slash") {
  36.                                         cout << players[i].name << " Cross slashes " << players[target].name << " with " << players[i].str*4 << " dmg" << endl;
  37.                                         players[target].hp += players[i].str*4;
  38.                         }
  39.                         if(players[i].abilities[input] == "Punch Art") {
  40.                                         cout << players[i].name << " uses Punch Art on " << players[target].name << " with " << players[i].str*3 << " dmg" << endl;
  41.                                         players[target].hp += players[i].str*3;
  42.                         }
  43.                         if(players[i].abilities[input] == "Goblin Punch") {
  44.                                         cout << players[i].name << " uses Goblin Punch on " << players[target].name << " with " << players[i].str*3 << " dmg" << endl;
  45.                                         players[target].hp += players[i].str*3;
  46.                         }
  47.                                         players[i].ct = 0;
  48.                         } else {
  49.                                         players[i].ct = 0;
  50.                                         players[target].hp = players[target].hpmax;
  51.                         }
  52. }
  53. int ac = 0;
  54. int ec = 0;
  55. int etarget = rand() % 4;
  56. int eability = rand() % 1;
  57. int main() {
  58.     int input;
  59.     int target;
  60.     player players[6];
  61.     players[0].hp = 1500;
  62.     cout << "Enter Ally 1 agility: ";
  63.     cin >> players[0].agi;
  64.     cout << "Enter Ally 1 strenght: ";
  65.     cin >> players[0].str;
  66.     players[0].abilities[0] = "Attack";
  67.     players[0].abilities[1] = "Summon";
  68.     players[0].name = "Edge";
  69.     players[1].hp = 4000;
  70.     cout << "Enter Ally 2 agility: ";
  71.     cin >> players[1].agi;
  72.     cout << "Enter Ally 2 strenght: ";
  73.     cin >> players[1].str;
  74.     players[1].abilities[0] = "Attack";
  75.     players[1].abilities[1] = "Cross Slash";
  76.     players[1].name = "Cloud";
  77.     players[2].hp = 4000;
  78.     cout << "Enter Ally 3 agility: ";
  79.     cin >> players[2].agi;
  80.     cout << "Enter Ally 3 strenght: ";
  81.     cin >> players[2].str;
  82.     players[2].abilities[0] = "Attack";
  83.     players[2].abilities[1] = "Punch Art";
  84.     players[2].name = "Tifa";
  85.     players[3].hp = 8000;
  86.     cout << "Enter Enemy 1 agility: ";
  87.     cin >> players[3].agi;
  88.     players[3].name = "Goblin";
  89.     cout << "Enter Enemy 1 Strenght: ";
  90.     cin >> players[3].str;
  91.     players[3].abilities[0] = "Attack";
  92.     players[3].abilities[1] = "Goblin Punch";
  93.     players[4].hp = 13000;
  94.     players[4].abilities[0] = "Attack";
  95.     players[4].abilities[1] = "HellFire";
  96.     cout << "Enter Enemy 2 agility: ";
  97.     cin >> players[4].agi;
  98.     players[4].name = "Ifrit";
  99.     cout << "Enter Enemy 2 Strenght: ";
  100.     cin >> players[4].str;
  101.     for(int i = 0; i <= 4; i++) {
  102.             players[i].dead = false;
  103.             players[i].hpmax = players[i].hp;
  104.             players[i].ct = 0;
  105.             players[i].ally = "ally";  
  106.     }                                                        
  107.     players[3].ally = "enemy";
  108.     players[4].ally = "enemy";
  109.     for(int i = 0; i <= 4; i++) {
  110.             if(players[i].ally == "ally") {
  111.                 ac += 1;
  112.             }
  113.             if(players[i].ally == "enemy") {
  114.                 ec += 1;
  115.             }
  116.     }
  117.     while(true) {
  118.                 for(int i = 0; i <= 4; i++) {
  119.                         if(players[i].hp <= 0 && players[i].ally == "ally" && !players[i].dead) {
  120.                                          players[i].dead = true;
  121.                                          ac -= 1;
  122.                                          break;  
  123.                         }
  124.                         if(players[i].hp <= 0 && players[i].ally == "enemy" && !players[i].dead) {
  125.                                          ec -= 1;
  126.                                          players[i].dead = true;
  127.                                          break;
  128.                                            
  129.                         }
  130.                         if(ac <= 0) {
  131.                               cout << "\nLost\n";
  132.                               cin.get();
  133.                               cin.get();
  134.                               exit(0);
  135.                         }
  136.                         if(ec <= 0) {
  137.                               cout << "\nwon\n";
  138.                               cin.get();
  139.                               cin.get();
  140.                               exit(0);  
  141.                         }
  142.                 }
  143.                 for(int i = 0; i <= 5; i++) {
  144.                         if(players[i].ct >= 100) {
  145.                         if(players[i].ally == "ally") {
  146.                                             cout << players[i].name << endl;
  147.                         for(int c = 0; c <= 1; c++) {
  148.                                 cout << c << " - " << players[i].abilities[c] << endl;      
  149.                         }
  150.                         cin >> input;
  151.                         cout << "Who do you want to target?\n";
  152.                         for(int j = 0; j <= 4; j++) {
  153.                                 cout << j << " - " << players[j].name << " Hp: " << players[j].hp << endl;      
  154.                         }
  155.                         cin >> target;
  156.                         if(players[target].dead) {
  157.                                                  cout << "\nAlready dead\n";
  158.                                                  players[i].ct = 0;
  159.                                                  break;                      
  160.                         }
  161.                         checkabi(players, i, target, input); break;
  162.                         }
  163.                         if(players[i].ally == "enemy") {
  164.                         while(true) {
  165.                         if(players[etarget].dead || players[etarget].ally == "enemy") {
  166.                         if(ac <= 0) break;
  167.                                               time_t t;
  168.                                               time(&t);
  169.                                               srand(t);
  170.                                               etarget = rand() % 4;                          
  171.                         }
  172.                         if(!players[etarget].dead || players[etarget].ally == "ally") break;  
  173.                         }
  174.                         checkabi(players, i, target, eability);
  175.                                               players[i].ct = 0;
  176.                                               time_t t;
  177.                                               time(&t);
  178.                                               srand(t);
  179.                                               etarget = rand() % 2;
  180.                                               time(&t);
  181.                                               srand(t);
  182.                                               eability = rand() % 1;
  183.                                               }
  184.                         }
  185.                         players[i].ct += players[i].agi;
  186.                         if(players[i].dead) players[i].ct = 0;
  187.                 }          
  188.     }
  189. }