#include<iostream.h>
#include<stdlib.h>
int quit;
int battleselection;
int canrun;
int turn;
int comprand;
class cplayer{
private:
int health, attckpwr, defpwr, speed;
public:
int gethealth(){
return(health);
}
int getattckpwr(){
return(attckpwr);
}
int getdefpwr(){
return(defpwr);
}
int getspeed(){
return(speed);
}
createplayer(int h, int a, int d, int s){
health=h;
attckpwr=a;
defpwr=d;
speed=s;
}
attack();//to be set at bottom
defend();//to be set at bottom
item();//to be set at bottom
run();//to be set at bottom
int newhealth;
setnewhealth(){
health=newhealth;
}
}player;
class cenemy{
private:
int health, attckpwr, defpwr, speed;
public:
int gethealth(){
return(health);
}
int getattckpwr(){
return(attckpwr);
}
int getdefpwr(){
return(defpwr);
}
int getspeed(){
return(speed);
}
attack();//to be set at bottom
defend();//to be set at bottom
int newhealth;
setnewhealth(){
health=newhealth;
}
createnewenemy(int h, int a, int d, int s){
health=h;
attckpwr=a;
defpwr=d;
speed=s;
}
}enemy;
class cbattlemenu{
public:
display(){
cout<<"Player health:"<<player.gethealth()<<"\n";
cout<<"Enemy health:"<<enemy.gethealth()<<"\n";
cout<<"Press 1 to attack\n";
cout<<"Press 2 to defend\n";
cout<<"Press 3 to use an item\n";
cout<<"Press 4 to run\n";
cout<<"Press 5 to quit\n";
cout<<"Choice:";
cin>>battleselection;
if(battleselection==1){
player.attack();
}
if(battleselection==2){
player.defend();
}
if(battleselection==3){
}
if(battleselection==4){
player.getspeed();
enemy.getspeed();
if(player.getspeed()>enemy.getspeed()){
cout<<"Got away safely!\n";
}
if(player.getspeed()<=enemy.getspeed()){
cout<<"The enemy is too fast!\n";
}
}
if(battleselection==5){
quit=2;
}
turn = turn + 1;
if(turn==2||turn==4||turn==6||turn==8||turn==10||turn==12||turn==14||turn==16||turn==18||turn==20||turn==20){
comprand = rand () % 100;
if(comprand<=75){
enemy.attack();
if(player.gethealth()<=0){
cout<<"I''m sorry but you have been defeated!!!\n";
quit=2;
}
}
if(comprand>75){
enemy.defend();
}
}
}
}menu;
main(){
player.createplayer(100,20,20,20);
enemy.createnewenemy(100,20,20,20);
turn=1;
while(quit!=2){
menu.display();
}
return (0);
}
cplayer::attack(){
enemy.newhealth= enemy.gethealth()+(enemy.getdefpwr()/2) - getattckpwr();
enemy.setnewhealth();
if(enemy.gethealth()<=0){
cout<<"Congradulations you have won!!!\n";
quit=2;
}
}
cenemy::attack(){
player.newhealth = player.gethealth() + (player.getdefpwr()/2) - getattckpwr();
player.setnewhealth();
}
cplayer::defend(){
defpwr=defpwr*2;
}
cenemy::defend(){
defpwr=defpwr*2;
}
I need help with my code.
My code works but I can''t figure out how to make it so that when the player defends it cuts the enemy''s attckpwr in half for one turn only. Can some one please help?
Cory Fisher
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
under:
int quit;
int battleselection;
int canrun;
int turn;
int comprand;
put:
int enemyturn = 0;
----
in class cenemy
under:
int getspeed(){ return(speed); }
put:
void setattckpwr(int x) { attckpwr = x; }
----
in class cbattlemenu
under:
if(battleselection==5)
{
quit=2;
}
put:
if (enemyturn == turn)
{
enemy.setattckpwr(enemy.getattckpwr() * 2);
}
----
in cplayer::defend()
under:
defpwr=defpwr*2;
put:
enemyturn = turn + 2;
enemy.setattckpwr(enemy.getattckpwr() / 2);
int quit;
int battleselection;
int canrun;
int turn;
int comprand;
put:
int enemyturn = 0;
----
in class cenemy
under:
int getspeed(){ return(speed); }
put:
void setattckpwr(int x) { attckpwr = x; }
----
in class cbattlemenu
under:
if(battleselection==5)
{
quit=2;
}
put:
if (enemyturn == turn)
{
enemy.setattckpwr(enemy.getattckpwr() * 2);
}
----
in cplayer::defend()
under:
defpwr=defpwr*2;
put:
enemyturn = turn + 2;
enemy.setattckpwr(enemy.getattckpwr() / 2);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement