2017-11-06 4 views
0

ので、私はヘビとはしごゲームを作っていると私はサイコロの問題を抱えているだけで、私のプレーヤー2ヘビとはしごのサイコロの問題(のpython)

のためにすべてをインデントするために必要な、今の助けに感謝し、それを固定しました:

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

この後、「player1 ready to roll ??」が繰り返されます。ここ

は私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

あなたはそのif文の中でNOに等しいplayer1rollをリセットする必要があります。

+0

私が文の場合、私は – groot

+0

まあそれをアップロードした際に、同様の問題を解決することができること、それwhileループではない作りになっていたのを忘れ、私は私はそれを変更する前にそれを持っていたthatsの何ので – rahlf23

+0

それはdoesntの仮定if文whoops – 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をロールする準備ができていますか? はい あなたはロールしました:2 player1が位置にあります:2 player1 ready to roll ??それは私に与えるものです – groot

+0

正直なところ私は何が起こっているのか分かりません – groot

0

は、あなたのコードのタイプミスがあると表示されます。

player1roll=input("player1 ready to roll??\n").upper 

には終了括弧がありませんので、 "YES"ではなく関数を取得する必要があります。

EDIT: 次のコードで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

それは上にする必要があります – lamorach

+0

iveはそれを追加してnothingsを変更しました – groot