2017-11-06 15 views
0

은 지금 감사가 도움을, 단 2뱀과 사다리 주사위 문제 (파이썬)

그래서 나는 뱀과 사다리 게임을 만들었습니다 그리고 난 주사위에 문제가있어 내 선수에 대한 모든 것을 들여 쓰기에 필요한 고정 :

while player1roll != "YES": 
      player1roll=input("player1 ready to roll??\n").upper 
      player1roll=random.choice(dice) 
      print("you rolled a:", player1roll) 

이 후에는 "player1 ready to roll ??" 여기

내 재생기 코드의 전체입니다 :

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

당신으로 많은 향상을 필요로 너무 도움이 될 다른 변경을 제안 할 수 있다면 그 if 문 안에서 player1roll을 NO로 재설정해야합니다.

+0

는 나는 그것을 while 루프하지 수 있도록했는데 잊었 if 문 내가 문제를 해결할뿐만 아니라 나는 그것이 나던 – groot

+0

음을 업로드 할 때 때문에 그게 전부 내가 그것을 변경하기 전에 내가 그것을 가지고 무엇을 if 문으로 돌아 가기 – rahlf23

+0

을 가정 수있는 그것을 – groot

0

"그냥 계속해서"player1을 굴릴 준비가되어 있다고 말하면 "그게 말 그대로 출력하는 유일한 것입니까? 다른 출력은 없습니까?

player1roll을 "주사위"시퀀스의 무작위 요소로 설정한다는 것을 알았습니까? 사용자 입력과 롤 값에 동일한 변수를 사용하는 것이 합리적입니까?

변수 이름을 변경하는 것은 어떻습니까?
변경 :

while player1roll != "YES": 
player1roll=input("player1 ready to roll??\n").upper 


까지 : 위의 코드 인 경우

while player1in != "YES": 
    player1in=input("player1 ready to roll??\n").upper 
+0

player1을 roll 할 준비가 되셨습니까 ?? 예 굴림 : 2 ​​ player1이 (가) 위치에 있습니다. 2 player1 roll to ready ?? 그것이 내게주는 것 – groot

+0

솔직히 더 이상 무슨 일이 일어날 지 모르겠다. – groot

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) 
+0

괄호는 무엇인가 – groot

+0

그것은 upper() – lamorach

+0

ive에 덧붙여서 nothings가 변경되어야 함 – groot