Exemplo n.º 1
0
    def start(self):
        menu = Menu([
            Option("1", "Read and load maze from file", self.load_maze),
            Option("2", "View maze", self.view_maze),
            Option("3", "Play maze game", self.play_maze),
            Option("4", "Configure current maze", self.edit_maze),
            Option("0", "Exit maze", self.end),
        ])

        while not self.ended:
            os.system('cls' if os.name == 'nt' else 'clear')
            print("Main menu")
            print("=========")
            print(menu.render())
            if not menu.select(input("Enter your option: ")):
                print("Invalid menu option, try again!")
                input("Press Enter to continue...")
            print()
Exemplo n.º 2
0
    def start(self):
        while not self.ended:
            os.system('cls' if os.name == 'nt' else 'clear')
            self.field.enter(Player())
            print(self.field.render())
            print()
            print("Configuration Menu")
            print("==================")

            menu = Menu([
                Option("1", "Create wall", self.create_wall),
                Option("2", "Create passageway", self.create_passageway),
                Option("3", "Create start point", self.create_start_point),
                Option("4", "Create end point", self.create_end_point),
                Option("0", "Exit to Main Menu", lambda: self.end()),
            ])
            print(menu.render())
            selection = input("Enter your option: ")
            menu.select(selection)
Exemplo n.º 3
0
def test_menu_render():
    option1 = Option("1", "Option 1", lambda: None)
    option2 = Option("2", "Option 2", lambda: None)
    menu = Menu([option1, option2])
    assert menu.render() == "[1] Option 1\n[2] Option 2"