下面代码中的循环正在运行,直到它到达玩家4,它继续显示第四个玩家的分数,而不是继续循环。 while循环也仅在玩家1得分= 100
时有效while player1_score < 100 or player2_score < 100 or player3_score < 100 or player4_score < 100:
dice_rolling()
scoring()
score_awarding()
if player_turn == 1:
player_turn = player_turn + 1
elif player_turn == playerholder:
player_turn = player_turn - 3
elif player_turn == 2 or player_turn == 3:
player_turn = player_turn + 1
print("Congratulations " + names[player_turn] + " you have won!")
print("Thanks for playing!")
非常感谢任何帮助:)
功能:
def create_players(numberofplayers):
for player in range(1,numberofplayers+1):
names.append(input("Please enter Player %d's name: " % player))
print('Welcome to the game ' + ' and '.join([', '.join(names[:-1]), names[-1]]) + '!')
#Module to 'roll' the dice essentially
def dice_rolling():
global dice_score1
global dice_score2
rollagain = 'yes'
while rollagain == 'Yes' or rollagain == 'yes':
dice_score1 = random.randint(1,6)
dice_score2 = random.randint(1,6)
print("Dice 1 has a score of " + str(dice_score1))
print("Dice 2 has a score of " + str(dice_score2))
reply = input("Would you like to roll again?")
if reply == 'yes' or reply == 'Yes':
rollagain = 'yes'
else:
rollagain = 'no'
#Module to get the dice score and then assign it to the score variable based on the values that were rolled
def scoring():
global score
global dice_score1
global dice_score2
score == 0
if dice_score1 and dice_score2 == 1:
score = 25
elif dice_score1 == dice_score2:
score = dice_score1 + dice_score2
score = score * 2
elif dice_score1 == 1 or dice_score2 == 1:
score = score - dice_score1 - dice_score2
elif dice_score1 != dice_score2:
score = dice_score1 + dice_score2
#Module to assign the score to the current players score
def score_awarding():
global score
global player1_score
global player2_score
global player3_score
global player4_score
global player_turn
if player_turn == 1:
player1_score = player1_score + score
print(names[0] + " has " + str(player1_score) + " points!")
elif player_turn == 2:
player2_score = player2_score + score
print(names[1] + " has " + str(player2_score) + " points!")
elif player_turn == 3:
player3_score = player3_score + score
print(names[2] + " has " + str(player3_score) + " points!")
elif player_turn == 4:
player4_score = player4_score + score
print(names[3] + " has " + str(player4_score) + " points!")