lundi 2 octobre 2017

How do i add a stop/quit/end command to this list text maze on python?

I have to make a maze with three different levels that allows you to quit at any time. I've tried inserting my quit() call everywhere but I can't seem to get it to work. Also, I know this isn't under the scope of my original question, but when I call the average() or difficult() levels, they just end up printing the easy() maze. Can someone tell me what I'm doing wrong? Thanks!

def start():
    print('Welcome to the Maze!')
    choose_level()

def choose_level():
    level = input('Select a level: Easy, Average, or Difficult \n')
    if level == 'Easy' or 'easy' or 'EASY' or '1':
        return easy()
    elif level == 'Average' or 'average' or 'AVERAGE' or '2':
        return average()
    elif level == 'Difficult' or 'difficult' or 'DIFFICULT' or '3':
        return difficult()


def easy():

    maze1_list = []
    # [Description, North, East, South, West]
    maze1_list.append(['Available Directions: East', None, 1, None, None]) #0
    maze1_list.append(['Available Directions: East, South, West', None, 2, 3, 0]) #1
    maze1_list.append(['Available Directions: West', None, None, None, 1]) #2
    maze1_list.append(['Available Directions: North, East', 1, 4, None, None]) #3
    maze1_list.append(['Available Directions: South, West', None, None, 5, 3]) #4

    current_tile = 0
    done = False

    directions = {'North' or 'north' or 'NORTH':1, 'East' or 'east' or 'EAST':2, 'South' or 'south' or 'SOUTH':3, 'West' or 'west' or 'WEST':4}
    #Source: obtained from <http://ift.tt/2fGcNWR;
    #Date: <October 2, 2017>
    #Name of Author/Programmer: <Anton vBR>

    while not done:
        print('')
        print(maze1_list[current_tile][0])
        x = '0'
        available = False

        while not available:

            while not directions.get(x.title()): #Source: obtained from <http://ift.tt/2yFgFOX;
                                             #Date: <October 2, 2017>
                                             #Name of Author/Programmer: <Paul Vincent Craven>
                if x!='0':
                    print('Please choose an available direction. ')
                x = input('Which direction will you take? \n')

            next_move = directions.get(x.title()) #Source: obtained from <http://ift.tt/2yFgFOX;
                                              #Date: <October 2, 2017>
                                              #Name of Author/Programmer: <Paul Vincent Craven>
            next_tile = maze1_list[current_tile][next_move]

            if next_tile:
                available = True
                current_tile = next_tile

            elif x == 'quit':
                quit()

            else:
                print('Please choose an availble direction.')
                x = '0'

        if current_tile == 5:
            print('Congratulations! You found the exit. \nGoodbye.')
            done = True


def average():

    maze2_list = []
    # [Description, North, East, South, West]
    maze2_list.append(['Available Directions: East', None, 1, None, None]) #0
    maze2_list.append(['Available Directions: East, South, West', None, 2, 5, 0]) #1
    maze2_list.append(['Available Directions: East, West', None, 3, None, 1]) #2
    maze2_list.append(['Available Directions: West', None, None, None, 2]) #3
    maze2_list.append(['Available Directions: East, South', None, 5, 8, None]) #4
    maze2_list.append(['Available Directions: North, East, West', 1, 6, None, 4]) #5
    maze2_list.append(['Available Directions: East, West', None, 7, None, 5]) #6
    maze2_list.append(['Available Directions: South, West', None, None, 11, 6]) #7
    maze2_list.append(['Available Directions: North, South', 4, None, 12, None]) #8
    maze2_list.append(['Available Directions: East', None, None, 5, 3]) #9
    maze2_list.append(['Available Directions: South, West', None, None, 14, 9]) #10
    maze2_list.append(['Available Directions: North, South', 7, None, 15, None]) #11
    maze2_list.append(['Available Directions: North, East', 8, 13, None, None]) #12
    maze2_list.append(['Available Directions: East, West', None, 12, None, 12]) #13
    maze2_list.append(['Available Directions: North, East', 10, 15, None, 14]) #14

    now_tile = 0
    finished = False

    compass = {'North' or 'north' or 'NORTH':1, 'East' or 'east' or 'EAST':2, 'South' or 'south' or 'SOUTH':3, 'West' or 'west' or 'WEST':4}
    #Source: obtained from <http://ift.tt/2fGcNWR;
    #Date: <October 2, 2017>
    #Name of Author/Programmer: <Anton vBR>

    while not finished:
        print('')
        print(maze2_list[now_tile][0])
        y = '0'
        present = False

        while not present:

            while not compass.get(y.title()): #Source: obtained from <http://ift.tt/2yFgFOX;
                                          #Date: <October 2, 2017>
                                          #Name of Author/Programmer: <Paul Vincent Craven>
                if y!='0':
                    print('Please choose an available direction. ')
                y = input('Which direction will you want to take? \n')

            next_move2 = compass.get(y.title()) #Source: obtained from <http://ift.tt/2yFgFOX;
                                            #Date: <October 2, 2017>
                                            #Name of Author/Programmer: <Paul Vincent Craven>
            next_tile2 = maze2_list[now_tile][next_move2]

            if next_tile2:
                available = True
                now_tile = next_tile2

            else:
                print('Please choose an available direction.')
                y= '0'
        if now_tile == 15:
            print('Congratulations! You found the exit. \nGoodbye.')
            finished = True


def difficult():

    maze3_list = []
    # [Description, North, East, South, West]
    maze3_list.append(['Available Directions: East, South', None, 1, 5, None]) #0
    maze3_list.append(['Available Directions: East, South, West', None, 2, 6, 0]) #1
    maze3_list.append(['Available Directions: East, West', None, 3, None, 1]) #2
    maze3_list.append(['Available Directions: South, West', None, None, 8, 3]) #3
    maze3_list.append(['Available Directions: South', None, None, 9, None]) #4
    maze3_list.append(['Available Directions: North, South', 0, None, 10, None]) #5
    maze3_list.append(['Available Directions: North', 1, None, None, None]) #6
    maze3_list.append(['Available Directions: South', None, None, 12, None]) #7
    maze3_list.append(['Available Directions: North, East, South', 3, 9, 13, None]) #8
    maze3_list.append(['Available Directions: North, West', 4, None, None, 8]) #9
    maze3_list.append(['Available Directions: North, South', 5, 11, None, None]) #10
    maze3_list.append(['Available Directions: South, West', None, None, 16, 10]) #11
    maze3_list.append(['Available Directions: North, East', 7, 13, None, None]) #12
    maze3_list.append(['Available Directions: North, East, West', 8, 14, None, 12]) #13
    maze3_list.append(['Available Directions: South, West', None, None, 19, 13]) #14
    maze3_list.append(['Available Directions: East', None, 16, None, None]) #15
    maze3_list.append(['Available Directions: North, East, South, West', 11, 17, 21, 15]) #16
    maze3_list.append(['Available Directions: South, West', None, None, 21, 16]) #17
    maze3_list.append(['Available Directions: East', None, 19, None, None]) #18
    maze3_list.append(['Available Directions: North, South, West', 14, None, 24, 18]) #19
    maze3_list.append(['Available Directions: East', None, 21, None, None]) #20
    maze3_list.append(['Available Directions: North, West', 16, None, None, 20]) #21
    maze3_list.append(['Available Directions: North, East', 17, 23, None, None]) #22
    maze3_list.append(['Available Directions: East, West', None, 24, None, 22]) #23

    updated_tile = 0
    completed = False

    path = {'North' or 'north' or 'NORTH':1, 'East' or 'east' or 'EAST':2, 'South' or 'south' or 'SOUTH':3, 'West' or 'west' or 'WEST':4}
    #Source: obtained from <http://ift.tt/2fGcNWR;
    #Date: <October 2, 2017>
    #Name of Author/Programmer: <Anton vBR>

    while not completed:
        print('')
        print(maze3_list[updated_tile][0])
        z = '0'
        free = False

        while not free:

            while not path.get(z.title()): #Source: obtained from <http://ift.tt/2yFgFOX;
                                       #Date: <October 2, 2017>
                                       #Name of Author/Programmer: <Paul Vincent Craven>
                if z!='0':
                    print('Please choose an available direction. ')
                z = input('Which direction will you take? \n')


            next_move3 = path.get(z.title()) #Source: obtained from <http://ift.tt/2yFgFOX;
                                         #Date: <October 2, 2017>
                                         #Name of Author/Programmer: <Paul Vincent Craven>
            next_tile3 = maze3_list[updated_tile][next_move3]

            if next_tile3:
                free = True
                updates_tile = next_tile3

            else:
                print('Please choose an available direction.')
                z= '0'
        if updated_tile == 24:
            print('Congratulations! You found the exit. \nGoodbye.')
            completed = True

# I don't know where to insert this quit function
def quit():
    print('Try again next time. \nGoodbye!')

start()

Aucun commentaire:

Enregistrer un commentaire