Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<fstream>
- #include<vector>
- #include<ctime>
- #include<stdlib.h>
- using namespace std;
- int loc = -1;
- int input;
- int target;
- int turn;
- int allycount = 0;
- int enemycount = 0;
- int sumofenemies = 0;
- int etarget;
- int eability = rand() % 2;
- int gold = 100;
- struct equipment {
- string type;
- string name;
- int str;
- int agl;
- int hpmax;
- };
- struct ability {
- int mp;
- string name;
- };
- struct player {
- string name;
- int hp;
- int hpmax;
- int str;
- int agl;
- int ct;
- string team;
- bool dead;
- int exp;
- int expmax;
- int lvl;
- equipment equips;
- ability ab[10];
- };
- int findturn(struct player *players) {
- while(true) {
- for(int i = 0; i < 6; i++) {
- if(players[i].ct >= 100) {
- players[i].ct = 0;
- return i;
- }
- players[i].ct += players[i].agl;
- }
- }
- }
- void checkability(struct player *players, int turn, int input, int target) {
- if(players[turn].ab[input].name == "Attack") {
- cout << players[turn].name << " attacks " << players[target].name << " with " << players[turn].str << endl;
- players[target].hp -= players[turn].str;
- }
- }
- void checkdeath(struct player *players) {
- for(int i = 0; i < 5; i++) {
- if(players[i].hp <= 0 && players[i].team == "ally" && !players[i].dead) {
- players[i].dead = true;
- allycount--;
- players[i].hp = 0;
- break;
- }
- if(players[i].hp < 0 && players[i].team == "enemy" && !players[i].dead) {
- players[i].dead = true;
- enemycount--;
- players[i].hp = 0;
- break;
- }
- }
- }
- void battle(struct player *players) {
- while(true) {
- checkdeath(players);
- if(allycount <= 0) {
- cout << endl << "Game over" << endl;
- return;
- }
- if(enemycount <= 0) {
- cout << endl << "Victory!" << endl;
- for(int i = 3; i < 5; i++) {
- sumofenemies += players[i].expmax;
- }
- while(true) {
- if(sumofenemies < 0) break;
- for(int i = 0; i < 3; i++) {
- if(players[i].dead) players[i].exp--;
- players[i].exp++;
- sumofenemies--;
- if(players[i].exp >= players[i].expmax) {
- cout << players[i].name << " Level Up!" << endl;
- players[i].lvl++;
- players[i].expmax *= 2;;
- players[i].agl++;
- }
- }
- }
- enemycount = 2;
- return;
- }
- checkdeath(players);
- turn = findturn(players);
- if(players[turn].dead) {
- players[turn].ct = 0;
- turn = findturn(players);
- }
- if(players[turn].team == "ally") {
- cout << players[turn].name << endl;
- for(int i = 0; i < 10; i++) {
- if(players[turn].ab[i].name == " ") break;
- cout << i << ": " << players[turn].ab[i].name << endl;
- }
- cout << ">> ";
- cin >> input;
- for(int v = 0; v < 5; v++) {
- cout << v << ": " << players[v].name << " HP: " << players[v].hp << endl;
- }
- cin >> target;
- checkability(players, turn, input, target);
- checkdeath(players);
- }
- if(players[turn].team == "enemy") {
- while(players[etarget].dead && players[etarget].team == "enemy") {
- etarget = rand() % 6;
- }
- eability = rand() % 2;
- checkability(players, turn, 0, etarget);
- etarget = rand() % 6;
- }
- players[turn].ct = 0;
- checkdeath(players);
- }
- }
- int main() {
- equipment items[10];
- equipment shopitems[4];
- shopitems[0].name = "Long Sword";
- shopitems[0].str = 22;
- shopitems[0].type = "Weapon";
- shopitems[0].agl = 9;
- shopitems[0].hpmax = 22;
- shopitems[1].name = "Iron Sword";
- shopitems[1].str = 33;
- shopitems[1].type = "Weapon";
- shopitems[1].agl = 10;
- shopitems[1].hpmax = 33;
- shopitems[2].name = "Genji Sword";
- shopitems[2].str = 44;
- shopitems[2].type = "Weapon";
- shopitems[2].agl = 14;
- shopitems[2].hpmax = 55;
- shopitems[3].name = "Crystal Sword";
- shopitems[3].str = 48;
- shopitems[3].type = "Weapon";
- shopitems[3].agl = 18;
- shopitems[3].hpmax = 77;
- for(int i = 0; i < 10; i++) {
- items[i].name = " ";
- }
- fstream gamesave;
- fstream gameload;
- player players[7];
- player enemies[2];
- srand(time(0));
- for(int i = 0; i < 3; i++) {
- players[i].hp = 32;
- players[i].hpmax = 32;
- players[i].str = 13;
- players[i].agl = 4;
- players[i].lvl = 1;
- players[i].exp = 0;
- players[i].expmax = 8;
- players[i].equips = shopitems[2];
- players[i].hpmax = players[i].equips.hpmax;
- players[i].agl = players[i].equips.agl;
- players[i].str = players[i].equips.str;
- players[i].team = "ally";
- players[i].ab[0].name = "Attack";
- players[i].ab[0].mp = 0;
- players[i].ct = 0;
- players[i].dead = false;
- }
- players[0].name = "Edge";
- players[1].name = "Cloud";
- players[2].name = "Tifa";
- for(int i = 0; i < 2; i++) {
- enemies[i].hp = 5;
- enemies[i].hpmax = 5;
- enemies[i].str = 5;
- enemies[i].agl = 5;
- enemies[i].lvl = 1;
- enemies[i].exp = 0;
- enemies[i].expmax = 8;
- enemies[i].equips = shopitems[1];
- enemies[i].hpmax = players[i].equips.hpmax;
- enemies[i].agl = players[i].equips.agl;
- enemies[i].str = players[i].equips.str;
- enemies[i].team = "enemy";
- enemies[i].name = "Goblin";
- enemies[i].ab[0].name = "Attack";
- enemies[i].ab[0].mp = 0;
- enemies[i].ct = 0;
- enemies[i].dead = false;
- }
- players[3] = enemies[0];
- players[4] = enemies[1];
- for(int i = 0; i < 6; i++) {
- if(players[i].team == "enemy") {
- enemycount++;
- }
- if(players[i].team == "ally") {
- allycount++;
- }
- }
- for(int i = 1; i < 10; i++) {
- players[0].ab[i].name = " ";
- players[1].ab[i].name = " ";
- players[2].ab[i].name = " ";
- players[3].ab[i].name = " ";
- players[4].ab[i].name = " ";
- players[5].ab[i].name = " ";
- players[6].ab[i].name = " ";
- }
- while(true) {
- if(loc == -1) {
- cout << " 1: New game" << endl;
- cout << " 2: Load game" << endl;
- cin >> input;
- if(input == 1) {
- // in construction
- }
- if(input == 2) {
- // in construction
- }
- }
- loc = 0;
- if(loc == 0) {
- players[3] = enemies[0];
- players[4] = enemies[1];
- cout << "Welcome to the Ancient Forest" << endl;
- cout << " 1: Fight in the arena" << endl;
- cout << " 2: Shop" << endl;
- cout << " 3: Equipment" << endl;
- cout << " 4: States" << endl;
- cin >> input;
- switch(input) {
- case 1:
- battle(players);
- break;
- case 2:
- cout << endl << "Equipment shop" << endl;
- cout << "1: Long Sword" << endl;
- cout << "2: Iron Sword" << endl;
- cout << "3: Genji Sword" << endl;
- cout << "4: Crystal Sword" << endl;
- cin >> input;
- if(input == 1) {
- if(gold-10 <= 0) {
- cout << "Not enough money" << endl;
- } else {
- for(int i = 0; i < 10; i++) {
- if(items[i].name == " ") {
- cout << "Purchased!" << endl;
- items[i] = shopitems[0];
- gold -= 10;
- break;
- }
- }
- }
- }
- if(input == 2) {
- if(gold-20 <= 0) {
- cout << "Not enough money" << endl;
- } else {
- for(int i = 0; i < 10; i++) {
- if(items[i].name == " ") {
- cout << "Purchased!" << endl;
- items[i] = shopitems[1];
- gold -= 20;
- break;
- }
- }
- }
- }
- if(input == 3) {
- if(gold-30 <= 0) {
- cout << "Not enough money" << endl;
- } else {
- for(int i = 0; i < 10; i++) {
- if(items[i].name == " ") {
- cout << "Purchased!" << endl;
- items[i] = shopitems[2];
- gold -= 30;
- break;
- }
- }
- }
- }
- if(input == 4) {
- if(gold-10 <= 0) {
- cout << "Not enough money" << endl;
- } else {
- for(int i = 0; i < 10; i++) {
- if(items[i].name == " ") {
- cout << "Purchased!" << endl;
- items[i] = shopitems[3];
- gold -= 10;
- break;
- }
- }
- }
- }
- break;
- case 3:
- cout << "Equipment manager" << endl;
- cout << " 1: Equip" << endl;
- cout << " 2: Remove equipment" << endl;
- cout << " 3: Back" << endl;
- cin >> input;
- if(input == 1) {
- cout << "Who do you want to equip? " << endl;
- for(int i = 0; i < 3; i++) {
- cout << i << ": " << players[i].name << endl;
- }
- cin >> input;
- cout << endl << "What do you want to equip?" << endl;
- for(int i = 0; i < 10; i++) {
- cout << i << ": " << items[i].name << endl;
- }
- cin >> target;
- players[input].equips = items[target];
- players[input].hpmax = players[input].equips.hpmax;
- players[input].agl = players[input].equips.agl;
- players[input].str = players[input].equips.str;
- items[target].name = " ";
- input = 0;
- }
- if(input == 2) {
- cout << "Whos equipment do you want to remove?" << endl;
- for(int i = 0; i < 3; i++) {
- cout << i << ": " << players[i].name << endl;
- }
- cin >> target;
- for(int i = 0; i < 10; i++) {
- if(items[i].name == " ") {
- items[i] = players[target].equips;
- break;
- }
- }
- players[target].equips.name = " ";
- players[target].str = 8;
- players[target].agl = 6;
- players[target].hp = 32;
- players[target].hpmax = 32;
- }
- break;
- case 4:
- cout << "Check status for what character?" << endl;
- for(int i = 0; i < 3; i++) {
- cout << i << ": " << players[i].name << endl;
- }
- cin >> target;
- cout << "Stats for " << players[target].name << endl;
- cout << "Hp " << players[target].hp << endl;
- cout << "HpMax " << players[target].hpmax << endl;
- cout << "Str " << players[target].str << endl;
- cout << "Agl " << players[target].agl << endl;
- cout << "Equipment " << players[target].equips.name << endl;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement