2014-05-15 3 views
0

먼저 나쁜 코드 스타일에 대해 사과 드리며, 이것은 내 첫 번째 커다란 프로젝트 (파이썬 클래스의 최종본)입니다. 루프 메뉴에서 "main menu"displaymenu 함수에서 movemenu 함수로 이동해야하는 루프 설정에 붙어 있습니다. displaymenu에서 A를 선택하면 바로 실행되므로 아무 것도 실행되지 않습니다. 선택 항목 b와 c는 잘 작동합니다. 내 추측은 루프를 설계하고 루프를 돌이키거나 이동하는 것과 관련된 문제입니다.내 루프로 묶인 클래스 용 RPG 디자인

실제 이동이 진행되는 한, 나는 꽤 좋은 찌르기를했다. 그러나 메뉴를 작동시키는 것은 움직임을 테스트 할 수있는 것조차 중요하다.

모든 입력 또는 건설적인 비판은 매우 감사하겠습니다. 감사합니다

#map movement functions--------------------------------------------------------- 


def mapFunc(x,y): 
    if x == 0: 
     if y == 0: 
      print("Sh*ts Swampy yo") 
     elif y == 1: 
      print("Sh*ts Sandy broski") 
     elif y == 2: 
      print("trees everywhere bro") 
     else: 
      print("how the f**k did you get here") 
    elif x == 1: 
     if y == 0: 
      print("Sh*ts Swampy yo") 
     elif y == 1: 
      print("Sh**s Sandy broski") 
     elif y == 2: 
      print("trees everywhere bro") 
     else: 
      print("how the f**k did you get here") 
    elif x == 2: 
     if y == 0: 
      print("S**s Swampy yo") 
     elif y == 1: 
      print("Sh*s Sandy broski") 
     elif y == 2: 
      print("trees everywhere bruh") 
     else: 
      print("how the f**k did you get here") 






def displayMenu(): 
    choice = None 
    choice = input(""" 



Choose from the following options: 

A.)Map Movement 

B.) Display Inventory and Stats 

C.) Configure Power Treads 
""").upper() 

    if choice == 'A': 
     moveMenu() 
     completed = True 
    elif choice == 'B': 
     displayStats(player) 
    elif choice == 'C': 
     askPowerTread() 
    else: 
     choice not in ['A','B','C'] 
     print("Invalid choice.") 


def moveMenu(): 
    choice = None 
    validMapMovement = False 
    #while choice not in ('A', 'B', 'C', 'D'): 
    while not validMapMovement: 
     choice = input 
     (""" 
     Choose a direction: 

    A.) North 
    B.) South 
    C.) East 
    D.) West 
    """).upper() 

    if choice == 'A': 
    if playerY (+1) >= 0: 
      playerY -= 1 
      mapFunc(playerX, playerY) 
      validMapMovement = True 
    else: 
     print("Invalid Choice") 
    elif choice == 'B': 
     if playerY +1 <= 2: 
      playerY += 1 
      mapFunc(playerX, playerY) 
      validMapMovement = True 
    else: 
     print("Invalid Choice") 
    elif choice == 'C': 
     if playerX +1 <= 2: 
      playerX += 1 
      mapFunc(playerX, playerY) 
      validMapMovement = True 
    else: 
     print("Invalid Choice") 
    elif choice == 'D': 
     if playerY -1 >= 0: 
      playerX -= 1 
      mapFunc(playerX, playerY) 
      validMapMovement = True 
    else: 
     print("Invalid Choice") 
    else: 
     choice not in ('A', 'B', 'C', 'D') 
     print("Invalid Choice") 
     roll() 

다음과 같은

#ExampleQuest, v5.5 
from ExampleQuestFunctions import * 
import random #rolls 
import time #sleep 
           #  Introduction  # 


#Main Loop()--------------------------------------------------------------------------- 
player = ["",20,5,10,3,7,0] 
playerInventory = [] 
playerX = 0 
playerY = 0 

def mapPhase():  
    completed = False 
    while not completed: 
     displayMenu() 


#Battle Loop()--------------------- 
def battlePhase(): 

#Instance Variables 
playerTurn = True 
completed = False 

playAgain = True 
while playAgain: 
    #Create the enemy pool, and generate a random enemy 
    pool = createEnemyPool() 
    enemy = random.choice(pool) 

    #Start the battle 
    player = battle(player, enemy, playerTurn) 

    #Continue Adventure 
    if getString("Would you like to continue your adventure?").upper() not in ['Y','YES']: 
     playAgain = False 
    else: 
     playAgain = False 
    inventoryUpdate() 



#-----------------------  
def main(): 
    mapPhase() 

#Run it! 
main() 
+0

코드의 들여 쓰기가 맞습니까? 예 : def main() :은 mapPhase()와 같은 들여 쓰기를가집니다. – Anov

+0

내 들여 쓰기가 괜찮습니다. 메신저에서 IDLE을 쓰면 즉시 구문 오류가 발생합니다. 모든 maphase()가 현재 부울입니다. 게시 할 서식 지정 요구 사항 때문에 내 들여 쓰기가 펑키 해 보일 수도 있습니다. – user3626260

+2

선생님이 매우 기쁘게 생각합니다 :) –

답변

0

뭔가 내가 ... 내가 당신의 질문을 이해 가정을 할 것이다 다음 방금 각각에 대해 menulist 요소를 포맷하는 방법입니다 거기에 내 주요으로 파일 메뉴와 거의 모든 것을 다룹니다.

def get_player_choice(choices): 
    labels,actions = zip(*choices) 
    choice_actions = dict(enumerate(actions,1)) 
    for choice_id,label in enumerate(labels,1): 
     print "%d. %s"%(choice_id,label) 
    while True: 
     result = raw_input("Select Option:") 
     try: 
      return choice_actions[int(result)] 
     except TypeError: 
      print "ERROR: Please enter a number choice!" 
     except KeyError: 
      print "ERROR: Unknown Choice!" 

def LookAround(): 
    print "You See Something!" 
def Quit(): 
    print sys.exit  

menu_a = [ 
("Look Around",LookAround), 
("Quit!",Quit) 
     ] 
fn = get_player_choice(menu_a) 
fn()   
+0

내가 구현하려고 시도해 보니 기꺼이 하겠지만 구문 중 일부는 초심자의 편한 영역 밖에 있습니다. 그러나 나는 그것의 일반적인 흐름을 이해할 수있다. – user3626260