그래서 게임의 초기 시작을 메인 메뉴로 정의하고 레벨 내에서의 어려움과 같은 몇 가지 옵션을 선택하여 인쇄 할 수 있습니다. 게임에 대한 도움말을 참조하십시오. 그들이 도움을 청할 때 나는 주 메뉴로 돌아갈 수있는 옵션을 갖기를 원합니다. 왜 def mainmenu()를 만들었습니까? 그러나 비록 내 helpmenu 문을 경우에도 나는 그들이 입력 한 메뉴 또는 메인 메뉴에서 다시 호출해야 메뉴 그것은 아무것도하지 않는다고 진술했다. 우리는 우리가 사용해야 모듈을 가지고 있고이 같은 사실은 그래서 그냥 :) 여기 클래스 내에있는 def를 호출하는 방법
코드 def mainmen():
p.write("Welcome to 'The Great Escape'!\n")
p.write("\nPlease type what dificulty you would like to play the game,\nthe options are Easy, Medium or Hard\n")
p.write("\nHowever, if you need help please type Help for instructions\n")
p.write(">>>")
dificulty = p.next()
if dificulty == "easy" or dificulty == "Easy":
p.clear()
p.write("The Great Escape")
easy()
elif dificulty == "medium" or dificulty == "Medium":
p.clear()
p.write("The Great Escape")
medium()
elif dificulty == "hard" or dificulty == "Hard":
p.clear()
p.write("The Great Escape")
hard()
elif dificulty == "help" or dificulty == "Help":
p.clear()
p.write("Welcome to 'The Great Escape' instructions\n")
p.write("\nTo complete the level you must move your Turtle around the\nline without touching the line itself\n")
p.write("\nControls\n")
p.write("Forward - 'W'\n")
p.write("Left - 'A'\n")
p.write("Backwards - 'S'\n")
p.write("Right - 'D'\n")
p.write("\nPlease type 'Menu' to go back to the main menu,\nor 'Exit' to quit the game\n")
p.write(">>>")
**`here is my help menu if statements, I want it so that if they type Menu or menu they get taken back to the main menu.`**
helpmenu = p.next()
if helpmenu == "Menu" or helpmenu == "menu":
p.clear()
mainmenu() **<<This should call on the mainmenu but it doesn't??**
elif helpmenu == "Exit" or helpmenu == "exit":
p.clear()
p.write("Hope you play soon!")
의 무시 사용자 입력을 수신 의미합니다 p.next()와 같은 것을 사용하는 이유입니다
나는 이것이 중복 된 것이라고 확신하지만, 다른 질문을 찾을 수 없습니다 ... –
기본을 배우는 데 도움이되는 좋은 파이썬 서적을 권하고 싶습니다. 현재 무료로 제공되는 사람들 중 가장 좋은 사람은 Zed Shaws "Python을 배우는 것이 어려운 방법"입니다. http://learnpythonthehardway.org/ –
수업이 필요하지 않습니다. 'mainmenu()'를 최상위 함수로 정의하고 코드를 단순화하십시오. (메소드 내에서'self '를 사용하지 않는 것에 유의하십시오. 이것은 메소드가 될 필요가 없다는 암시입니다. –