我正在將Python豬遊戲作爲一項業餘愛好。我的具體問題是關於第二個if
聲明。爲什麼它在前面if
陳述中設置爲player1roll = 'End Turn'
?Python遊戲如果執行語句
import random, easygui
player1score = 0
player2score = 0
player1turnTotal = 0
player2turnTotal = 0
player1name = easygui.enterbox ('Player 1 please enter your name: ')
player2name = easygui.enterbox ('Player 2 please enter your name: ')
dice1roll = 0
dice2roll = 0
player1roll = 'Roll Again'
player2roll = 'Roll Again'
player1checkScore = 0
player2checkScore = 0
while player1roll == 'Roll Again' or player2roll == 'Roll Again':
while player1roll != 'End Turn' and player2score < 100 and player2roll != 'Quit' and player1roll != 'Quit':
dice1roll = random.randint (1, 7)
dice2roll = random.randint (1, 7)
if dice1roll == 1 and dice2roll == 1:
print 'Player 1 if 1.'
player1score = 0
player1turnScore = 0
dice1 = str (dice1roll)
dice2 = str (dice2roll)
# print 'You rolled a 1 and a 1'
# print player1name, 'your total score is 0'
easygui.msgbox (player1name + ' you rolled a ' + dice1 + ' and a ' + dice2)
easygui.msgbox (player1name + ' your total score is: 0')
player1roll = 'End Turn'
player2roll = 'Roll Again'
player1turnTotal = 0
if dice1roll == 1 or dice2roll == 1 and player1roll != 'End Turn':
print 'Player 1 if 2.'
player1turnScore = 0
dice1 = str (dice1roll)
dice2 = str (dice2roll)
player1score = player1score + player1turnScore
player1total = str (player1score)
easygui.msgbox (player1name + ' you rolled a ' + dice1 + ' and a ' + dice2)
easygui.msgbox (player1name + ' your total score at turns end is: ' + player1total)
player1roll = 'End Turn'
player2roll = 'Roll Again'
player1turnTotal = 0
if dice1roll != 1 and dice2roll !=1 and player1roll != 'End Turn':
print 'Player 1 if 3.'
dice1 = str (dice1roll)
dice2 = str (dice2roll)
easygui.msgbox (player1name + ' you rolled a ' + dice1 + ' and a ' + dice2)
player1turnScore = dice1roll + dice2roll
player1turnTotal = player1turnTotal + player1turnScore
player1total = str (player1turnTotal)
player1overall = str (player1score)
easygui.msgbox (player1name + ' your total turn score is: ' + player1total + ' and your total score is: ' + player1overall)
player1checkScore = player1score + player1turnTotal
if player1checkScore >= 100:
print 'Player 1 if 3.1.'
easygui.msgbox ("Congratulations, you've won " + player1name + "!!!")
player2roll = 'End Turn'
player1roll = 'End Turn'
if player1checkScore < 100:
print 'Player 1 if 3.2.'
player1roll = easygui.buttonbox (player1name, ' roll or end turn?', choices = ['Roll Again', 'End Turn', 'Quit'])
if player1roll == 'End Turn' and player1checkScore < 100:
print 'Player 1 if 3.3.'
player1score = player1score + player1turnTotal
player1endTotal = str (player1score)
easygui.msgbox (player1name + ' Your total score at turns end is: ' + player1endTotal)
player1roll = 'End Turn'
player2roll = 'Roll Again'
player1turnTotal = 0
while player2roll != 'End Turn' and player1score < 100 and player2roll != 'Quit' and player1roll != 'Quit':
dice1roll = random.randint (1, 7)
dice2roll = random.randint (1, 7)
if dice1roll == 1 and dice2roll == 1:
print 'Player 2 if 1.'
player2score = 0
player2turnScore = 0
dice1 = str (dice1roll)
dice2 = str (dice2roll)
# print 'You rolled a 1 and a 1'
# print player2name, 'your total score is 0'
easygui.msgbox (player2name + ' you rolled a ' + dice1 + ' and a ' + dice2)
easygui.msgbox (player2name + ' your total score is: 0')
player2roll = 'End Turn'
player1roll = 'Roll Again'
player2turnTotal = 0
if dice1roll == 1 or dice2roll == 1 and player2roll != 'End Turn':
print 'Player 2 if 2.'
player2turnScore = 0
dice1 = str (dice1roll)
dice2 = str (dice2roll)
player2score = player2score + player2turnScore
player2total = str (player2score)
easygui.msgbox (player2name + ' you rolled a ' + dice1 + ' and a ' + dice2)
easygui.msgbox (player2name + ' your total score at turns end is: ' + player2total)
player2roll = 'End Turn'
player1roll = 'Roll Again'
player2turnTotal = 0
if dice1roll != 1 and dice2roll !=1 and player2roll != 'End Turn':
print 'Player 2 if 3.'
dice1 = str (dice1roll)
dice2 = str (dice2roll)
easygui.msgbox (player2name + ' you rolled a ' + dice1 + ' and a ' + dice2)
player2turnScore = dice1roll + dice2roll
player2turnTotal = player2turnTotal + player2turnScore
player2total = str (player2turnTotal)
player2overall = str (player2score)
easygui.msgbox (player2name + ' your total turn score is: ' + player2total + ' and your total score is: ' + player2overall)
player2checkScore = player2turnTotal + player2score
if player2checkScore >= 100:
print 'Player 2 if 3.1.'
easygui.msgbox ("Congratulations, you've won " + player2name + "!!!")
player1roll = 'End Turn'
player2roll = 'End Turn'
if player2checkScore < 100:
print 'Player 2 if 3.2.'
player2roll = easygui.buttonbox (player2name, ' roll or end turn?', choices = ['Roll Again', 'End Turn', 'Quit'])
if player2roll == 'End Turn' and player2checkScore < 100:
print 'Player 2 if 3.3.'
player2score = player2score + player2turnTotal
player2endTotal = str (player2score)
easygui.msgbox (player2name + ' Your total score at turns end is: ' + player2endTotal)
player2roll = 'End Turn'
player1roll = 'Roll Again'
player2turnTotal = 0
因爲'diceroll'之一是'1'? – linusg