好吧,我正在创建这个文本冒险游戏。为了独一无二,我决定增加一个影响系统,让你对其他角色的反应可以影响他们对你的反应以及他们的战斗力。 我在C++方面拥有相当丰富的经验,并且刚刚开始了我的第二学期的C课程。到目前为止,我已经尝试过使用全局变量,结构体,静态变量以及其他函数内部的函数。我也试过使用指针,但每次都会收到错误,所以我停下来了。这是一个代码片段,尝试使用影响系统(很抱歉的明星,不想放弃任何故事情节):在C中,如何评估一个函数中的局部变量,在不同的函数中?
#include <stdlib.h>
#include <stdio.h>
static int positive_Influence; int negative_Influence; int overall_Influence;
void printpInI(int positive_Influence, int negative_Influence);//positive and negative influence
int choice_6()
{
int choice = 0;
int positive_Influence, negative_Influence, overall_Influence;
positive_Influence = 0;
negative_Influence = 0;
overall_Influence = 0;
printf("What do you do?\n");
printf("\t1. You: ****\n");
printf("\t2. You: ****\n");
printf("\t3. You: ****\n");
do
{
scanf_s("%i", &choice);
switch (choice)
{
case 1:
{
printf("\t****?\n");
system("pause");
negative_Influence += 10;
printf("You lose influence and are now at %i with ****.\n", positive_Influence-negative_Influence);
break;
}
case 2:
{
printf("\t****");
system("pause");
positive_Influence += 10;
printf("You gain influence and are now at %i influence with ****.\n", positive_Influence-negative_Influence);
break;
}
case 3:
{
printf("**** smiles at this.\n");
system("pause");
positive_Influence += 10;
printf("You gain influence and are now at %i influence with ****.\n", positive_Influence-negative_Influence);
break;
}
}
}while(choice != 1 && choice != 2 && choice != 3);
overall_Influence = positive_Influence-negative_Influence;
printf("%i\n", overall_Influence);
}
void story_7()
{
printf("Your overall influence is %i\n", overall_Influence);
}
int main()
{
choice_6();
story_7();
system("pause");
}
你实际上没有说明你的问题。我的意思是根据你的代码说你遇到的实际问题是什么。 – Brandin