我正在为2名玩家制作一个简单的棋盘游戏,你可以滚动2个游戏并将第一个游戏移动到49个胜利(见图片结束时)
然而,当该玩家达到49或更多时,我的程序不会停止
from random import randint
print("Welcome to my game please input the players names")
player1=input("Please enter player 1's name followed by the return key : ")
player2=input("Please enter player 2's name followed by the return key : ")
print("right then ", player1," and ",player2, " the game is simple i'll explain the rules as we go along")
player1position=1
player2position=1
while player1position or player2position <49:
print("Its" , player1 , "' go ")
dice1=randint(0,6)
dice2=randint(0,6)
print("Your first dice was a ", dice1, " and your second was a ", dice2)
print("your total is ", dice1+dice2)
player1position=player1position+dice1+dice2
print("player one is now on square ", player1position)
print("Its" , player2 , "' go ")
dice1=randint(0,6)
dice2=randint(0,6)
print("Your first dice was a ", dice1, " and your second was a ", dice2)
print("your total is ", dice1+dice2)
player2position=player2position+dice1+dice2
print("player two is now on square ", player2position)
else:
if player1position > 49:
print(player1 , "has won well done")
else:
print(player2 , "has won well done")
答案 0 :(得分:0)
首先,虽然不需要其他条款。然后,你做的错误是在while子句中。你想检查你的player1position是否小于49并且你的player2position是否相同,但如果你这样检查:
while player1position or player2position <49:
您正在检查,当var1存在或var2小于49时... 所以这将是一个无限循环。
所以,这是代码:
from random import randint
print("Welcome to my game please input the players names")
player1=input("Please enter player 1's name followed by the return key : ")
player2=input("Please enter player 2's name followed by the return key : ")
print("right then ", player1," and ",player2, " the game is simple i'll explain the rules as we go along")
player1position=1
player2position=1
while player1position<49 or player2position<49:
print("Its" , player1 , "' go ")
dice1=randint(0,6)
dice2=randint(0,6)
print("Your first dice was a ", dice1, " and your second was a ", dice2)
print("your total is ", dice1+dice2)
player1position=player1position+dice1+dice2
print("player one is now on square ", player1position)
print("Its" , player2 , "' go ")
dice1=randint(0,6)
dice2=randint(0,6)
print("Your first dice was a ", dice1, " and your second was a ", dice2)
print("your total is ", dice1+dice2)
player2position=player2position+dice1+dice2
print("player two is now on square ", player2position)
if player1position > player2position:
print(player1 , "has won well done")
else:
print(player2 , "has won well done")
一点修复: 可能是player1position和player2position超过49的情况,我们应该检查最后一个条件。