我为游戏制作的代码运行得很好,但是当一个人达到至少100分时,我无法让游戏结束。
def dont_Be_Greedy(turn):
points = 0
keepPlaying = 121
print('Lets start!')
input('Press enter to roll')
while keepPlaying == 121:
roll = roll_Dice()
print('You rolled a ' + str(roll))
if roll == 1:
points = 0 * roll
keepPlaying = 110
enter = input('Your turn is over. Next player.')
elif roll > 1:
points += roll
print('your total is', points)
passPlay = input('Do you want to keep playing or pass?'
'\ntype pass or play. ')
if passPlay == 'play':
keepPlaying = 121
else:
keepPlaying = 110
enter = input('Your turn is over. Next player.')
return points
player1 = 0
player2 = 0
while player1 < 100 and player2 < 100:
print('Player 1 points are: ' + str(player1))
print('Player 2 points are: ' + str(player2))
gameOn = dont_Be_Greedy(1)
player1 += gameOn
print('Player 1 points are: ' + str(player1))
print('Player 2 points are: ' + str(player2))
gameOn = dont_Be_Greedy(2)
player2 += gameOn
if player1 >= 100:
print('Player 1 is the winner!')
elif player2 >= 100:
print('Player 2 is the winner!')
当一个玩家达到100时,而不是程序停止,它让他们继续轮到他们。在他们轮到他们之后,它让下一个玩家开始滚动直到他们通过或滚动一个然后程序停止并说明获胜者(两个得分中较高的人)。 我不确定问题出在哪里。
编辑:我添加了dont_Be_Greedy
我尝试移动循环下方的if
和elif
语句,程序停止而不打印获胜者。
答案 0 :(得分:-1)
好像问题在于dont_Be_Greedy()
。
当它达到100时它不会停止。