교수님은 5 명의 검투 사 이름을 지정한 다음 통계를 만들고 보스 통계를 작성한 다음 검투 사가 보스와 싸울 수 있도록하기 위해 검투사 시뮬레이션을 작성하기를 원합니다. 싸우는 동안, 우승자가 결정될 때까지 모든 사람의 건강과 무작위로 생성 된 수의 피해가 표시되며, 거기에서 재 시합을 원한다면 사용자에게 알립니다.생성자/실험실 9 문제
현재 저는 무엇이 무엇인지, 그리고 어떻게 생성자를 사용하는지 알아 내야합니다. 전반적으로, 나는 프로젝트에서 모두 분실되었지만, 지금은이 단계별로 이해하고 싶다. BossFight.h 내부에는 프로토 타입 기능이 있습니다. 내가 지금까지했던 어떤
class BossFight {
private:
//Holds the party of gladiators that is banded together to fight the boss
Gladiator party[PSIZE];
//Holds the powerful boss that the party is fighting
Gladiator boss;
//Variables used for record keeping
int turnNum, fightsStarted, fightsWon;
//Will fill the party with gladiators, this function can call/reuse the createGladiator function.
void getParty();
//Will generate a boss for the party to fight. Has no crit or evasion, but 3* damage min and range, and 6* health
void getBoss();
//Tells the user who won, after how many turns, and the current record for the session
void displayFightResults(bool partyWon);
//One turn occurs, where each party member attacks the boss, then the boss attacks the party.
//Returned value indicates status of fight (continue, party win, party loss)
//Boss will randomly choose between attacking a single (randomly chosen) party member for full damage, or
//attacking the full party for half damage.
int takeTurn();
//Handles dealing damage to the entire party
void bossAttacksArea();
public:
//Responsible for generating the party and the boss, should initialize the other
//private variables as well
BossFight();
//User calls this when they want to run a fight. It will ask them if they want to use
//the same party, or get a new one.
void runFight();
};
는
#include <iostream>
#include <string>
#include "BossFight.h"
#include <stdlib.h>
#include <time.h> // Allows seed to generate new random numbers every time.
using namespace std;
const int SIZE = 5; //Party Size
Gladiator createGladiator(string name) // Data type Gladiator with its data named createGladiator
{
Gladiator stats; // Structure tag
for (int i = 0; i < SIZE; i++)
{
int maxHealth, evasion, critical;
stats.name = name;
// set max health
switch (rand() % 3) // % 3 means the range. So the starting number is 0 and final number is 2. Used to find a random number between the range 0-2.
// Uses that random number to open up one of the cases.
{
case 0: stats.maxHealth = 150;
break;
case 1: stats.maxHealth = 200;
break;
case 2: stats.maxHealth = 250;
break;
}
// set evasion
int numE = (rand() % 5); // Used to find a random number between the range 0-4.
switch (numE) // Uses that random number to open up one of the cases.
{
case 0: stats.evasion = 50;
break;
case 1: stats.evasion = 75;
break;
case 2: stats.evasion = 100;
break;
case 3: stats.evasion = 125;
break;
case 4: stats.evasion = 150;
break;
}
// Set Critical
int numC = (rand() % 5); // Used to find a random number between the range 0-4.
switch (numC) // // Uses that random number to open up one of the cases.
{
case 0: stats.critical = 50;
break;
case 1: stats.critical = 75;
break;
case 2: stats.critical = 100;
break;
case 3: stats.critical = 125;
break;
case 4: stats.critical = 150;
break;
}
// Set minDamage
int minimum, maximum;
minimum = 8;
maximum = 5;
int numMin = (minimum + rand() % (maximum + minimum)); // Used to find a random number between the minimum and maximum values.
stats.dmgMin = numMin;
// set DamageRange
int maxMin, maxMax;
maxMin = 16;
maxMax = 5;
int numMax = (maxMin + rand() % (maxMax - maxMin)); // Used to find a random number between the minimum and maximum values.
stats.dmgRange = numMax;
return stats; //Return all of the stats into the structure tag.
}
}
BossFight::BossFight() ***< -- stuck right here ***
{
getParty();
}
void BossFight::getBoss()
{
getBoss();
}
void getParty(string name[])
{
{
cout << "To begin with, enter 5 gladiator's name" << endl; // First for loop asking user for array input.
for (int i = 0; i < SIZE; i++)
{
cin >> name[i];
}
for (int i = 0; i < SIZE; i++)
{
cout << "Gladiator " << i + 1 << " name is " << endl;
cout << name[i] << endl;
}
}
}
int main()
{
srand(time(NULL)); //initiate random number generator seed.
string name[SIZE];
cout << "Hello user" << endl;
BossFight();
system("PAUSE");
}
내가 도움의 모든 유형을 이해할 것입니다. 컴퓨터 과학 수업에 대한 소개를하고 있다는 것을 기억하십시오. 그렇기 때문에 복잡한 코딩을 아직 이해하지 못할 수도 있습니다. 나는 코드가 영어로 어떻게 작동해야 하는지를 지금까지 잘 해왔지만 코드를 통해 어떻게해야하는지 해석하기가 어렵다. 또한
, 내가 오류를 얻고있다
심각도 코드 설명 프로젝트 파일 라인 억제 상태 오류 LNK2019 확인되지 않은 외부 기호 "개인 : 무효 __thiscall BossFight :: getParty (무효)"? (getParty @ BossFight @@ AAEXXZ) 에서 참조하는 함수 "public : __thiscall BossFight :: BossFight (void)" (0BossFight @@ QAE @ XZ) ConsoleApplication6 심각도 코드 설명 프로젝트 파일 줄 억제 상태 오류 LNK2019 해결되지 않은 외부 기호 "private : void __thiscall BossFight :: getParty (void) "(? getParty @ BossFight @@ A (공백) " (0BossFight @@ QAE @ XZ) ConsoleApplication6 C : \ Users \ 1 \ documents \ visual 스튜디오 2017 \ Projects \ ConsoleApplication6 \ ConsoleApplication6 \ 1에있는"public : __thiscall BossFight :: BossFight .obj 1
그리고이 문제가 무엇인지 궁금합니다. 내 비주얼 스튜디오에있는 것은 모두 내 머리글과 cpp 파일입니다.
굉장! 당신의 답변에 감사드립니다. 구현으로 무엇을 의미합니까? 나는 시도했다 void BossFight :: getParty() { getParty; } 아무 것도 발생하지 않았습니다. 나는 void 함수 안에서 void 함수를 호출하기 때문에 그것이라고 가정했다. –
안녕하세요 @ TonyDo : "구현"이란 함수 또는 메서드 ("클래스의 멤버 함수"라고도 함)가 호출 될 때 실행되는 코드를 의미합니다. 'BossFight.h' 헤더 파일에는 선언이 포함되어 있으며 CPP 파일에는 구현이 포함되어 있습니다. 구현 내에서 BossFight :: getParty()가 호출 될 때 실행해야하는 코드를 작성해야합니다. 모든 BossFight 메소드를 구현해야합니다 (구현 구현). –
다른 질문에 대해서는 void 함수 내에서 void 함수를 호출하는 것이 좋습니다. 하지만 당신은 아마 void BossFight :: getParty() {getParty(); } '이것은 무한 루프 나 스택 오버 플로우를 초래할 수 있기 때문이다. –