现在修复它感谢帮助,只需要为我的播放器缩进一切2
所以我做了蛇和梯子游戏,我对骰子有问题:
while player1roll != "YES":
player1roll=input("player1 ready to roll??\n").upper
player1roll=random.choice(dice)
print("you rolled a:", player1roll)
在此之后它只是不断重复" player1准备滚动?"
这是我的所有player1代码:
while selection != "PVP" or "AI":
selection=input("player vs player(PVP) or with AI (AI)??\n").upper()
if selection == "PVP":
while player1pos or player2pos <100:
**while player1roll != "YES":
player1roll=input("player1 ready to roll??\n").upper
player1roll=random.choice(dice)
print("you rolled a:", player1roll)**
player1pos+=player1roll
if board[player1pos] >0: #if the number is bigger than 0 its a ladder
print("you found a ladder")
player1pos+= board[player1pos] #find the position its supposed to be at on the board
print("player1 is at position:",player1pos)
print("")
elif board[player1pos] <0: #if the number is negative then its a snake
print("you found a snake")
player1pos+=board[player1pos]
print("player 1 is at position:",player1pos)
print("")
else: #if its just a 0 they stay at that position
print("player1 is at position:",player1pos)
print("")
if 100<=player1pos: #if the player position is 100 or more they win
print("player1 win")
quit()
如果您可以建议任何其他有用的更改,因为我需要尝试尽可能地改进它:)
答案 0 :(得分:0)
您需要在该if语句中重置player1roll等于NO。
答案 1 :(得分:0)
当你说“它只是不断重复”播放器1准备好滚动?“”这是你看到的唯一输出吗?没有其他输出?
你确实意识到你正在将player1roll设置为“骰子”序列中的随机元素,对吧?对用户输入和滚动值使用相同的变量是否有意义?
如何更改变量名称?
变化:
while player1roll != "YES":
player1roll=input("player1 ready to roll??\n").upper
到:
while player1in != "YES":
player1in=input("player1 ready to roll??\n").upper
答案 2 :(得分:0)
如果您的代码如上所示,则代码中会出现拼写错误。
player1roll=input("player1 ready to roll??\n").upper
缺少结束括号,所以应该抓住函数而不是“YES”。
编辑: 在以下代码中,player1roll用于玩家输入和掷骰子。这导致模具滚动超越轮到他的接受程度。如果掷骰子应该是while循环的一部分,那么你应该创建一个新变量。
while player1_input != "YES":
player1_input=input("player1 ready to roll??\n").upper
player1roll=random.choice(dice)
print("you rolled a:", player1roll)