2016-06-26 4 views
0

私は単純なゲームのメニューを書いていますので、whileループを使用して、ユーザが希望するオプションをクリックするようにしました。私のプログラムは、このループまで正常に動作しますが、次のループの行に到達したとき、それは続行されません:Pythonでwhileループを真の条件で無視しています

pygame.mouse.set_visible(True)  # This is the last line processed. 
while True:       # This line ist not processed. 
    (curx,cury)= pygame.mouse.get_pos() 
    screen.blit(cursor,(curx-17,cury-21)) 
    pygame.display.flip() 
    # rating values of the cursor position and pressed mouse button below: 
    (b1,b2,b3) = pygame.mouse.get_pressed() #getting states of mouse buttons 
    if (b1 == True or b2 == True or b3 == True): # "if one mouse button is pressed" 
     (cx,cy) = pygame.mouse.get_pos() 
     if (px <= curx <= px+spx and py <= cury <= py+spy): 
      return (screen,0) 
     elif (ox <= curx <= ox+sox and oy <= cury <= oy+soy): 
      return (screen,1) 
     elif (cx <= curx <= cx+scx and cy <= cury <= cy+scy): 
      return (screen,2) 
     else: 
      return (screen,3) 
    time.sleep(0.05) 

私はすでに間違ってインデントのようなものをチェックしています。私が持っていた

:質問が削除された答えに頼まれたので

ところで、私の通訳(python.exe、Pythonの2.7.11)は、常に

while True: 

のこの行に到達した後に応答しません上記の各行の間に印字( "")を付けて、問題のある行を探します。 私が4行上に書いたように、インタープリタ(それとデバッガとバグレポート)はそれ以上の応答なしでクラッシュしました。

この関数の全体のコードは次のとおり #MAIN MENU DEF smenu(スクリーン、解像度、menuimg、カーソル): #preset: X、Y =のRES クリック= Falseの

print("preset") # TEST PART 

# Fontimports, needed because of non-standard font in use 
menu = pygame.image.load("menu.png") 
playGame = pygame.image.load("play.png") 
options = pygame.image.load("options.png") 
crdts = pygame.image.load("credits.png") 

print("Fontimport") # TEST PART 


#SIZETRANSFORMATIONS 
# setting of sizes 
smx,smy = int((y/7)*2.889),int(y/7) 
spx,spy = int((y/11)*6.5),int(y/11) 
sox,soy = int((y/11)*5.056),int(y/11) 
scx,scy = int((y/11)*5.056),int(y/11) 

print("setting of sizes") # TEST PART 

# setting real size of text 'n' stuff 

menu = pygame.transform.scale(menu,(smx,smy)) 
playGame = pygame.transform.scale(playGame,(spx,spy)) 
options = pygame.transform.scale(options, (sox,soy)) 
crdts = pygame.transform.scale(crdts, (scx,scy)) 
cursor = pygame.transform.scale(cursor,(41,33)) 

print("actual size transformation") # TEST PART 

#DISPLAY OF MENU 
# fixing positions 
mx, my = int((x/2)-((y/7)/2)*2.889),10 # position: 1. centered (x) 2. moved to the left for half of the text's length 3. positioned to the top(y), 10 pixels from edge 
px, py = int((x/2)-((y/11)/2)*6.5),int(y/7+10+y/10) # position: x like above, y: upper edge -"menu"'s height, -10, - height/10 
ox, oy = int((x/2)-((y/11)/2)*5.056),int(y/7+10+2*y/10+y/11) 
cx, cy = int((x/2)-((y/11)/2)*5.056),int(y/7+10+3*y/10+2*y/11) 

print("fixing positions") # TEST PART 

# set to display 
#screen.fill(0,0,0) 
screen.blit(menuimg,(0,0)) 
screen.blit(menu,(mx,my)) 
screen.blit(playGame,(px,py)) 
screen.blit(options,(ox,oy)) 
screen.blit(crdts,(cx,cy)) 
pygame.display.flip() 

print("set to display") # TEST PART 

# request for input (choice of menu options) 
pygame.mouse.set_visible(True) 
print("mouse visible") # TEST PART last processed line 
while (True): 
    print("While-loop") # TEST PART 
    curx,cury = pygame.mouse.get_pos() 
    screen.blit(cursor,(curx-17,cury-21)) 
    pygame.display.flip() 
    # decision value below 
    (b1,b2,b3) = pygame.mouse.get_pressed() # getting mouse button's state 
    if (b1 == True or b2 == True or b3 == True): # condition true if a buton is pressed 
     (cx,cy) = pygame.mouse.get_pos() 
     if (px <= curx <= px+spx and py <= cury <= py+spy): 
      return (screen,0) 
     elif (ox <= curx <= ox+sox and oy <= cury <= oy+soy): 
      return (screen,1) 
     elif (cx <= curx <= cx+scx and cy <= cury <= cy+scy): 
      return (screen,2) 
     else: 
      return (screen,3) 
    time.sleep(0.05) 
print("directly skipped") 
+0

'(curx、cury)'のかっこを削除しようとしましたか? –

+0

はい、私はしました:それは何も変わっていません。 – CaptainPoset

答えて

0

コメントはしますが、担当者が少ないためできません。

問題は、値を関数外のwhileループに戻している可能性があります。

あなたのインタプリタ/ IDEが正しいエラーメッセージを表示していないのはちょっと奇妙ですが、

+1

私はPythonが関数内のwhileループから値を返そうとするのは不思議ですが、Python基盤の公式のインタプリタにとっては致命的なエラーだとは考えにくいですインタラクティブなクラッシュ。それはそれが処理できないそのような間違いに対する保護はない。 – CaptainPoset

0

if (b1 == True or b2 == True or b3 == True): 

あなたが戻ってあなたの関数ずにwhileループの中に立ち往生しているように、この条件がtrueになることはありません:私はこの問題は、あなたの次のコード行であることを考えますything。

+0

このプログラムのアイデアは次のとおりです。3つの特定のフィールドの1つでマウスボタンを押してオプションを選択するまでは、ループを維持する必要があります。つまり、ループを処理することさえできません。 pygame.orgの文書によると、マウスボタンを押すと条件が真となります。 – CaptainPoset

関連する問題