我爲遊戲設定的代碼運行得很好,但是當一個人達到至少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
聲明正好在循環下面,程序停止沒有打印贏家。
因此,一個顯而易見的問題它不會停止:是'print'語句執行器(Player 1/2是贏家!)? – UnholySheep
我認爲你的問題是'dont_Be_Greedy()'。確保它停在100. – Bharel
@UnholySheep我不知道我理解你的問題。 – Jason