【发布时间】:2020-06-27 14:41:14
【问题描述】:
所以,我得到了 2 个函数,它们基本上都在玩一个名为 "Pig Game" 的游戏,下面的代码是 int main() 在我的代码中,它只是打印主要内容,然后一一启动功能。另外,还有一个名为 roll_a_dice() 的函数你可以忽略它,它基本上是掷骰子。
例如,在第一个 while 循环中,play_computer 首先启动,然后是 play_user。循环重复 6 次。 而我需要的是在每一轮之后,我需要获取函数的结果(或输出,或返回),并将其放入另一个名为 scoresheets 的函数中()。我不知道该怎么做。请帮帮我。
int main(void){
int roll, comp, me, round=1;
srand(time(NULL));
printf("Welcome to Big Pig game.");
printf("\nLets get started!");
comp = roll_a_dice();
printf("\nI have rolled the dice and got %d!",comp);
printf("\nShall i roll the dice for you (Y/N)? ");
scanf("%c",&roll);
if (roll=='Y'){
me=roll_a_dice();
printf("I have rolled the dice for you and you got %d!",me);
if (comp>me){
while (round<=6){
printf("\nRound %d--My Turn: ",round);
printf("\n===================================================================================");
printf("%d",play_computer());
printf("\nRound %d--Your Turn: ",round);
printf("\n===================================================================================");
printf("%d",play_user());
round++;
}
}
else{
while (round<=6){
printf("\nRound %d--Your Turn: ",round);
printf("\n===================================================================================");
printf("%d",play_user());
printf("\nRound %d--My Turn: ",round);
printf("\n===================================================================================");
printf("%d",play_computer());
round++;
}
}
}
printf("%d",scoresheet());
return 0;
}
【问题讨论】:
-
请澄清大猪游戏规则
-
规则是:一开始,玩家和电脑随机掷骰子,点数大的先开始。第一个开始的人掷 2 个骰子,就这样。最后,如果玩家或计算机掷出 1 或按下 N,它会停止并返回该轮的总分。第 1 轮:玩家然后计算机,第 2 轮:玩家然后计算机....进入第 6 轮。我需要获得 scoresheet() 的总分。
标签: c function if-statement while-loop main