0
嘿在我的基於文本的冒險遊戲。我有這個類:攻擊玩家的方法
class wolves
{
public:
string name;
int health;
private:
string attack;
//wolves(string name,int health); // Constructor
//hitPoints() +1;
};
我有一個隨機計數生命值的方法。我不知道如何使用類創建一個函數。或者如何在課堂上使用生命值功能。
任何人都可以幫忙嗎?
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;
}
目前還不清楚要問什麼。你又有什麼問題? – 0x499602D2
聽起來像你應該在OO C++上尋找一個很好的教程。 – chris
請注意時態隨機! –