I'm writing my first game.the game is in c++, its a text based fighting game like "Rpg" in the game section of the source code page of this site. at first the enemy was attacking himself but now he is not attacking at all and when he starts the program is not executing properly. the whole code can be found at C++ code by eltonbang - 114 lines - codepad but i will of course post the area i believe to be the problem area. any help would be greatly appreciated. thanks
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int Lvl1();
int Lvl2();
int Lvl3();
int Lvl4();
int Lvl5();
int Lvl6();
int Lvl7();
int Lvl8();
int Lvl9();
int lvl10();
int main();
int choice;
int ENhp,PLhp,ENagi,PLagi,I,PLdef,ENdef,ENatk,PLatk,init,PLdamage,ENdamage; // EN = Enemy,PL = player
////////////////////////////////main/////////////////////////////////////////////////////////////
int main(){
{srand((unsigned)time(0));}
cout <<"Back Ally Brawls by John Billingsley\n";
do {Lvl1();} while (ENhp>0||PLhp>0);
return 0;}
///////////////////LVL_1/////////////////////////////////////////////////////////
int Lvl1(){
PLatk = 20 + rand() % 10;/////////////////////////////////////////////////////////////////
PLdef = 20 + rand() % 10;
PLagi = 20 + rand() % 10;
PLhp = 200; // player values before attack bonus
init = rand() % 2+1;
ENatk = 15 + rand() % 10;
ENdef = 15 + rand() % 10;
ENagi = 15 + rand() % 10;
ENhp = 150;
srand((unsigned)time(0));
////////////////////////////////////////////////////////////////////////////////////
if (init==1){ cout << "You start.\n";
cout << "you'r first fight will be against a deranged crack head\n";
while (ENhp > 0 && PLhp > 0) {
cout << "What do you want to do?\n1 - punch\n2 - kick\n3 - Block\n";
do{cin>>choice;}while(choice>3 || choice<1);
switch (choice){case 1:
PLatk == 20+rand()% 6;
PLdef == 20 ;
PLagi == 20+rand()% 11;
break;
case 2: ///attacks and attack bonuses
PLatk == 20+rand()% 11;
PLdef == 20;
PLagi == 20+rand()% 6;
break;
case 3:
PLatk == 0 ;
PLdef == 20+rand()% 11;
PLagi == 20+rand()% 16;
break;
}
///////////////////////////////////////////////////////////////////////////
ENdamage=(PLatk+PLagi)-(ENdef+ENagi);
if (ENdamage<1) {ENdamage=0;} ////dealing damage, this may be a problem area
ENhp=(ENhp-ENdamage);
cout<<"The enemy has:"<<ENhp<<" health remaining\n";
cin.get();
if (ENhp<1){cout<<"One crackhead down, 9 fierce fighters to go!\n";
return 0;}
PLdamage=(ENatk+ENagi)-(PLdef+PLagi);
if(PLdamage<1){PLdamage=0;}
PLhp=(PLhp-PLdamage);
cout<<"You have:"<<PLhp<<" health remaining\n";
cin.get();
if (PLhp<1){cout<<"YOU GOT KNOCKED THE ........ OUT\n";
return 0;}}}
/////////////////////////////////////////////////////////////////////////////
else {
cout<<"your first fight will be against a deranged crack head.\n";
cout<<"Crack Head will start.\n";
while (PLhp > 0 && ENhp > 0){
choice = rand()% 3; /////the enemy was attacking himself
switch (choice) {
case 1: //// now he is not attacking
ENatk == 15+rand()% 6;
ENdef == 15 ;
ENagi == 15+rand()% 6;
break;
case 2:
ENatk == 15+rand()% 11;
ENdef == 15;
ENagi == 15+rand()% 6;
break;
case 3:
ENatk == 0;
ENdef == 15+rand()% 11;
ENagi == 15+rand()% 6;
break;
}}}
ENdamage=(PLatk+PLagi)-(ENdef+ENagi);
if (ENdamage<1) {ENdamage=0;}
ENhp=(ENhp-ENdamage);
cout<<"The enemy has:"<<ENhp<<" health remaining\n";
cin.get();
if (ENhp<1){cout<<"One crackhead down, 9 fierce fighters to go!\n";
return 0;}
PLdamage=(ENatk+ENagi)-(PLdef+PLagi);
if(PLdamage<1){PLdamage=0;}
PLhp=(PLhp-PLdamage);
cout<<"You have:"<<PLhp<<" health remaining\n";
cin.get();
if (PLhp<1){cout<<"YOU GOT KNOCKED THE ........ OUT\n";
return 0;}
}