如您所见,我是 Python 的初学者,因此我们将不胜感激。我的问题是,我正在尝试测试所有场景的代码,但我无法测试决胜局。当然,我可以只插入Player1Score = Player2Score
(我已经对其进行了哈希标记以显示位置),但这只会使程序进入无限循环,这违背了决胜局的目的。那么有什么办法可以让程序只经历一次决胜局部分,然后让一个玩家获胜呢?
(如果我的问题有任何错误,我深表歉意,我也是 stackoverflow 的新手)
import random
def DiceGame():
Count = 0
Player1Score = 0
Player2Score = 0
while Count <= 4:
Count += 1
print ("\n It is Round",Count, "\n")
print ("It is Player 1's turn.")
x = input("Press [Enter] to roll.")
Score = Rolls()
Player1Score += Score
print ("Player 1, your score so far is",Player1Score)
print ("It is Player 2's turn.")
x = input("Press [Enter] to roll.")
Score = Rolls()
Player2Score += Score
print ("Player 2, your score so far is",Player2Score)
#Player1Score = Player2Score
if Player1Score == Player2Score:
print ("It is a tie!")
print ("There will be a final tiebreaker.")
Count -= 1
DiceGame()
elif Player1Score >= Player2Score:
print ("Player 1 wins!")
elif Player1Score <= Player2Score:
print ("Player 2 wins!")
def Rolls():
Roll1 = random.randint(1,6)
Roll2 = random.randint(1,6)
print ("You got a",Roll1)
print ("You got a",Roll2)
Score1 = Roll1 + Roll2
if Score1 == 2 or Score1 == 4 or Score1 == 6 or Score1 == 8 or Score1 == 10 or Score1 == 12:
print ("Your total is even so you get an extra 10 pts.")
Score2 = Score1 + 10
print ("Your score for this round is" ,Score2)
elif Score1 == 3 or Score1 == 5 or Score1 == 7 or Score1 == 9 or Score1 == 11:
print ("Your total is odd so you lose 5 pts.")
Score2 = Score1 - 5
if Score2 <= 0:
print ("Your score has gone below 0pts. It will therefore be reset to 0pts")
Score2 = 0
print ("Your score for this round is" ,Score2)
return Score2
DiceGame()
慕尼黑5688855
相关分类