Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <stdlib.h>
- using namespace std;
- //GLOBAL VARIABLES
- struct inventory {
- string type;
- string name;
- bool equiped;
- };
- struct player {
- int hp;
- int hpmax;
- int agi;
- int str;
- string name;
- string abilities[3];
- bool dead;
- int ct;
- string ally;
- int dex;
- int magicattackmul;
- int attackmul;
- string job;
- int mp;
- int mpmax;
- int lvl;
- int exp;
- int expmax;
- int ap;
- inventory inv[10];
- int items;
- };
- int chance = rand() % 100;
- int ac = 0;
- int ec = 0;
- int etarget = rand() % 4;
- int eability = rand() % 1;
- int input;
- int target;
- int itemin;
- int gold;
- bool found = false;
- int itemfound;
- //THIS IS JUST FOR TESTING
- void setup_player(struct player *players) {
- for(int i = 0; i <= 4; i++) {
- players[i].dead = false;
- players[i].hpmax = players[i].hp;
- players[i].ct = 0;
- players[i].ally = "ally";
- }
- players[3].ally = "enemy";
- players[4].ally = "enemy";
- for(int i = 0; i <= 4; i++) {
- if(players[i].ally == "ally") {
- ac += 1;
- }
- if(players[i].ally == "enemy") {
- ec += 1;
- }
- }
- for(int i = 0; i <= 4; i++) {
- cout << players[i].ally << i << " Name: ";
- cin >> players[i].name;
- cout << i << " Agility";
- cin >> players[i].agi;
- cout << players[i].ally << i << " Strenght: ";
- cin >> players[i].str;
- cout << players[i].ally << i << " Hit Points: ";
- players[i].attackmul = 4;
- cin >> players[i].hp;
- players[i].hpmax = players[i].hp;
- players[i].abilities[0] = "Attack";
- players[i].dex = 77;
- players[0].abilities[1] = "Steal";
- players[1].abilities[1] = "Cura";
- players[2].abilities[1] = "Blaze";
- players[i].abilities[2] = "Item";
- players[i].inv[0].name = "Grenade";
- players[i].inv[1].name = "Grenade";
- players[i].inv[2].name = "Grenade";
- }
- for(int i = 3; i < 10; i++) {
- players[0].inv[i].name = " ";
- players[1].inv[i].name = " ";
- players[2].inv[i].name = " ";
- }
- for(int i = 0; i < 10; i++) {
- players[i].items = 3;
- }
- for(int i = 0; i <= 4; i++) {
- players[i].mp = 999;
- players[i].mpmax = 999;
- }
- for(int i = 3; i <= 4; i++) {
- players[i].abilities[1] = "Blaze";
- }
- }
- //ABILITY LIST; all the abilities are utterly useless due to attackmul.
- void checkabi(struct player *players, int i, int target, int input) {
- if(players[target].hp+players[i].str <= players[target].hpmax) {
- if(players[i].abilities[input] == "Attack") {
- if(chance <= players[i].dex) {
- cout << "Critical Hit!";
- cout << players[i].name << " attacks " << players[target].name << " with " << players[i].str*players[i].attackmul*2 << " dmg" << endl;
- players[target].hp += players[i].str*players[i].attackmul*2;
- srand(150);
- chance = rand() % 100;
- } else {
- cout << players[i].name << " attacks " << players[target].name << " with " << players[i].str*players[i].attackmul << " dmg" << endl;
- players[target].hp += players[i].str*players[i].attackmul;
- }
- }
- if(players[i].mp <= 0) {
- cout << "Out of MP";
- } else {
- if(players[i].abilities[input] == "Cure") {
- cout << players[i].name << " heals " << " with " << "500"<< " restored hp " << endl;
- players[target].hp += 500;
- }
- if(players[i].abilities[input] == "Blaze") {
- cout << players[i].name << " Casts Blaze" << " with " << players[i].str*2 << " dmg" << endl;
- players[target].hp += players[i].str*2*players[i].attackmul;
- players[i].mp -= 4;
- }
- if(players[i].abilities[input] == "Cura") {
- cout << players[i].name << " Heals " << " with " << "1000" << " restored hp" << endl;
- players[target].hp += 1000;
- }
- if(players[i].abilities[input] == "Blaza") {
- cout << players[i].name << " Casts Blaze " << " with " << players[i].str << " hp" << endl;
- players[target].hp += players[i].str*3*players[i].attackmul;
- players[i].mp -= 8;
- }
- }
- if(players[i].abilities[input] == "Steal") {
- for(int v = 0; v < 10; v++) {
- if(players[target].inv[v].name != " ") {
- found = true;
- itemfound = v;
- break;
- }
- }
- cout << "Stole " << players[target].inv[itemfound].name << "!\n";
- players[i].inv[players[i].items].name = players[target].inv[itemfound].name;
- players[i].items++;
- }
- if(players[i].abilities[input] == "Item") {
- for(int v = 0; v < 10; v++) {
- cout << v << " " << players[i].inv[v].name << endl;
- }
- cin >> itemin;
- if(players[i].inv[itemin].name == "Potion") {
- cout << players[i].name << " Throws a Potion\n";
- players[target].hp += 100;
- }
- if(players[i].inv[itemin].name == "HiPotion") {
- cout << players[i].name << " Throws a HiPotion\n";
- players[target].hp += 500;
- }
- if(players[i].inv[itemin].name == "XPotion") {
- cout << players[i].name << " Throws a XPotion\n";
- players[target].hp = players[target].hpmax;
- }
- if(players[i].inv[itemin].name == "Grenade") {
- cout << players[i].name << " Throws a grenade\n";
- players[target].hp += -300;
- }
- if(players[i].inv[itemin].name == " ") {
- cout << "Empty slot!";
- }
- players[i].inv[itemin].name = " ";
- players[i].items--;
- }
- players[i].ct = 0;
- } else {
- players[i].ct = 0;
- players[target].hp = players[target].hpmax;
- }
- }
- //BATTLE FUNCTION
- void battle(struct player *players) {
- while(true) {
- for(int i = 0; i <= 4; i++) {
- if(players[i].hp <= 0 && players[i].ally == "ally" && !players[i].dead) {
- players[i].dead = true;
- ac -= 1;
- break;
- }
- if(players[i].hp <= 0 && players[i].ally == "enemy" && !players[i].dead) {
- ec -= 1;
- players[i].dead = true;
- break;
- }
- if(ac <= 0) {
- cout << "\nLost\n";
- cin.get();
- cin.get();
- exit(0);
- }
- if(ec <= 0) {
- cout << "\nwon\n";
- cin.get();
- cin.get();
- exit(0);
- }
- }
- for(int i = 0; i <= 4; i++) {
- if(players[i].ct >= 100) {
- if(players[i].ally == "ally") {
- cout << players[i].name << endl;
- for(int c = 0; c <= 2; c++) {
- cout << c << " - " << players[i].abilities[c] << endl;
- }
- cin >> input;
- cout << "Who do you want to target?\n";
- for(int j = 0; j <= 4; j++) {
- cout << j << " - " << players[j].name << " Hp: " << players[j].hp << endl;
- }
- cin >> target;
- if(players[target].dead) {
- cout << "\nAlready dead\n";
- players[i].ct = 0;
- break;
- }
- checkabi(players, i, target, input); break;
- }
- if(players[i].ally == "enemy") {
- while(true) {
- if(players[etarget].dead || players[etarget].ally == "enemy") {
- if(ac <= 0) break;
- etarget = rand() % 4;
- }
- if(!players[etarget].dead || players[etarget].ally == "ally") break;
- }
- checkabi(players, i, etarget, eability);
- players[i].ct = 0;
- etarget = rand() % 4;
- eability = rand() % 2;
- }
- }
- players[i].ct += players[i].agi;
- if(players[i].dead) players[i].ct = 0;
- }
- }
- }
- main() {
- //SIMPLY CHANGE VARIABLES TO CHANGE THE BATTLE SETTINGS :) However, you will need to change a LOT of variables for one player..
- player players[6];
- srand(time(0));
- setup_player(players);
- battle(players);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement