2017-10-14 3 views
-1

저는 텍스트 기반 게임을 만드는 초보자입니다. 플레이어가 잠긴 문을 여는 방법을 알아 내고 끝낼 수있는 상황에 처해 있습니다. 그러나 나는 그들이 그것을 열지 않기 전에 그들이 문을 나가기를 원하지 않는다.다른 정의 된 함수에 정의 된 함수를 추가하려면 어떻게합니까?

def exit_(): 
    if decision == "exit": 
     print("(exit room)") 
     print("You exit the room.") 
     room_2() 
     #level up here 
    elif decision == "exit prison cell": 
     print("(exit room)") 
     print("You exit the room.") 
     room_2() 
     # level up here 
    elif decision == "exit the prison cell": 
     print("(exit room)") 
     print("You exit the room.") 
     room_2() 

를 다음과 같이 함께 추가 : 플레이어가 자신의 대답을 inputed 후

room_1() and exit_() 

올바르게 잠금을 해제하는 것이, 그래도 난 내가 이렇게 썼다 별도의 정의 함수를 만들 것 문. 하지만 그것은 작동하지 않는 것, 두 개의 정의 된 함수를 함께 추가하는 방법이 있을까요 아니면 다른 방법을 사용해야할까요?

답변

0

사용자가 잠긴 문 여부를 통과 할 수있는 경우 검사에 대한 논리 값을 사용할 수 결정은 출력 room_1()

door_locked == True 
if userinput == correct_answer: 
    door_locked = False 
    # user can do whatever they want now the door is unlocked 
    room_2() 
else: 
    door_locked = True 
    # user can do whatever they want but the door is still locked 
+0

이것은입니다. 파이썬이 아니라 ...'bool door_locked == true' ?? 파이썬은 동적 인 언어이고, 변수는 타이핑되지 않으며'true'가 아니라'true'이고'user.input'은 무엇입니까 ??? –

+0

@ juanpa.arrivillaga 코드는 일반적이며 예를 들어 쉽게 번역 할 수 있습니다. 'correct_answer = "unlock"''input = input ("")''if (input == correct_answer)'등. –

0
def exit_(decision): 
    if decision== "exit": 
       print ("(exit room)") 
       print ("You exit the room.") 
       room_2() 
       #level up here 
    elif decision== "exit prison cell": 
       print ("(exit room)") 
       print ("You exit the room.") 
       room_2() 
       #level up here 
    elif decision== "exit the prison cell": 
       print ("(exit room)") 
       print ("You exit the room.") 
       room_2() 

그리고 당신이 만드는

def room_1(): 
    #do stuff... 
    return decision 

그러면 전화 하시게

exit(room_1())