所以我正在做一个文字冒险游戏。它有数百条故事线,一个功能齐全的战斗系统,我现在正在尝试创建一个影响系统。基本上应该按以下方式工作:某些响应/动作将增加或减小您对不同角色的影响。我想在choice_6()和story_7()中使用影响变量。我怎么做?请不要给我发送任何链接。我经历了许多其他答案,它们对我来说没有任何意义,因此,如果您要复制和粘贴,请至少与其他答案以不同的方式进行解释。谢谢。
int choice_6()
{
int influence = 0;
int choice = 0;
printf("What do you do?\n");
printf("\t1. You: No. I know absolutely nothing about you. You could be a monster\n");
printf("\ttoo for all I know! Normal people don't turn into frogs!\n");
printf("\t2. You: Your right we should keep moving. You can tell me when your\n");
printf("\tready.\n");
printf("\t3. You: Okay where do you think should we go then?\n");
do
{
scanf_s("%i", &choice);
switch (choice)
{
case 1:
{
printf("\tBrie flashes a pained look on her face and you immediately regret saying that.\n");
printf("\tBrie: You really think I'm a monster?\n");
system("pause");
influence -= 10;
printf("You lose influence and are now at %i with Brie.\n", influence);
system("pause");
printf("Influence affects characters reactions towards you, their combat effectiveness, and even their allegiances in rare cases.\n");
printf("However, depending on the situation, low influence is not always a bad thing...\n");
system("pause");
printf("\tYou: Your right we should keep moving.\n");
break;
}
case 2:
{
printf("\tBrie: Thank you. I'd rather not discuss this my life story in a dark\n");
printf("\tdungeon.\n");
system("pause");
influence += 10;
printf("You gain influence and are now at %i influence with Brie.\n", influence);
system("pause");
printf("Influence affects characters reactions towards you, their combat effectiveness, and even their allegiances in rare cases.\n");
printf("However, depending on the situation, low influence is not always a bad thing...\n");
system("pause");
printf("\tYou: I'd have to agree with you there. Let's see what is up these stairs.\n");
choice = 2;
break;
}
case 3:
{
printf("Brie smiles at this.\n");
printf("\tBrie: Well the only way out seems to be these stairs so let's go up.\n");
system("pause");
influence += 10;
printf("You gain influence and are now at %i influence with Brie.\n", influence);
system("pause");
printf("Influence affects characters reactions towards you, their effectiveness in combat, and even their allegiances in rare cases.\n");
printf("However, depending on the situation, low influence is not always a bad thing...\n");
system("pause");
printf("\tYou: Sounds good to me I am quite frankly done with dungeons about now.\n");
break;
}
default:
{
printf("Type the number for the choice you want to do\n");
system("pause");
break;
}
}
}while(choice != 1 && choice != 2 && choice != 3);
}
int story_7()
{
printf("\ninfluence is %i\n", influence);
printf("You lead the way walking upstairs\n");
system("pause");
printf("You turn the corner while crouched to find a room full of gremlins and goblins.\n");
system("pause");
printf("You grab Brie's hand and roll to the left behind some crates before they see you.\n");
system("pause");
printf("Even though you realize you will probably not make it out of this situation\n");
printf("alive, you can't help but feel lucky with Brie being so tightly pressed against you on the floor.\n");
system("pause");
printf("After a long period of silence to confirm nobody has seen you both enter,\n");
printf("Brie looks up at you and rolls her eyes.\n");
system("pause");
printf("*whispers*\tBrie: At least buy me dinner first jeez.\n");
system("pause");
printf("*whispers*\tYou: I'd love to but we should probably kill these uglies first.\n");
system("pause");
if (influence > 0)
{
printf("Brie laughs at this and slowly leans you off her to have both of you crouch.");
system("pause");
}
else
{
printf("Brie: Ugh just get off of me!\n");
printf("Brie pushes you off her violently and you manage to stay crouched.");
system("pause");
}
}
int main()
{
int play = 0;
int influence = 0;
intro_1();
story_1();
choice_1();
story_2();
choice_2();
story_3();
choice_3();
story_4();
choice_4();
story_5();
choice_5();
intro_2();
combat_1();
story_6();
choice_6();
story_7();
choice_7();
system("pause");
}
如果要在函数中进行修改,可以将指针传递给influence
变量。像这样:
int choice_6(int *influence)
{
// ...
*influence -= 10;
// use *influence wherever you would have had used influence before
// ...
}
int story_7(int influence)
{
// ...
if (influence > 0) ...
// ...
}
int main()
{
int influence = 0;
// ...
choice_6(&influence);
story_7(influence);
// ...
}
这传递了一个指针,choice_6()
因为您需要influence
在该函数中进行修改。这是将值传递给的,story_7()
因为您不需要在influence
那里修改值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句