2017-03-21 1 views
1

저는 초보 프로그래머이며 버튼을 사용하는 나쁜 UI 투사 게임을 만들기 위해 Pythonista를 사용하고 있습니다. 내 코드는 Ui 스크립트를 참조하여 공격과 관련된 단추 또는 아래 코드에 나열된 기능을 방어합니다. 내 문제는, iR에서 함수가 호출되어 eturn이라고 표시된 적의 차례로 이동할 수있게되기를 기다리는 것입니다. 현재 Ui는 적을 즉시 뽑아 내고 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

감사합니다. 그것은 생명의 은인입니다! –

관련 문제