#include <stdio.h>#include <iostream>#include <fstream>#include <string>#include <cstdlib>#include <cmath>using namespace std;//Declare global variablesint health = 100; //Player healthint enemyh = 100; //Enemy healthint weapon; //Current weaponint ch1 = 1; //weapon choice 1int ch2 = 2; //weapon choice 2int ch3 = 3; //weapon choice 3int heal; //heal the characterint choice; //turn choiceint att = 1; //Player attacksint hel = 2; //healint weaponAttack = 0; //Bonus from weaponint healBonus = 0; //Bonus from weaponint enemeyAttack = 0; //Bonus from weapon(enemey)bool loop = true;//Prototypesint attackPoints();int healPoints();//Player battle scriptvoid playerBattle() { cout<<"It is your turn. what do you do?(1 to attack and 2 to heal)"<< endl; cin>> choice; if (choice == att) { cout << "You have attacked him!" << endl; enemyh -= attackPoints() + weaponAttack; if(enemyh <= 0) { cout << endl << "You have slain your enimies!" << endl; loop=false;} cout << "He now has " << enemyh << " health left" << endl; }else if (choice == hel){ cout << "You have healed your-self!" << endl; health += healPoints() + healBonus; cout <<"You now have "<< health<<" health left"<< endl; }}//Enemey battle scriptvoid enemeyBattle() { cout << "It is his turn to attack! He has struck you with his mighty weapon!" << endl; health -= attackPoints() + enemeyAttack; if( health <= 0) { cout << endl << "You have been defeated!" << endl; loop=false;} cout<<" You now have only "<< health<< " health left!" << endl;}//Random attack numberint attackPoints(){ return int(8.0 * rand()/(RAND_MAX+1.0)); }//Random heal amountint healPoints(){ return int(15.0 * rand()/(RAND_MAX+1.0));}int main(int argc, char *argv[]){ cout << "Armor core arenas" << endl; cout << endl; cout << "Welcome to armor core arenas! The game where you fight against your"<< endl; cout << "opponent in an arena with a weapon of your choice."<< endl; cout << endl; cout << endl; cout << endl; cout << "Please choose your weapon"<< endl; cout << "1. axe(+2 to attack, +5 to heal)"<< endl; cout << "2. sword(+4 to attack, +0 to heal)"<< endl; cout << "3. staff(magic)(+0 to attack, +15 to heal)"<< endl; cin >> weapon; if (weapon == ch1) { weaponAttack = 2; healBonus = 5; enemeyAttack = 2; cout << "You have chosen the axe. The battle will now comence!"<< endl; cout << "your opponet will be the crusher. he is a large opponet who also weilds an axe"<< endl; cout << endl; } else if(weapon == ch2){ weaponAttack = 4; healBonus = 0; enemeyAttack = 0; cout << "You have chosen the sword. a mighty weapon that can quickly slice through opponets. The battle will now commence!"<< endl; cout << "Your opponet will be the hunter. A swift enemy who uses his bow and arrow to a great advantage"<< endl; cout << endl; } else if(weapon == ch3){ weaponAttack = 0; healBonus = 15; enemeyAttack = 2; cout << "You have chosen the magic staff. a mystical item that has extrodinary powers. The battle will now commence!"<< endl; cout << "Your opponet is the wizard ar naria. a powerful wizard with unknown powers."<< endl; cout << endl; } else { cout << "You have selected an invalid item" <<endl; } while(loop) { if(health > 0) playerBattle(); if(enemyh > 0) enemeyBattle(); } return 0;}
it is a bit more organized and less repeted code. I threw in some random number for attacks and used your base number to get the weapon and heal bonus. Nothing perfect, but at least a start in the right direction.
dimebag