I am getting an error while compiling this program . This is a simple game made in c++.
Game-content---- the player(user) will attack and reduce power of the enemy and in turn the enemy will attack automatically and reduce power of player. I am not understanding what that error means.It would be generous of you if you answer to this question.
HERE IS THE CODE
main.cpp
#include <iostream>
#include "Player.h"
using namespace std;
int getattack(int choice);
int enemypts = 200;
int playerpts = 200;
Player playerObj;
int main()
{
int attack;
attack = getattack(attack);
while(attack !=4){
switch(attack){
case 1:playerObj.PlayerAttack(enemypts,playerpts);break;
case 2:playerObj.PlayerAttack(enemypts,playerpts);break;
case 3:playerObj.PlayerAttack(enemypts,playerpts);break;
default :cout<<" what was that ? do it again..... "<<endl;
getattack(attack);break;
}
cout<<" YOUR TURN -"<<endl;
cin>>attack;
}
return 0;
}
int getattack(int choice){ //get attack
cout<<" 1 for hammer\n";
cout<<" 2 for AK-47\n";
cout<<" 3 for Space-12\n";
cout<<" 4 to quit\n\n";
cout<<" YOUR TURN "<<endl;
cin>>choice;
return choice;
}
enemy.cpp
#include "enemy.h"
#include "Player.h"
#include "enemy.h"
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
enemy::enemy()
{
}
void enemy::enemyAttack(int p){
int r;
cout<<" ENEMY'S TURN "<<endl;
srand(time(0));
r = rand()%100;
p = p - r;
cout<<" Now its enemy's turn to attack"<<endl;
cout<<" The attack was of power "<<r<<endl;
cout<<" Player - remaining power "<<p<<endl;
}
player.cpp
#include "Player.h"
#include "enemy.h"
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
enemy enemyObj;
Player::Player()
{
}
void PlayerAttack(int enpts,int plypts){
int r;
srand(time(0));
r = rand()%100;
enpts = enpts - r;
cout<<" Your attack was of power - "<<r<<endl;
cout<<" Enemy- remaining power : "<<enpts;
enemyObj.enemyAttack(plypts);
}
just for sake of rechecking below.. enemy.h
#ifndef ENEMY_H
#define ENEMY_H
class enemy
{
public:
enemy();
void enemyAttack(int p);
private:
int p;
};
#endif // ENEMY_H
player.h
#ifndef PLAYER_H
#define PLAYER_H
class Player
{
public:
Player();
void PlayerAttack(int enpts,int plypts);
private:
int enpts,plypts;
};
#endif // PLAYER_H
Aucun commentaire:
Enregistrer un commentaire