2017-07-14 51 views
0

我想提出一個簡單的棋盤遊戲,在那裏你滾2個模具和移動吳丹許多廣場第一至49勝(見高端形象)2名球員蟒蛇棋盤遊戲錯誤不會達到臨界

但是我的計劃會當玩家到達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") 

board i am trying to create

回答

0

首先不會停止,而不需要else子句。然後,你犯的錯誤是在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的情況​​下,我們應該在最後一個條件檢查。

+0

非常感謝這真的有幫助 – benisbestpokemongo