示例#1
0
def main():
    player = Player(get_player_name())   #get input for player name
    intro(player.first_name)   #format player name into intro text
    rooms = init_rooms()
    house = House(rooms,rooms[0])
    map = house.init_house_graph()

    #state machine loop
    while True:
        room_in = house.get_current_room()
        room_in.print_text()
        choice = get_direction()
        next_rooms = room_in.get_adjacent()

        #these if statements index the list of adjacent rooms to move to next room
        if choice == 'F':
            if next_rooms[0] != '':
                print(next_rooms[0])
                house.set_current_room(next_rooms[0])
            else:
                print("can't go that way...")
        if choice == 'B':
            if next_rooms[1] != '':
                house.set_current_room(next_rooms[1])
            else:
                print("can't go that way...")
        if choice == 'R':
            if next_rooms[2] != '':
                house.set_current_room(next_rooms[2])
            else:
                print("can't go that way...")
        if choice == 'L':
            if next_rooms[3] != '':
                house.set_current_room(next_rooms[3])
            else:
                print("can't go that way...")
        if choice == 'U':
            if next_rooms[4] != '':
                house.set_current_room(next_rooms[4])
            else:
                print("can't go that way...")
        if choice == 'D':
            if next_rooms[5] != '':
                house.set_current_room(next_rooms[5])
            else:
                print("can't go that way...")
        if choice == 'Q':
            break