好吧,我正在創建這個文本冒險遊戲。爲了獨一無二,我決定增加一個影響系統,讓你對其他角色的反應可以影響他們對你的反應以及他們的戰鬥力。 我在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