以下是我的MainCharacter和NPC的一些代码(我知道代码很草率)
当我尝试检查任务是否有效时 void CMainCharacter :: MissionSets(){
using namespace std;
if (npc->StoryLineMission = npc->NoMission)
{
if (npc->StoryLineMission = npc->LearningTheTruth) {
cout << "hello" << endl;
}
}
}
我定义了故事情节 StoryLineMission = NoMission;
这是所有的任务 CNCP :: UpdateQuest(){
if (QuestMission == NoQuest) {
if (csdl_setup->GetMainEvent()->type == SDL_KEYDOWN)
{
if (csdl_setup->GetMainEvent()->key.keysym.sym == SDLK_SPACE)
{
std::cout << "Quests have been activated" << std::endl;
QuestMission = Quest;
}
}
}
if (QuestMission == Quest) {
if (csdl_setup->GetMainEvent()->type == SDL_KEYDOWN)
{
if (csdl_setup->GetMainEvent()->key.keysym.sym == SDLK_q) {
QuestMission = QuestActive;
std::cout << "Quest/Mission has been delivered to you" << std::endl;
}
}
}
if (QuestMission == QuestActive)
{
if (StoryLineMission == NoMission) {
StoryLineMission = LearningTheTruth;
}
else if (StoryLineMission == LearningTheTruthCompleted) {
StoryLineMission = MeetingOldFriends;
}
else if (StoryLineMission == MeetingOldFriendsCompleted) {
StoryLineMission = HelpingFriends;
}
else if (StoryLineMission == HelpingFriendsCompleted) {
StoryLineMission = TheChasing;
}
else if (StoryLineMission == TheChasingCompleted) {
StoryLineMission = TheReturn;
}
}
if (StoryLineMission == LearningTheTruth)
{
LearningTheTruthArrowDown1->Draw();
LearningTheTruthArrowRight1->Draw();
if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN) {
if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT) {
LearningTheTruthPart1->Draw();
LearningTheTruthPart2->Draw();
LearningTheTruthPart3->Draw();
LearningTheTruthPart4->Draw();
}
}
if (csdl_setup->GetMainEvent()->type == SDL_KEYDOWN) {
if (csdl_setup->GetMainEvent()->key.keysym.sym == SDLK_c) {
QuestMission = LearningTheTruthQuestCompleted;
StoryLineMission = LearningTheTruthCompleted;
QuestType = LearningTheTruthQuestCompleted;
}
}
}
if (StoryLineMission == MeetingOldFriends) {
if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN) {
if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT) {
MeetingOldFriendsPart1->Draw();
MeetingOldFriendsPart2->Draw();
}
}
if (csdl_setup->GetMainEvent()->type == SDL_KEYDOWN) {
if (csdl_setup->GetMainEvent()->key.keysym.sym == SDLK_c) {
QuestMission = MeetingOldFriendsQuestCompleted;
StoryLineMission = MeetingOldFriendsCompleted;
QuestType = MeetingOldFriendsQuestCompleted;
}
}
}
if (StoryLineMission == HelpingFriends) {
if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN) {
if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT) {
}
}
if (csdl_setup->GetMainEvent()->type == SDL_KEYDOWN) {
if (csdl_setup->GetMainEvent()->key.keysym.sym == SDLK_c) {
QuestMission = HelpingFriendsQuestCompleted;
StoryLineMission = HelpingFriendsCompleted;
QuestType = HelpingFriendsQuestCompleted;
}
}
}
if (StoryLineMission == TheChasing) {
std::cout << "The Chasing" << std::endl;
if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN) {
if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT) {
}
}
if (csdl_setup->GetMainEvent()->type == SDL_KEYDOWN) {
if (csdl_setup->GetMainEvent()->key.keysym.sym == SDLK_c) {
QuestMission = TheChasingQuestCompleted;
StoryLineMission = TheChasingCompleted;
QuestType = TheChasingQuestCompleted;
}
}
}
if (StoryLineMission == TheReturn) {
std::cout << "Welcome Home" << std::endl;
if (csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN) {
if (csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT) {
}
}
if (csdl_setup->GetMainEvent()->type == SDL_KEYDOWN) {
if (csdl_setup->GetMainEvent()->key.keysym.sym == SDLK_c) {
QuestMission = TheReturnQuestCompleted;
StoryLineMission = TheReturnCompleted;
QuestType = TheReturnQuestCompleted;
}
}
}
if (QuestMission == LearningTheTruthQuestCompleted) {
std::cout << "LearningTheTruth has been succesfully completed" << std::endl;
StoryLineMission = LearningTheTruthCompleted;
QuestMission = Quest;
}
if (QuestMission == MeetingOldFriendsQuestCompleted) {
std::cout << "Meeting Old Friends has been succesfully completed" << std::endl;
StoryLineMission = MeetingOldFriendsCompleted;
QuestMission = Quest;
}
if (QuestMission == HelpingFriendsQuestCompleted) {
std::cout << "HelpingFriends quest has been succesfully completed" << std::endl;
StoryLineMission = HelpingFriendsCompleted;
QuestMission = Quest;
}
if (QuestMission == TheChasingQuestCompleted) {
std::cout << "The Chasing has been completed" << std::endl;
StoryLineMission = TheChasingCompleted;
QuestMission = Quest;
}
if (QuestMission == TheReturnQuestCompleted) {
std::cout << "The Return has been completed" << std::endl;
StoryLineMission = TheReturnCompleted;
QuestMission = QuestsDone;
}
if (QuestMission == QuestsDone) {
// AllQuestsDone->Draw();
}
if (QuestType == LearningTheTruthQuestCompleted) {
if (StoryLineMission == LearningTheTruthCompleted) {
SLearningTheTruthCompleted->Draw();
}
}
if (QuestType == MeetingOldFriendsQuestCompleted) {
if (StoryLineMission == MeetingOldFriendsCompleted) {
SMeetingOldFriendsCompleted->Draw();
}
}
if (QuestType == HelpingFriendsQuestCompleted) {
if (StoryLineMission == HelpingFriendsCompleted) {
SHelpingFriendsCompleted->Draw();
}
}
if (QuestType == TheChasingQuestCompleted) {
if (StoryLineMission == TheChasingCompleted) {
STheChasingCompleted->Draw();
}
}
if (QuestType == TheReturnQuestCompleted) {
if (StoryLineMission == TheReturnCompleted) {
STheReturnCompleted->Draw();
//AllQuestsDone->Draw();
}
}
}
每次我尝试运行它都会得到一个访问违规写入位置,我似乎无法让它工作。
我在不同的班级中调用任务集功能
void CMain :: GameLoop(void) {
while (!quit && csdl_setup->GetMainEvent()->type != SDL_QUIT)
{
csdl_setup->Begin();
//Tiles
Forest->DrawBack();
//NPC
OrcNPC->Draw();
OrcNPC->UpdateComputerNPC();
//Players
Josh->Draw();
Josh->Update();
Forest->DrawFront();
Forest->Update();
//Quests
OrcNPC->UpdateQuest();
OrcNPC->DeleteQuest();
OrcNPC->UpdateAnimation();
Josh->MissionSets();
csdl_setup->End();
}
}
答案 0 :(得分:0)
在 if 声明中,这只是一个错字吗?改变=到==
if (npc->StoryLineMission == npc->NoMission)
{
if (npc->StoryLineMission == npc->LearningTheTruth) {
cout << "hello" << endl;
}
}