C++ 游戏出错,我很确定指针有问题。但我不知道
Having an error with C++ game, I'm pretty sure it's something wrong with the pointers. but i cant tell
我不知道你是如何解决这个问题的。它一直告诉我没有匹配的函数可以调用,并且一直说参数 1 没有从 'Npc**' 到 'Npc*
的已知转换
具体来说,是说 handleDialogueTwo(&nonplayer); 有问题;和 handleDialogueThree(&nonplayer);
我确定这是一个愚蠢的修复程序,但我已经挠头了好几个小时了。请帮忙
void Dungeon::handleRoomWithNpc(Room * room) {
Npc nonplayer = room->nonplayer.front();
cout << "Inside, you see a " << nonplayer.name << ".\n";
string actions[] = {
"a: Talk to " + nonplayer.name,
"b: Fight " + nonplayer.name,
"c: Leave",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueOne(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer.attack);
cout << nonplayer.name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else if (input == "c") {
player.changeRooms(player.previousRoom);
enterRoom(player.currentRoom);
return;
} else {
cout << "Wrongo, Bucko.\n";
}
}
}
void Dungeon::handleDialogueOne(Npc * nonplayer) {
cout << nonplayer->dialogueOne;
string actions[] = {
"a: continue",
"b: die",
"c: fight",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueTwo(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
}
} else if (input == "c") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else {
cout << "Wrongo, Bucko!\n";
}
}
}
void Dungeon::handleDialogueTwo(Npc * nonplayer) {
cout << nonplayer->dialogueTwo;
string actions[] = {
"a: continue",
"b: die",
"c: fight",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueThree(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
}
} else if (input == "c") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else {
cout << "Wrongo, Bucko!\n";
}
}
}
void Dungeon::handleDialogueThree(Npc * nonplayer) {
cout << nonplayer->dialogueThree;
string actions[] = {
"a: continue",
"b: die",
"c: win",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueTwo(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else if (input == "c") {
nonplayer->currentHealth = 0;
return;
} else {
cout << "Wrongo, Bucko!\n";
}
}
}
数据nonplayer
的类型是Npc *
,被调用者的参数类型也是Npc *
,所以在[=14=中不需要&
] 和 handleDialogueThree(&nonplayer);
。删除它们。
我不知道你是如何解决这个问题的。它一直告诉我没有匹配的函数可以调用,并且一直说参数 1 没有从 'Npc**' 到 'Npc*
的已知转换具体来说,是说 handleDialogueTwo(&nonplayer); 有问题;和 handleDialogueThree(&nonplayer);
我确定这是一个愚蠢的修复程序,但我已经挠头了好几个小时了。请帮忙
void Dungeon::handleRoomWithNpc(Room * room) {
Npc nonplayer = room->nonplayer.front();
cout << "Inside, you see a " << nonplayer.name << ".\n";
string actions[] = {
"a: Talk to " + nonplayer.name,
"b: Fight " + nonplayer.name,
"c: Leave",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueOne(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer.attack);
cout << nonplayer.name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else if (input == "c") {
player.changeRooms(player.previousRoom);
enterRoom(player.currentRoom);
return;
} else {
cout << "Wrongo, Bucko.\n";
}
}
}
void Dungeon::handleDialogueOne(Npc * nonplayer) {
cout << nonplayer->dialogueOne;
string actions[] = {
"a: continue",
"b: die",
"c: fight",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueTwo(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
}
} else if (input == "c") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else {
cout << "Wrongo, Bucko!\n";
}
}
}
void Dungeon::handleDialogueTwo(Npc * nonplayer) {
cout << nonplayer->dialogueTwo;
string actions[] = {
"a: continue",
"b: die",
"c: fight",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueThree(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
}
} else if (input == "c") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else {
cout << "Wrongo, Bucko!\n";
}
}
}
void Dungeon::handleDialogueThree(Npc * nonplayer) {
cout << nonplayer->dialogueThree;
string actions[] = {
"a: continue",
"b: die",
"c: win",
};
while(true) {
printActions(3, actions);
string input;
cin >> input;
if (input == "a") {
handleDialogueTwo(&nonplayer);
return;
} else if (input == "b") {
int damage = player.takeDamage(nonplayer->attack);
cout << nonplayer->name << " hits you for " << damage << " damage! \n";
if (player.checkIsDead()){
return;
};
} else if (input == "c") {
nonplayer->currentHealth = 0;
return;
} else {
cout << "Wrongo, Bucko!\n";
}
}
}
数据nonplayer
的类型是Npc *
,被调用者的参数类型也是Npc *
,所以在[=14=中不需要&
] 和 handleDialogueThree(&nonplayer);
。删除它们。