2017-03-21 11 views
1

私は初心者プログラマーで、私はPythonistaを使って、ボタンを利用した悪いUIファイティングゲームを作成しています。私のコードは、攻撃に関連するボタンや下のコードに挙げられている機能を守るUIスクリプトを参照しています。私の問題は、ウインの機能が呼び出され、eturnというラベルの敵のターンに移動できるようになるまで待つことです。現在、uiは瞬時にターンしてからuiをレイヤーし、敵の回転を無期限に繰り返す。初心者の知識レベルを維持しながら、ユーザー入力が完了するまでスクリプトを待機させる方法を誰かが知っていれば、大いに感謝します。 コード:ui経由の入力が受信されるまで待つ関数呼び出しを取得する

import ui 
import random 
import time 
hp = 100 
pots = 3 
atk = 7 
guard = False 

#enemy values 
ehp = random.randint(50, 75) 
eatk = random.randint(8, 11) 
eguard = False 

def menu(): 
    global guard 
    v = ui.load_view('option menu') 
    v.present('sheet') 

def attack(sender): 
    v.close() 
    if eguard == False: 
     ehp -= atk 
     print('You slash at the enemy and deal %r damage' % atk) 
     print('\nIt has %r hp left' % ehp) 
     return ehp 
    elif eguard == True: 
     dmg = (atk - 3) 
     ehp -= dmg 
     print('You slash at the enemy and deal %r damage' % dmg) 
     print('\nIt has %r hp left' % ehp) 
     return ehp 

def defend(sender): 
    v.close() 
    print('You put up your guard') 
    guard = True 
    return guard 

def heal(sender): 
    global hp, pots 
    v.close() 
    if pots > 0: 
     pots -= 1 
     hp += 25 
     if hp > 100: 
      hp = 100 
     print('You use a health potion and gain 25hp, you have %r potions and %r hp left' % (pots, hp)) 
    elif pots == 0: 
     print('You are out of potions!') 

def eturn(): 
    global eguard, hp, ehp 
    choice = random.randint(1, 3) 
    eguard = False 
    if choice == 1: 
     if guard == True: 
      dmg = eatk - 3 
      hp -= dmg 
      print('The creature swipes at you and deals %r damage, you have %r hp left' % (dmg, hp)) 
     elif guard == False: 
      hp -= eatk 
      print('The creature swipes at you and deals %r damage, you have %r hp left' % (eatk, hp)) 
    elif choice == 2: 
     print('The creature defends itself') 
     eguard = True 
    elif choice == 3: 
     ehp += 10 
     if ehp > 75: 
      ehp = 75 
     print('The creature heals itself for 10 hp') 

def turn(): 
    menu() 

def game(): 
    print('instructions') 
    turn() 
    eturn() 

game() 

答えて

0

これを試してください。

def menu(): 
    global guard 
    v = ui.load_view('option menu') 
    v.present('sheet') 
    v.wait_modal() # Waits until the dialog is off the screen 
    v.close()  # Properly cleans up the dialog 
+0

ありがとうございます!それは命の恩人です! –

関連する問題