Пример #1
0
class Updater:
    def __init__(self):
        self.load_config() 
        self.anime = Anime(self.cache_dir)
        self.downloader = Subscribe(self.list_path, self.cache_dir, self.aria2_url, self.aria2_dir)

    def load_config(self):
        self.main_dir = os.path.abspath(os.path.dirname(__file__))
        try: 
            with open(os.path.join(self.main_dir,"config.json"), 'r',  encoding='utf8') as f:
                config = json.load(f)

            self.log_dir = path_format(config["log_dir"])
            if not os.path.isdir(self.log_dir):
                raise Exception("log dir not exist!") 

            # aria2 parameter
            self.aria2_dir = path_format(config["download_dir"])
            self.aria2_url = config["aria2"]

            # two log files
            self.error_log = self.log_dir + "error.log"
            self.update_log = self.log_dir + "update.log"
            logs._init(self.error_log, self.update_log)

            # list file path
            self.list_path = self.log_dir + "mylist.json"
            if not os.path.isfile(self.list_path):
                raise Exception("list.json not exist!")

            # cache dir path: ./log/cache/
            self.cache_dir = self.log_dir + "cache/"
            if not os.path.isdir(self.cache_dir):
                os.makedirs(self.cache_dir)

        except Exception as e:
            print("[error] init: {}".format(e))
            os._exit(1)

    def update(self):
        self.anime.update()

    def download(self):
        self.downloader.download() 
Пример #2
0
def game():
    group = pygame.sprite.Group()
    player_anim = Anime(group, (228, 288))
    board = Board.load_map(None, name)
    board.set_view(30, 30, 30)
    lst = []
    if sum(board.hero[0]):
        player = Player(screen, player_anim, board, board.hero[0])
        player_anim.resize(30)
    if sum(board.hero[1]):
        tverdolobiy = Tverdolobiy(group, board.hero[1], board, player)
        tverdolobiy.resize(30)
        lst.append(tverdolobiy)
    if sum(board.hero[2]):
        merzopakostniy = Merzopakostniy(group, board.hero[2], board, player)
        merzopakostniy.resize(30)
    if sum(board.hero[3]):
        legushka = Legushka(group, board.hero[3], board, player)
        legushka.resize(30)
        lst.append(legushka)
    running = True
    c = 0
    while running:
        c += 1
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == pygame.MOUSEBUTTONDOWN:
                board.get_click(event.pos)
            if event.type == pygame.KEYDOWN:
                if event.key in up:
                    player.set_dir('up')
                if event.key in down:
                    player.set_dir('down')
                if event.key in left:
                    player.set_dir('left')
                if event.key in right:
                    player.set_dir('right')
                if event.key == pygame.K_LEFT:
                    player.set_dir('left')
                if event.key == pygame.K_RIGHT:
                    player.set_dir('right')
                if event.key == pygame.K_UP:
                    player.set_dir('up')
                if event.key == pygame.K_DOWN:
                    player.set_dir('down')
        screen.fill((0, 0, 0))
        board.render()
        if not len(board.check_points):
            board.check_points.add(None)
        if not board.are_left():
            board.reset()
        player.move([])
        player_anim.rect.x, player_anim.rect.y = player.x, player.y
        if sum(board.hero[2]):
            merzopakostniy.move()
        if not c % 2:
            if sum(board.hero[3]):
                legushka.move()
            if sum(board.hero[1]):
                tverdolobiy.move()
        group.draw(screen)
        if c % 20 == 0:
            player_anim.update()
        if sum(board.hero[2]):
            check = Check(player, merzopakostniy.num_bomb() + lst)
        elif sum(board.hero[0]):
            check = Check(player, lst)
        if check.checkaed():
            running = False
        draw(str(len(board.check_points) - 1 + board.count))
        pygame.display.flip()
    Finish(group, str(len(board.check_points) - 1 + board.count))