Function Snakes and Ladders算法中的增量相关问题(C)
因此,我对函数turns()和game()有一些问题。每当我提示用户在键盘上按“d”时,pspace(玩家空间)的值就会重置回0。这是密码Function Snakes and Ladders算法中的增量相关问题(C),function,increment,Function,Increment,因此,我对函数turns()和game()有一些问题。每当我提示用户在键盘上按“d”时,pspace(玩家空间)的值就会重置回0。这是密码 int turns() { int diceval; int pspace = 0; diceval = diceroll(diceval); pspace = pspace + diceval; printf("Die: %d\n", diceval); printf("%d
int turns()
{
int diceval;
int pspace = 0;
diceval = diceroll(diceval);
pspace = pspace + diceval;
printf("Die: %d\n", diceval);
printf("%d\n", pspace);
return pspace;
}
char promptrolldie()
{
char droll;
int diceval;
int pspace = 0;
printf("Press D to roll the die \n");
scanf("%s", &droll);
if (droll == 'd' || droll == 'D');
turns();
promptrolldie();
return droll;
}
/* Void Game is the game itself. Yes, the game itself, packed in one function. */
void game()
{
int snake1;
int snake2;
int snake3;
int plspace;
int playlives = 3;
int ladder1, ladder2, ladder3;
snake1 = snakepositions(snake1);
snake2 = snakepositions(snake2);
snake3 = snakepositions(snake3);
ladder1 = ladderpositions(ladder1);
ladder2 = ladderpositions(ladder2);
ladder3 = ladderpositions(ladder3);
printf("Snakes are located at %d, %d and %d\n", snake1, snake2, snake3);
printf("Ladders are located at %d, %d and %d\n", ladder1, ladder2, ladder3);
promptrolldie();
turns();
plspace = turns(plspace);
if (plspace == snake1 || plspace == snake2 || plspace == snake3)
{
playlives = playlives - 1;
printf("You lost a life.\n");
printf("Remaining lives = %d\n\n", playlives);
plspace = (plspace - 3);
} else if (plspace == ladder1 || plspace == ladder2 || plspace == ladder3)
{
plspace = plspace + 4;
}
if (playlives == 0)
{
printf("You ran out of lives.\n");
printf("Game Over!");
}
if (plspace >= 50)
printf("You win!");
else
printf("You landed on an empty block. \n");
}
我已经粘贴了掷骰子(promptrolldie)、增加玩家空间(回合)和调用回合函数的游戏函数。有没有办法保留以前的pspace值?这是C吗?您似乎有python背景。我冒昧地增强了您的缩进(假设这不是python…)。我怀疑它可能真的回答了你的问题。(特别是检查<代码> > < <代码> > <代码(如果是DROL= = 'D',''.'''.''.''/''','/d>),请标记语言C或C++或java或…我还建议提供一个例子来演示您的问题。请解释您的计划,说明
promptrolldie()
中的非终止递归应该实现什么。这是C吗?您似乎有python背景。我冒昧地增强了您的缩进(假设这不是python…)。我怀疑它可能真的回答了你的问题。(特别是检查<代码> > < <代码> > <代码(如果是DROL= = 'D',''.'''.''.''/''','/d>),请标记语言C或C++或java或…我还建议提供一个示例来演示您的问题。请解释您的计划,说明promptrolldie()
中的未终止递归应该实现什么。