def main():
    engine = create_engine("sqlite:///cinema.db")
    Base.metadata.create_all(engine)
    session = Session(bind=engine)
    cinema_city = Cinema(session)
    new_movies_and_projections_in_cinema(cinema_city)
    command_parser = CommandParser()
    command_parser.add_command("show_movies", cinema_city.show_movies)
    cinema_city.show_movies(session)
    command = input(">>>")
    command_parser.run_command(command)
def main():
    fill_with_questions(session)
    command_parser = CommandParser()
    command_parser.add_command("begin", begin_interaction_with_user)
    command_parser.add_command("start", start_game)
    command_parser.add_command("highscores", show_highscores)
    command_parser.add_command("finish", finish)
    command_parser.run_command("begin")
    command = prompt_for_input()
    command_parser.run_command(command)
    while command != "finish":
        command = prompt_for_input()
        command_parser.run_command(command)
def main():
    fill_with_questions(session)
    command_parser = CommandParser()
    command_parser.add_command("begin", begin_interaction_with_user)
    command_parser.add_command("start", start_game)
    command_parser.add_command("highscores", show_highscores)
    command_parser.add_command("finish", finish)
    command_parser.run_command("begin")
    command = prompt_for_input()
    command_parser.run_command(command)
    while command != "finish":
        command = prompt_for_input()
        command_parser.run_command(command)
class CLI:
    def __init__(self):
        self.game = Game()
        self.command_parser = CommandParser()
        self.init_command_parser()
        print('Welcome to the "Do you even math?" game!')

    def init_command_parser(self):
        self.command_parser.add_command('start', self.start)
        self.command_parser.add_command('highscores', self.print_highscores)
        self.command_parser.add_command('exit', self.exit)

    def start_menu(self):
        print('''
Here are your options:
- start
- highscores
- exit''')
        command = input('?> ')
        self.command_parser.execute(command)

    def start(self):
        username = input('Enter your playername>')
        print('Welcome {}! Let the game begin!'.format(username))
        self.game.register(username)
        while not self.game.is_over:
            self.game.generate_new_question()
            print('Question #{}:'.format(self.game.level))
            print(self.game.get_expression_string())
            try:
                answer = int(input('?> '))
            except ValueError:
                print('Answer must be an integer!')
            if self.game.give_answer(answer):
                print('Correct')
            else:
                print(
                    '''Incorrect! Answer was {}. Ending game. You score is: {}'''
                    .format(self.game.get_answer(), self.game.get_score()))
                self.game.restart()
                self.start_menu()

    def print_highscores(self):
        print(self.game.get_highscores_string())
        self.start_menu()

    def exit(self):
        import sys
        sys.exit()
class CLI:

    def __init__(self):
        self.game = Game()
        self.command_parser = CommandParser()
        self.init_command_parser()
        print('Welcome to the "Do you even math?" game!')

    def init_command_parser(self):
        self.command_parser.add_command('start', self.start)
        self.command_parser.add_command('highscores', self.print_highscores)
        self.command_parser.add_command('exit', self.exit)

    def start_menu(self):
        print('''
Here are your options:
- start
- highscores
- exit''')
        command = input('?> ')
        self.command_parser.execute(command)

    def start(self):
        username = input('Enter your playername>')
        print('Welcome {}! Let the game begin!'.format(username))
        self.game.register(username)
        while not self.game.is_over:
            self.game.generate_new_question()
            print('Question #{}:'.format(self.game.level))
            print(self.game.get_expression_string())
            try:
                answer = int(input('?> '))
            except ValueError:
                print('Answer must be an integer!')
            if self.game.give_answer(answer):
                print('Correct')
            else:
                print('''Incorrect! Answer was {}. Ending game. You score is: {}'''.format(
                    self.game.get_answer(), self.game.get_score()))
                self.game.restart()
                self.start_menu()

    def print_highscores(self):
        print(self.game.get_highscores_string())
        self.start_menu()

    def exit(self):
        import sys
        sys.exit()
Example #6
0
def create_command_parser():
    command_parser = CommandParser()
    command_parser.add_command('show_movies', show_movies)
    command_parser.add_command('show_movie_projections',
                               show_movie_projections)
    command_parser.add_command('make_reservation', make_reservation)
    command_parser.add_command('cancel_reservation', cancel_reservation)
    command_parser.add_command('exit', exit)
    command_parser.add_command('help', show_help)
    return command_parser
def create_command_parser():
    command_parser = CommandParser()
    command_parser.add_command('show_movies', show_movies)
    command_parser.add_command(
        'show_movie_projections', show_movie_projections)
    command_parser.add_command('make_reservation', make_reservation)
    command_parser.add_command('cancel_reservation', cancel_reservation)
    command_parser.add_command('exit', exit)
    command_parser.add_command('help', show_help)
    return command_parser