嘿,在我的基于文本的冒险游戏中。我有这堂课:
class wolves
{
public:
string name;
int health;
private:
string attack;
//wolves(string name,int health); // Constructor
//hitPoints() +1;
};
我有一种随机计算生命值的方法。我不知道如何使用类创建函数。或者如何在类中使用 hitpoints 函数。
任何人都可以帮忙吗?
hitpoints()
int hitPoints()
{
srand(time(0)); // seed random number generator based on current time
int randomNumber= rand(); // generate random number
int hitPoints = (randomNumber% 20) + 1; // get a number between 1 and 20
return hitPoints;
}
int fatigue()
{
srand(time(0)); // seed random number generator based on current time
int randomNumber= rand(); // generate random number
int fatigue = (randomNumber% 5) + 1; // get a number between 1 and 5
return fatigue;
}
int Encounter()
{
srand(time(0)); // seed random number generator based on current time
int randomNumber= rand(); // generate random number
int encounter = (randomNumber% 3); // get a number between 1 and 5
cin >> encounter;
switch(encounter)
{
case 1:
Wolves();
menu = false;
break;
case 2:
Soldier();
break;
case 3:
CaveBear();
break;
}
cout << encounter;
return encounter;
}