Advertisement
Guest User

Untitled

a guest
Apr 9th, 2013
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4. #include<vector>
  5. #include<ctime>
  6. #include<stdlib.h>
  7. using namespace std;
  8. int loc = -1;
  9. int input;
  10. int target;
  11. int turn;
  12. int allycount = 0;
  13. int enemycount = 0;
  14. int sumofenemies = 0;
  15. int etarget;
  16. int eability = rand() % 2;
  17. int gold = 100;
  18. struct equipment {
  19.     string type;
  20.     string name;
  21.     int str;
  22.     int agl;
  23.     int hpmax;
  24. };
  25. struct ability {
  26.     int mp;
  27.     string name;
  28. };
  29. struct player {
  30.     string name;
  31.     int hp;
  32.     int hpmax;
  33.     int str;
  34.     int agl;
  35.     int ct;
  36.     string team;
  37.     bool dead;
  38.     int exp;
  39.     int expmax;
  40.     int lvl;
  41.     equipment equips;
  42.     ability ab[10];
  43. };
  44. int findturn(struct player *players) {
  45.     while(true) {
  46.         for(int i = 0; i < 6; i++) {
  47.             if(players[i].ct >= 100) {
  48.                 players[i].ct = 0;
  49.                 return i;
  50.             }
  51.             players[i].ct += players[i].agl;
  52.         }
  53.     }
  54. }
  55.  
  56. void checkability(struct player *players, int turn, int input, int target) {
  57.     if(players[turn].ab[input].name == "Attack") {
  58.         cout << players[turn].name << " attacks " << players[target].name << " with " << players[turn].str << endl;
  59.         players[target].hp -= players[turn].str;
  60.     }
  61. }
  62. void checkdeath(struct player *players) {
  63.     for(int i = 0; i < 5; i++) {
  64.         if(players[i].hp <= 0 && players[i].team == "ally" && !players[i].dead) {
  65.             players[i].dead = true;
  66.             allycount--;
  67.             players[i].hp = 0;
  68.             break;
  69.         }
  70.         if(players[i].hp < 0 && players[i].team == "enemy" && !players[i].dead) {
  71.             players[i].dead = true;
  72.             enemycount--;
  73.             players[i].hp = 0;
  74.             break;
  75.         }
  76.     }
  77. }
  78. void battle(struct player *players) {
  79.     while(true) {
  80.         checkdeath(players);
  81.         if(allycount <= 0) {
  82.             cout << endl << "Game over" << endl;
  83.             return;
  84.         }
  85.         if(enemycount <= 0) {
  86.             cout << endl << "Victory!" << endl;
  87.             for(int i = 3; i < 5; i++) {
  88.                 sumofenemies += players[i].expmax;
  89.             }
  90.             while(true) {
  91.                 if(sumofenemies < 0) break;
  92.                 for(int i = 0; i < 3; i++) {
  93.                     if(players[i].dead) players[i].exp--;
  94.                     players[i].exp++;
  95.                     sumofenemies--;
  96.                     if(players[i].exp >= players[i].expmax) {
  97.                         cout << players[i].name << " Level Up!" << endl;
  98.                         players[i].lvl++;
  99.                         players[i].expmax *= 2;;
  100.                         players[i].agl++;
  101.                     }
  102.                 }
  103.             }
  104.             enemycount = 2;
  105.             return;
  106.         }
  107.         checkdeath(players);
  108.         turn = findturn(players);
  109.         if(players[turn].dead) {
  110.             players[turn].ct = 0;
  111.             turn = findturn(players);
  112.         }
  113.         if(players[turn].team == "ally") {
  114.             cout << players[turn].name << endl;
  115.             for(int i = 0; i < 10; i++) {
  116.                 if(players[turn].ab[i].name == " ") break;
  117.                 cout << i << ": " << players[turn].ab[i].name << endl;
  118.             }
  119.             cout << ">> ";
  120.             cin >> input;
  121.             for(int v = 0; v < 5; v++) {
  122.                 cout << v << ": " << players[v].name << " HP: " << players[v].hp << endl;
  123.             }
  124.             cin >> target;
  125.             checkability(players, turn, input, target);
  126.             checkdeath(players);
  127.         }
  128.         if(players[turn].team == "enemy") {
  129.             while(players[etarget].dead && players[etarget].team == "enemy") {
  130.                 etarget = rand() % 6;
  131.             }
  132.             eability = rand() % 2;
  133.             checkability(players, turn, 0, etarget);
  134.             etarget = rand() % 6;
  135.         }
  136.         players[turn].ct = 0;
  137.         checkdeath(players);
  138.     }
  139. }
  140. int main() {
  141.     equipment items[10];
  142.     equipment shopitems[4];
  143.     shopitems[0].name = "Long Sword";
  144.     shopitems[0].str = 22;
  145.     shopitems[0].type = "Weapon";
  146.     shopitems[0].agl = 9;
  147.     shopitems[0].hpmax = 22;
  148.     shopitems[1].name = "Iron Sword";
  149.     shopitems[1].str = 33;
  150.     shopitems[1].type = "Weapon";
  151.     shopitems[1].agl = 10;
  152.     shopitems[1].hpmax = 33;
  153.     shopitems[2].name = "Genji Sword";
  154.     shopitems[2].str = 44;
  155.     shopitems[2].type = "Weapon";
  156.     shopitems[2].agl = 14;
  157.     shopitems[2].hpmax = 55;
  158.     shopitems[3].name = "Crystal Sword";
  159.     shopitems[3].str = 48;
  160.     shopitems[3].type = "Weapon";
  161.     shopitems[3].agl = 18;
  162.     shopitems[3].hpmax = 77;
  163.     for(int i = 0; i < 10; i++) {
  164.         items[i].name = " ";
  165.     }
  166.     fstream gamesave;
  167.     fstream gameload;
  168.     player players[7];
  169.     player enemies[2];
  170.     srand(time(0));
  171.     for(int i = 0; i < 3; i++) {
  172.         players[i].hp = 32;
  173.         players[i].hpmax = 32;
  174.         players[i].str = 13;
  175.         players[i].agl = 4;
  176.         players[i].lvl = 1;
  177.         players[i].exp = 0;
  178.         players[i].expmax = 8;
  179.         players[i].equips = shopitems[2];
  180.         players[i].hpmax = players[i].equips.hpmax;
  181.         players[i].agl = players[i].equips.agl;
  182.         players[i].str = players[i].equips.str;
  183.         players[i].team = "ally";
  184.         players[i].ab[0].name = "Attack";
  185.         players[i].ab[0].mp = 0;
  186.         players[i].ct = 0;
  187.         players[i].dead = false;
  188.     }
  189.     players[0].name = "Edge";
  190.     players[1].name = "Cloud";
  191.     players[2].name = "Tifa";
  192.     for(int i = 0; i < 2; i++) {
  193.         enemies[i].hp = 5;
  194.         enemies[i].hpmax = 5;
  195.         enemies[i].str = 5;
  196.         enemies[i].agl = 5;
  197.         enemies[i].lvl = 1;
  198.         enemies[i].exp = 0;
  199.         enemies[i].expmax = 8;
  200.         enemies[i].equips = shopitems[1];
  201.         enemies[i].hpmax = players[i].equips.hpmax;
  202.         enemies[i].agl = players[i].equips.agl;
  203.         enemies[i].str = players[i].equips.str;
  204.         enemies[i].team = "enemy";
  205.         enemies[i].name = "Goblin";
  206.         enemies[i].ab[0].name = "Attack";
  207.         enemies[i].ab[0].mp = 0;
  208.         enemies[i].ct = 0;
  209.         enemies[i].dead = false;
  210.     }
  211.     players[3] = enemies[0];
  212.     players[4] = enemies[1];
  213.     for(int i = 0; i < 6; i++) {
  214.         if(players[i].team == "enemy") {
  215.             enemycount++;
  216.         }
  217.         if(players[i].team == "ally") {
  218.             allycount++;
  219.         }
  220.     }
  221.     for(int i = 1; i < 10; i++) {
  222.         players[0].ab[i].name = " ";
  223.         players[1].ab[i].name = " ";
  224.         players[2].ab[i].name = " ";
  225.         players[3].ab[i].name = " ";
  226.         players[4].ab[i].name = " ";
  227.         players[5].ab[i].name = " ";
  228.         players[6].ab[i].name = " ";
  229.     }
  230.     while(true) {
  231.         if(loc == -1) {
  232.             cout << "   1: New game" << endl;
  233.             cout << "   2: Load game" << endl;
  234.             cin >> input;
  235.             if(input == 1) {
  236.                 // in construction
  237.             }
  238.             if(input == 2) {
  239.                 // in construction
  240.             }
  241.         }
  242.         loc = 0;
  243.         if(loc == 0) {
  244.             players[3] = enemies[0];
  245.             players[4] = enemies[1];
  246.             cout << "Welcome to the Ancient Forest" << endl;
  247.             cout << "   1: Fight in the arena" << endl;
  248.             cout << "   2: Shop" << endl;
  249.             cout << "   3: Equipment" << endl;
  250.             cout << "   4: States" << endl;
  251.             cin >> input;
  252.             switch(input) {
  253.                 case 1:
  254.                     battle(players);
  255.                     break;
  256.                 case 2:
  257.                     cout << endl << "Equipment shop" << endl;
  258.                     cout << "1: Long Sword" << endl;
  259.                     cout << "2: Iron Sword" << endl;
  260.                     cout << "3: Genji Sword" << endl;
  261.                     cout << "4: Crystal Sword" << endl;
  262.                     cin >> input;
  263.                     if(input == 1) {
  264.                         if(gold-10 <= 0) {
  265.                             cout << "Not enough money" << endl;
  266.                         } else {
  267.                             for(int i = 0; i < 10; i++) {
  268.                                 if(items[i].name == " ") {
  269.                                     cout << "Purchased!" << endl;
  270.                                     items[i] = shopitems[0];
  271.                                     gold -= 10;
  272.                                     break;
  273.                                 }
  274.                             }
  275.                         }
  276.                     }
  277.                     if(input == 2) {
  278.                         if(gold-20 <= 0) {
  279.                             cout << "Not enough money" << endl;
  280.                         } else {
  281.                             for(int i = 0; i < 10; i++) {
  282.                                 if(items[i].name == " ") {
  283.                                     cout << "Purchased!" << endl;
  284.                                     items[i] = shopitems[1];
  285.                                     gold -= 20;
  286.                                     break;
  287.                                 }
  288.                             }
  289.                         }
  290.                     }
  291.                     if(input == 3) {
  292.                         if(gold-30 <= 0) {
  293.                             cout << "Not enough money" << endl;
  294.                         } else {
  295.                             for(int i = 0; i < 10; i++) {
  296.                                 if(items[i].name == " ") {
  297.                                     cout << "Purchased!" << endl;
  298.                                     items[i] = shopitems[2];
  299.                                     gold -= 30;
  300.                                     break;
  301.                                 }
  302.                             }
  303.                         }
  304.                     }
  305.                     if(input == 4) {
  306.                         if(gold-10 <= 0) {
  307.                             cout << "Not enough money" << endl;
  308.                         } else {
  309.                             for(int i = 0; i < 10; i++) {
  310.                                 if(items[i].name == " ") {
  311.                                     cout << "Purchased!" << endl;
  312.                                     items[i] = shopitems[3];
  313.                                     gold -= 10;
  314.                                     break;
  315.                                 }
  316.                             }
  317.                         }
  318.                     }
  319.                     break;
  320.                 case 3:
  321.                     cout << "Equipment manager" << endl;
  322.                     cout << "   1: Equip" << endl;
  323.                     cout << "   2: Remove equipment" << endl;
  324.                     cout << "   3: Back" << endl;
  325.                     cin >> input;
  326.                     if(input == 1) {
  327.                         cout << "Who do you want to equip? " << endl;
  328.                         for(int i = 0; i < 3; i++) {
  329.                             cout << i << ": " << players[i].name << endl;
  330.                         }
  331.                         cin >> input;
  332.                         cout << endl << "What do you want to equip?" << endl;
  333.                         for(int i = 0; i < 10; i++) {
  334.                             cout << i << ": " << items[i].name << endl;
  335.                         }
  336.                         cin >> target;
  337.                         players[input].equips = items[target];
  338.                         players[input].hpmax = players[input].equips.hpmax;
  339.                         players[input].agl = players[input].equips.agl;
  340.                         players[input].str = players[input].equips.str;
  341.                         items[target].name = " ";
  342.                         input = 0;
  343.                     }
  344.                     if(input == 2) {
  345.                         cout << "Whos equipment do you want to remove?" << endl;
  346.                         for(int i = 0; i < 3; i++) {
  347.                             cout << i << ": " << players[i].name << endl;
  348.                         }
  349.                         cin >> target;
  350.                         for(int i = 0; i < 10; i++) {
  351.                             if(items[i].name == " ") {
  352.                                 items[i] = players[target].equips;
  353.                                 break;
  354.                             }
  355.                         }
  356.                         players[target].equips.name = " ";
  357.                         players[target].str = 8;
  358.                         players[target].agl = 6;
  359.                         players[target].hp = 32;
  360.                         players[target].hpmax = 32;
  361.                     }
  362.                     break;
  363.                     case 4:
  364.                         cout << "Check status for what character?" << endl;
  365.                         for(int i = 0; i < 3; i++) {
  366.                             cout << i << ": " << players[i].name << endl;
  367.                         }
  368.                         cin >> target;
  369.                         cout << "Stats for " << players[target].name << endl;
  370.                         cout << "Hp " << players[target].hp << endl;
  371.                         cout << "HpMax " << players[target].hpmax << endl;
  372.                         cout << "Str " << players[target].str << endl;
  373.                         cout << "Agl " << players[target].agl << endl;
  374.                         cout << "Equipment " << players[target].equips.name << endl;
  375.                         break;
  376.             }
  377.         }
  378.     }
  379. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement