qq_33031101 2016-04-24 11:55 采纳率: 0%
浏览 2991

新手求助,C++的头文件引用问题

为什么#include "container.h"报错说打不开source file啊,我完全不知道怎么回事,啊啊啊啊啊,求帮助

#ifndef _CONTAINER

#define _CONTAINER
#include
using namespace std;
class container
{
protected:
int numOfHeal;
int numOfMW;
public:
container();
void set(int heal_n, int mw_n);
int nOfHeal();
int nOfMW();
void display();
bool useHeal();
bool useMW();
};
container::container()
{
set(0, 0);
};

void container::set(int heal_n, int mw_n)
{
    numOfHeal = heal_n;
    numOfMW = mw_n;
};


int container::nOfHeal()
{
    return numOfHeal;
};


int container::nOfMW()
{
    return numOfMW;
};


void container::display()
{
    cout << "Your bag contains: " << endl;
    cout << "Heal(HP+100): " << numOfHeal << endl;
    cout << "Magic Water (MP+80): " << numOfMW << endl;
};


bool container::useHeal()
{
    numOfHeal--;
        return 1;       
};

//use magic water
bool container::useMW()
{
    numOfMW--;
    return 1;
};

#endif

#ifndef _PLAYER
#define _PLAYER

#include

#include

#include "container.h"
#include
using namespace std;
enum job { sw, ar, mg };

class player
{
friend void showinfo(player &p1, player &p2);
friend class swordsman;

protected:
int HP, HPmax, MP, MPmax, AP, DP, speed, EXP, LV;

string name;    
job role;       
container bag;  

public:
virtual bool attack(player &p) = 0;
virtual bool specialatt(player &p) = 0;
virtual void isLevelUp() = 0;

void reFill();      
bool death();       
void isDead();      
bool useHeal();     
bool useMW();       
void transfer(player &p);   
void showRole();    

private:
bool playerdeath;

};
void player::reFill()
{
HP = HPmax;

MP = MPmax;
}

bool player::death()
{
return playerdeath;
};

void player::isDead()
{
if (HP <= 0)

cout << name << " is Dead." << endl;
system("pause");
playerdeath = 1;

}
};

bool player::useHeal()
{
if (bag.nOfHeal()>0)
{
HP = HP + 100;
if (HP>HPmax)

HP = HPmax;

cout << name << " used Heal, HP increased by 100." << endl;
bag.useHeal();

system("pause");
return 1;

}
else

{
cout << "Sorry, you don't have heal to use." << endl;
system("pause");
return 0;

}
};

bool player::useMW()
{
if (bag.nOfMW()>0)
{
MP = MP + 100;
if (MP>MPmax)
MP = MPmax;
cout << name << " used Magic Water, MP increased by 100." << endl;
bag.useMW();
system("pause");
return 1;

}
else
{
cout << "Sorry, you don't have magic water to use." << endl;
system("pause");
return 0;
}
}

// possess opponent's items after victory
void player::transfer(player &p)
{
cout << name << " got" << p.bag.nOfHeal() << " Heal, and " << p.bag.nOfMW() << " Magic Water." << endl;
system("pause");
p.bag.set(p.bag.nOfHeal(), p.bag.nOfMW());
};
void player::showRole()
{
switch (role)
{
case sw:
cout << "Swordsman";
break;
case ar:
cout << "Archer";
break;
case mg:
cout << "Mage";
break;
default:
break;
}
};

// display character's job
void showRole()
{
system("cls");
cout << "##############################################################" << endl;
cout << "# Player" << setw(10) << p1.name << " LV. " << setw(3) << p1.LV
<< " # Opponent" << setw(10) << p2.name << " LV. " << setw(3) << p2.LV << " #" << endl;
cout << "# HP " << setw(3) << (p1.HP <= 999 ? p1.HP : 999) << '/' << setw(3) << (p1.HPmax <= 999 ? p1.HPmax : 999)
<< " | MP " << setw(3) << (p1.MP <= 999 ? p1.MP : 999) << '/' << setw(3) << (p1.MPmax <= 999 ? p1.MPmax : 999)
<< " # HP " << setw(3) << (p2.HP <= 999 ? p2.HP : 999) << '/' << setw(3) << (p2.HPmax <= 999 ? p2.HPmax : 999)
<< " | MP " << setw(3) << (p2.MP <= 999 ? p2.MP : 999) << '/' << setw(3) << (p2.MPmax <= 999 ? p2.MPmax : 999) << " #" << endl;
cout << "# AP " << setw(3) << (p1.AP <= 999 ? p1.AP : 999)
<< " | DP " << setw(3) << (p1.DP <= 999 ? p1.DP : 999)
<< " | speed " << setw(3) << (p1.speed <= 999 ? p1.speed : 999)
<< " # AP " << setw(3) << (p2.AP <= 999 ? p2.AP : 999)
<< " | DP " << setw(3) << (p2.DP <= 999 ? p2.DP : 999)
<< " | speed " << setw(3) << (p2.speed <= 999 ? p2.speed : 999) << " #" << endl;
cout << "# EXP" << setw(7) << p1.EXP << " Job: " << setw(7);
p1.showRole();
cout << " # EXP" << setw(7) << p2.EXP << " Job: " << setw(7);
p2.showRole();
cout << " #" << endl;
cout << "--------------------------------------------------------------" << endl;
p1.bag.display();
cout << "##############################################################" << endl;
};

#endif

  • 写回答

4条回答 默认 最新

  • oyljerry 2016-04-24 13:08
    关注

    这个头文件路径是否正确 你编译器能否直接打开

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!