Exemple #1
0
def write(description, color, sc):  #description - обращение к пользователю
    clock = pygame.time.Clock()     #color - fon
    sc.fill(color)  #здесь очищается весь экран. Тебе не понадобится
    #pygame.init()
    text = []
    f1 = pygame.font.Font(None, 100)   #размер шрифта обращения
    f2 = pygame.font.Font(None, 75)   #размер шрифта ввода
    text1 = f1.render(description, 0, (180, 60, 0))
    sc.blit(text1, (10, 50))   #координаты обращения
    pygame.display.update()
    while 1:
        for i in pygame.event.get():
            if i.type == pygame.KEYDOWN:
                if i.key == pygame.K_ESCAPE:
                    return ''
                if i.key == pygame.K_KP_ENTER or i.key == pygame.K_RETURN:
                    return "".join(text)
                if i.key == pygame.K_BACKSPACE:  # управление: работают кнопки статистика, настройки и выход,
                    if text.__len__():
                     text.pop()
                     sc.fill(color)             #здесь очищается весь экран.
                     sc.blit(text1, (10, 50))   #координаты обращени
                elif text.__len__() < 15:
                    text.append(i.unicode)
                text2 = f2.render("".join(text), 0, (180, 60, 0))
                sc.blit(text2, (10, 250))     #координаты ввода
                pygame.display.update()
            elif i.type == pygame.QUIT:
                for i in ('point.txt', 'record.txt', 'save.txt', 'password.txt'):
                    hashFile(i)
                sys.exit()
        clock.tick(30)
    def on_find_clicked(self, data):
        self.apply_button.set_sensitive(False)
        self.find_button.set_sensitive(False)
        self.filename = self.totem.get_current_mrl()
        self.model.hash , self.model.size = hashFile(self.filename)

        self.os_get_results()
Exemple #3
0
    def on_find_clicked(self, data):
        self.apply_button.set_sensitive(False)
        self.find_button.set_sensitive(False)
        self.filename = self.totem.get_current_mrl()
        self.model.hash, self.model.size = hashFile(self.filename)

        self.os_get_results()
Exemple #4
0
    def search_subtitles(self, filename):
        self.message = ''
        self.hash, self.size = hashFile(filename)

        if self.log_in():
            searchdata = {'sublanguageid': self.LANG,
                          'moviehash'    : self.hash,
                          'moviebytesize': str(self.size)}

            try:
                result = self.server.SearchSubtitles(self.token, [searchdata])
            except xmlrpclib.ProtocolError:
                self.message = 'Could not contact the OpenSubtitles website'

            if result['data']:
                return result['data']
            else:
                self.message = 'No results found'

        return None
Exemple #5
0
def game_play(x, player, mode, image):

    surface_menu.blit(surface_menu, (0, 0))
    surface_menu.fill((70, 40, 70))

    pygame.draw.rect(surface_menu, right_panel, (600, 0, 600, 800))

    map = labGen(x, x)
    size = int(surface_height / x)
    new_image = pygame.transform.scale(image, (size, size))

    xdraw = 0
    ydraw = 0

    for i in range(x):
        for j in range(x):
            if map[i][j] == 2 or map[i][j] == 'f':  # проход
                gamedraw = (100, 150, 100)
                pygame.draw.rect(surface_menu, gamedraw,
                                 (xdraw, ydraw, size, size))
            if map[i][j - 1] == 'f':
                gamedraw = (150, 20, 20)
                pygame.draw.rect(surface_menu, gamedraw,
                                 (xdraw, ydraw, size, size))
            if map[i][j] == 3:  # игрок
                xpl = j * size
                ypl = i * size
                surface_menu.blit(new_image, (xpl, ypl))
            if map[i][j] == 1:  # стена
                gamedraw = (70, 40, 70)
                pygame.draw.rect(surface_menu, gamedraw,
                                 (xdraw, ydraw, size, size))
            xdraw += size
        xdraw = 0
        ydraw += size

    time_out = 0

    done_game = True
    while done_game:

        surface_menu.blit(surface_menu, (0, 0))
        pygame.display.flip()

        font = pygame.font.Font(None, 52)

        time_out += 1
        pygame.draw.rect(surface_menu, right_panel, (600, 0, 600, 800))
        DrawText('время:', font, surface_menu, 610, 50)
        DrawText(str(time_out // 20), font, surface_menu, 610, 90)

        file_name = 'point.txt'
        changed_file = []
        with open(file_name, 'r') as f:  # ищем в файле очки игрока
            for string in f:
                if player in string:
                    items = string.split()
                    points = int(items[1])
                else:
                    changed_file.append(string.rstrip())
        DrawText(player, font, surface_menu, 610, 150)
        DrawText(str(points), font, surface_menu, 610, 190)

        DrawText('размер:', font, surface_menu, 610, 250)
        DrawText(str(x) + 'x' + str(x), font, surface_menu, 610, 290)

        font = pygame.font.Font(None, 72)

        gamedraw = (100, 150, 100)

        for igame in pygame.event.get():
            if igame.type == pygame.KEYDOWN:
                if igame.key == pygame.K_ESCAPE:
                    done_game = False
                elif igame.key == pygame.K_DOWN or igame.key == pygame.K_s:
                    if map[int(ypl / size) + 1][int(
                            xpl / size)] == 2 or map[int(ypl / size) + 1][int(
                                xpl /
                                size)] == 3 or map[int(ypl / size) + 1][int(
                                    xpl / size)] == 'f':
                        pygame.draw.rect(surface_menu, gamedraw,
                                         (xpl, ypl, size, size))
                        ypl += size
                        surface_menu.blit(new_image, (xpl, ypl))
                elif igame.key == pygame.K_UP or igame.key == pygame.K_w:
                    if map[int(ypl / size) - 1][int(
                            xpl / size)] == 2 or map[int(ypl / size) - 1][int(
                                xpl /
                                size)] == 3 or map[int(ypl / size) - 1][int(
                                    xpl / size)] == 'f':
                        pygame.draw.rect(surface_menu, gamedraw,
                                         (xpl, ypl, size, size))
                        ypl -= size
                        surface_menu.blit(new_image, (xpl, ypl))
                elif igame.key == pygame.K_LEFT or igame.key == pygame.K_a:
                    if map[int(
                            ypl / size)][int(xpl / size) - 1] == 2 or map[int(
                                ypl /
                                size)][int(xpl / size) - 1] == 3 or map[int(
                                    ypl / size)][int(xpl / size) - 1] == 'f':
                        pygame.draw.rect(surface_menu, gamedraw,
                                         (xpl, ypl, size, size))
                        xpl -= size
                        surface_menu.blit(new_image, (xpl, ypl))
                elif igame.key == pygame.K_RIGHT or igame.key == pygame.K_d:
                    if map[int(
                            ypl / size)][int(xpl / size) + 1] == 2 or map[int(
                                ypl /
                                size)][int(xpl / size) + 1] == 3 or map[int(
                                    ypl / size)][int(xpl / size) + 1] == 'f':
                        pygame.draw.rect(surface_menu, gamedraw,
                                         (xpl, ypl, size, size))
                        xpl += size
                        surface_menu.blit(new_image, (xpl, ypl))
            if map[int(ypl / size)][int(xpl / size) - 1] == 'f':
                surface_menu.fill(bgcolor)
                time_stop = str(time_out // 20)
                if float(time_stop) < 1:
                    time_stop = '1'

                DrawText('Вы прошли уровень!!!', font, surface_menu,
                         (surface_width / 2) - 350,
                         (surface_height / 2.5) - 220)

                if int(time_stop) // 10 == 1:
                    seconds_draw = ' секунд'
                elif int(time_stop) % 10 == 1:
                    seconds_draw = ' секунда'
                elif int(time_stop) % 10 == 2 or int(
                        time_stop) % 10 == 3 or int(time_stop) % 10 == 4:
                    seconds_draw = ' секунды'
                else:
                    seconds_draw = ' секунд'

                DrawText('Ваше время: ' + time_stop + seconds_draw, font,
                         surface_menu, (surface_width / 2) - 300,
                         (surface_height / 2.5) - 110)

                if mode == 0:
                    delta = add_points(x, x, int(time_stop), player)
                    DrawText('Полученные очки: ' + str(delta), font,
                             surface_menu, (surface_width / 2) - 285,
                             (surface_height / 2.5) - 55)
                    saveGen(player)
                    DrawText('Лабиринт увеличился на 2', font, surface_menu,
                             (surface_width / 2) - 325,
                             (surface_height / 2.5) - 165)
                else:
                    DrawText('Вы не получаете очки((', font, surface_menu,
                             (surface_width / 2) - 285,
                             (surface_height / 2.5) - 55)
                    DrawText('Лабиринт не увеличился((', font, surface_menu,
                             (surface_width / 2) - 325,
                             (surface_height / 2.5) - 165)
                pygame.display.update()

                done_game = False
            elif igame.type == pygame.QUIT:
                for i in ('point.txt', 'record.txt', 'save.txt',
                          'password.txt'):
                    hashFile(i)
                sys.exit()
        clock.tick(20)
Exemple #6
0
def choice_skin():
    global image
    surface_menu.fill(bgcolor)
    font = pygame.font.Font(None, 72)
    DrawText('Выбор персонажа', font, surface_menu, (surface_width / 2) - 220,
             (surface_height / 2.5) - 220)

    x = 100
    y = 100
    x_circle = x - 35
    y_circle = y + 37  # 137

    number = 1

    for i_skin in range(5):
        if i_skin == 0:
            image = pygame.image.load('1.jpg').convert()
        elif i_skin == 1:
            image = pygame.image.load('2.png').convert()
        elif i_skin == 2:
            image = pygame.image.load('3.jpg').convert()
        elif i_skin == 3:
            image = pygame.image.load('4.jpg').convert()
        elif i_skin == 4:
            image = pygame.image.load('5.jpg').convert()
        new_image = pygame.transform.scale(image, (70, 70))
        surface_menu.blit(new_image, (x, y))
        y += 80

    done_skin = True
    while done_skin:
        surface_menu.blit(surface_menu, (0, 0))

        pygame.display.flip()

        pygame.draw.circle(surface_menu, font_color, (x_circle, y_circle), 27)

        for i_skin in pygame.event.get():  # цикл с событиями
            if i_skin.type == pygame.KEYDOWN:
                if i_skin.key == pygame.K_ESCAPE:
                    done_skin = False
                if i_skin.key == pygame.K_w or i_skin.key == pygame.K_UP:
                    pygame.draw.circle(surface_menu, bgcolor,
                                       (x_circle, y_circle), 27)
                    if y_circle == 137:
                        y_circle = 457
                        number = 5
                    else:
                        y_circle -= 80
                        number -= 1
                if i_skin.key == pygame.K_s or i_skin.key == pygame.K_DOWN:
                    pygame.draw.circle(surface_menu, bgcolor,
                                       (x_circle, y_circle), 27)
                    if y_circle == 457:
                        y_circle = 137
                        number = 1
                    else:
                        y_circle += 80
                        number += 1
                pygame.draw.circle(surface_menu, font_color,
                                   (x_circle, y_circle), 27)
                if i_skin.key == pygame.K_e or i_skin.key == pygame.K_KP_ENTER:
                    if number == 1:
                        image = pygame.image.load('1.jpg').convert()
                    elif number == 2:
                        image = pygame.image.load('2.png').convert()
                    elif number == 3:
                        image = pygame.image.load('3.jpg').convert()
                    elif number == 4:
                        image = pygame.image.load('4.jpg').convert()
                    elif number == 5:
                        image = pygame.image.load('5.jpg').convert()
                    done_skin = False

            if i_skin.type == pygame.QUIT:
                for i in ('point.txt', 'record.txt', 'save.txt',
                          'password.txt'):
                    hashFile(i)
                sys.exit()
Exemple #7
0
def main():

    if (len(sys.argv) < 2):
        print('Error! Pass the path of the video file as an argument.')
        sys.exit(0)

    else:
        # Proxy to the opensubtitles api
        opensubtitles_server_proxy = xmlrpc.client.ServerProxy(
            "http://api.opensubtitles.org/xml-rpc")

        # Login to the server to get the token
        login_details = opensubtitles_server_proxy.LogIn(
            '', '', 'eng', user_agent)
        token = login_details['token']

        # Get the path to the file for which we need the subtitles
        file = sys.argv[1]

        # Get the hash of the video and the size in bytes
        (moviehash, moviebytesize) = hashFile(file)
        moviebytesize = str(moviebytesize)

        # Param to search for the subtitles
        movie_details = [{
            'sublanguageid': 'eng',
            'moviehash': moviehash,
            'moviebytesize': moviebytesize
        }]

        # Search for subtitles
        subtitle_details = opensubtitles_server_proxy.SearchSubtitles(
            token, movie_details)
        subs = subtitle_details['data']

        # If more than 1 subtitle is found, prompt user for the choice
        if (len(subs) > 1):
            print('Choose the subtitle: \n')
            for i in range(len(subs)):
                print("%d. %s" % (i + 1, subs[i]['SubFileName']))

            choice = input("Enter your choice (%d-%d): " % (1, len(subs)))
            choice = int(choice)

            if (choice < 1 or choice > len(subs)):
                print('Invalid choice! Exiting')
                sys.exit(0)

        elif (len(subs) > 0):
            choice = 1

        else:
            print('No subtitles found! Exiting.')
            sys.exit(0)

        # Index is 1 less than the choice value
        ind = choice - 1

        # Get the url of the subtitle
        sub_url = subs[ind]['SubDownloadLink']
        r = requests.get(sub_url)

        # Download the subtitle
        with open(subs[ind]['SubFileName'], 'wb') as f:

            print("Downloading %s" % (subs[ind]['SubFileName']))
            response = requests.get(sub_url, stream=True)
            total_length = response.headers.get('content-length')

            if total_length is None:  # no content length header
                f.write(response.content)
            else:
                dl = 0
                total_length = int(total_length)
                for data in response.iter_content(chunk_size=4096):
                    dl += len(data)
                    f.write(data)
                    done = int(50 * dl / total_length)
                    sys.stdout.write("\r[%s%s] %d%%" % ('=' * done, ' ' *
                                                        (50 - done), done * 2))
                    sys.stdout.flush()
Exemple #8
0
def exit():
    for i in ('point.txt', 'record.txt', 'save.txt', 'password.txt'):
        hashFile(i)
    sys.exit()