当前位置: 首页>>代码示例>>Python>>正文


Python Commands.show_movie_name方法代码示例

本文整理汇总了Python中commands.Commands.show_movie_name方法的典型用法代码示例。如果您正苦于以下问题:Python Commands.show_movie_name方法的具体用法?Python Commands.show_movie_name怎么用?Python Commands.show_movie_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在commands.Commands的用法示例。


在下文中一共展示了Commands.show_movie_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from commands import Commands [as 别名]
# 或者: from commands.Commands import show_movie_name [as 别名]
class ConsoleInterface:

    OCCUPIED_PLACE = 'X'

    def __init__(self):

        self.database = Commands('cinema.db')
        self.commands = {
            "show_movies": self.show_movies,
            "show_movie_projections": self.show_movie_projections,
            "grid": self.print_grid,
            "make_reservation": self.make_reservation,
            "finalize": self.finalize,
            "give_up": self.give_up,
            # "cancel_reservation": self.cancel_reservation,
            "exit": self.exit,
            "help": self.help
        }
        self.tuple_list = []

    def read_command(self):
        user_input = input('>')
        arguments = user_input.split(" ")[1:]
        function = ''.join(user_input.split(" ")[0:1])
        self.commands[function](*arguments)

    def show_movies(self):
        movies = self.database.show_movies()
        print('Current movies:')
        for movie in movies:
            print(
                '[{}] - {} ({})'.format(movie['movie_id'], movie['name'], movie['rating']))

    def show_movie_projections(self, movie_id, reservation=False):
        projections = self.database.show_movie_projections(movie_id)
        label = True
        for projection in projections:
            if label:
                print('Projections for {}:'.format(projection['name']))
                label = False
            if reservation is True:
                print('[{}] - {} {} ({}) - {} spots available'.format(projection['projection_id'], projection[
                      'date_projection'], projection['time'], projection['type'], 100 - projection['seats']))
            else:
                print('[{}] - {} {} ({})'.format(projection['projection_id'],
                                                 projection['date_projection'], projection['time'], projection['type']))

    def make_reservation(self):

        name = input('Step 1 (User): Choose name>')
        if name == "give_up":
            self.give_up()
        tickets = input('Step 1 (User): Choose number of tickets>')
        if tickets == "give_up":
            self.give_up()
        self.show_movies()

        movie_id = input('Step 2 (Movie): Choose a movie>')
        if movie_id == "give_up":
            self.give_up()
        self.show_movie_projections(movie_id, reservation=True)

        projection_id = input('Step 3 (Projection): Choose a projection>')
        if projection_id == "give_up":
            self.give_up()
        print('Available seats (marked with a dot):')

        self.print_grid(projection_id)
        self.manage_tickets(tickets, projection_id)
        self.print_reservation_info(movie_id, projection_id, self.tuple_list)

        command = input('Step 5 (Confirm - type "finalize") >')
        if command == 'finalize':
            self.finalize(name, projection_id, self.tuple_list)
        if command == "give_up":
            self.give_up()

    def manage_tickets(self, tickets, projection_id):
        grid = self.database.available_seats(projection_id)
        step = 1

        while (step - 1) != int(tickets):
            user_input = input('Step 4 (Seats): Choose seat {}>'.format(step))
            seat = eval(user_input)
            row = seat[0]
            col = seat[1]
            if row > 10 or col > 10 or row == 0 or col == 0:
                print('Lol...NO!')
            elif grid[row][col] == self.OCCUPIED_PLACE:
                print('This seat is already taken!')
            else:
                self.tuple_list.append((row, col))
                step += 1
        print(self.tuple_list)

    def print_reservation_info(self, movie_id, projection_id, tuple_list):
        movie_name = self.database.show_movie_name(movie_id)
        proj = self.database.show_movie_projection_info(projection_id)
        print('This is your reservation:')
        print('Movie: {} ({})'.format(
#.........这里部分代码省略.........
开发者ID:yordanovagabriela,项目名称:Cinema-Reservation-System,代码行数:103,代码来源:console_interface.py


注:本文中的commands.Commands.show_movie_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。