我看了很久了。。问题在哪
//在源文件class Monster
{
private:
int exp2,hp2,money2,damage2,rank2; //钱(money),//生命值(hp)//攻击力(damage),经验
public:
void setX();
int initial(); //实力
void attack(); //战斗
int win(); //胜利
void attacked(Ultraman *pUlt); //
//void fightback(Ultraman *pUlt); //反击
int display(); //查看双方实力
int gethp();
int getmoney();
int getrank();
int getexp();
int getdamage();
};
class Ultraman
{
private:
int rank,exp,hp,money,damage; //等级(rank),钱(money),
//生命值(hp)
//攻击力(damage),经验(exp),对方的实力(display)
public:
int initial();
int attracked(Monster *pmo);
int attack(Monster *pmo);
int isalive(); //活着
int restore(); //补血
int upgrade(); //升级
int win( ); //胜利
int escape(); //逃跑
int display(); //查看双方实力
int gethp();
int getmoney();
int getrank();
int getexp();
int getdamage();
int attacked(); //受到攻击
};
//在头文件
#include<iostream>
using namespace std;
#include<stdlib.h>
#include<time.h>
#include "attack.h"
int Ultraman::initial() //实力
{
rank=1;
exp=0;
hp=10;
money=0;
damage=10;
return 1;
}
int Ultraman::display()
{
initial();
cout<<"奥特曼等级,经验,血量,钱量,攻击力:"<<rank<<" "<<exp<<" "<<hp<<" "<<money<<" "<<damage
<<endl;
return 1;
}
int Ultraman::escape()
{
cout<<"奥特曼逃跑啦"<<endl;
hp--;
return hp;
}
int Ultraman::attack(Monster *pmo)
{
if(pmo->getmoney()%2!=0)
money++;
exp++;
return 1;
}
int Ultraman::attacked(Monster *pmo)
{
hp=hp-pmo->getdamage()/2;
return 1;
}
int Ultraman::win(Monster *pmo)
{
{if(pmo->getmoney()!=0)
money=money+pmo->getmoney();
}
exp=exp+pmo->getexp();
}
int Ultraman::restore()
{
if(money>=10||hp==rank*10)
{
hp++;
money=money-10;
}
else
cout<<"不能补血,奥特曼失败";
}
int Ultraman::upgrade()
{
rank++;
exp=exp-10*rank;
hp=10*rank;
}
int Ultraman::gethp()
{
return hp;
}
int Ultraman::getrank()
{
return rank;
}
void Monster::setX()
{
srand(time(NULL));
rank2=rand()%10+1;
hp2=(rand()%rank2+1)*5;
exp2=rand()%rank2+1;
damage2=rand()%rank2+1;
money2=rand()%rank2+1;
}
int Monster::display()
{
setX();
cout<<"怪兽等级,经验,血量,钱量,攻击力:"<<rank2<<" "<<exp2<<" "<<hp2<<" "<<money2<<" "<<damage2<<endl;
return 1;
}
void Monster::attacked(Ultraman *pUlt)//被攻击 { hp2=hp2-pUlt->getdamage(); if(getmoney()%2==0) ; else { money2=money2-1; } }
int Monster::getrank()
{
return rank2;
}
int Monster::getdamage()
{
return damage2;
}
int Monster::getexp()
{
return exp2;
}
int Monster::gethp()
{
return hp2;
}
int Monster::getmoney()
{
return money2;
}
void main()
{
Ultraman ul;
Monster mo;
Monster *p=&mo;
Ultraman *q=&ul;
ul.display();
mo.display();
do
{
ul.attack(p);
mo.attacked(q);
ul.attacked();
}
while(ul.gethp()!=0||mo.gethp()!=0);
cout<<"胜负已出";
if(ul.gethp()==0)
{
cout<<"奥特曼失败";
ul.restore();
}
else
{
cout<<"奥特曼胜利";
ul.upgrade();
}
}
3 IntelliSense: 声明与 "void Monster::attacked(<error-type> *pUlt)" (已声明 所在行数: 10,所属文件: "d:\文件位\奥特曼打怪兽\奥特曼打怪兽\attack.h") 不兼容 d:\文件位\奥特曼打怪兽\奥特曼打怪兽\attack.cpp 88 15 奥特曼打怪兽
2 IntelliSense: 声明与 "int Ultraman::win()" (已声明 所在行数: 35,所属文件: "d:\文件位\奥特曼打怪兽\奥特曼打怪兽\attack.h") 不兼容 d:\文件位\奥特曼打怪兽\奥特曼打怪兽\attack.cpp 42 15 奥特曼打怪兽
1 IntelliSense: 声明与 "int Ultraman::attacked()" (已声明 所在行数: 43,所属文件: "d:\文件位\奥特曼打怪兽\奥特曼打怪兽\attack.h") 不兼容 d:\文件位\奥特曼打怪兽\奥特曼打怪兽\attack.cpp 37 15 奥特曼打怪兽
问题显示啊啊啊。。
[ 本帖最后由 bieniy 于 2012-4-7 08:53 编辑 ]