Exemple #1
0
def save():
    global timer
    if time.time() - timer > 3600:
        level.save()
        commands.save()
        timer = time.time()
        logging.debug("Saving...")
Exemple #2
0
def on_message(message):
    save()
    if message.content is "save" and message.author.id is client.user.id:
        level.save()
        commands.save()
        permission.save()
        logging.debug("Saving...")

    level.tick()
    level.process_message(message=message)
    if message.content.lower().startswith(
            '!block') and permission.has_permission(message.author.id) == 0:
        yield from commands.block(message=message, client=client)
    elif message.content.lower().startswith(
            '!unblock') and permission.has_permission(message.author.id) == 0:
        yield from commands.unblock(message=message, client=client)
    elif message.content.lower().startswith('!status'):
        yield from level.status(message=message, client=client)

    elif message.content.lower().startswith(
            '!givexp') and permission.has_permission(message.author.id) <= 1:
        yield from level.give_exp(message=message, client=client)

    elif message.content.lower().startswith(
            '!takexp') and permission.has_permission(message.author.id) <= 1:
        yield from level.take_exp(message=message, client=client)

    elif message.content.lower().startswith(
            '!setxp') and permission.has_permission(message.author.id) <= 1:
        yield from level.set_exp(message=message, client=client)

    elif message.content.lower().startswith(
            '!top') and permission.has_permission(message.author.id) <= 3:
        yield from level.top(message=message, client=client)
 def save_2(self, dt=0):
     self.busy = False
     path = gui.save_file(default_name="Level_.yaml")
     graphics.main_window.set_fullscreen(True)
     if path == None: return
     level.save(path)
     pyglet.clock.schedule_once(self.save_3, 0.5)
     self.busy = True
Exemple #4
0
 def __init__(self, screen, lvl, lvl_name):
     Menu.__init__(self, screen, [], '')
     if lvl_name != '__NEW__':
         level.save(lvl_name, lvl)
         self.quit()
     self.label = self.reg_font.render('Name:', True, (0,0,0))
     self.name = ''
     self.lvl = lvl
     self.topleft = (300, 200)
     self.shift = False
Exemple #5
0
 def EVT_tick(self,event):
     if self.delay:
         self.delay -= 1
     else:
         filename = Campaign.next(self.level.replace('\\','/'))
         if filename:
             lvl = level.load(filename)
             level.save(lvl,'save.lvl')
             self.quit(GameState(lvl))
         else:
             self.quit(Ending())
def offer_moves(lvl, player_x, player_y):
    """
    offer player to do move
        :param str lvl: string representation of level
        :param int player_x: current x-position of player
        :param int player_y: current y-position of player
        :return: delta x, y coords
        :rtype: tuple
    """

    dungeon_game_logger.logger.debug('offering moves to player')
    lvl_size = level.size(lvl)

    up_cell = level.get_cell(lvl, player_x, player_y - 1)
    down_cell = level.get_cell(lvl, player_x, player_y + 1)
    left_cell = level.get_cell(lvl, player_x - 1, player_y)
    right_cell = level.get_cell(lvl, player_x + 1, player_y)

    message = f'# - wall (dead end)\n$ - treasure\n! - trap\n_ - empty space\np - player\n'
    env_message = '{:^3}\n{}p{}\n{:^3}\n'.format(up_cell, left_cell, right_cell, down_cell)

    dungeon_game_logger.logger.info(message)

    if up_cell == '!' or down_cell == '!' or left_cell == '!' or right_cell == '!':
        dungeon_game_logger.logger.info('Trap somewhere!')

    if up_cell == '$' or down_cell == '$' or left_cell == '$' or right_cell == '$':
        dungeon_game_logger.logger.info('Treasure somewhere!')

    dungeon_game_logger.logger.info(env_message)

    while True:

        move = input('Enter your move (`left`, `right`, `up`, `down` or `save`): ')

        if move == 'save':
            level.save(lvl, player_x, player_y)
            dungeon_game_logger.logger.info('Game saved')
        elif move not in MOVES:
            dungeon_game_logger.logger.info('Wrong input! It should be one of this: `left`, `right`, `up`, `down`')
        else:
            break

    return MOVES[move]
Exemple #7
0
    def check_mode_change(self):
        if gui.current_card == 1:
            # unpause
            self.toggle_pause()
        if gui.current_card == RETURN_FROM_CHOOSE:
            self.mode = PLAYING
            gui.current_card = None
        if gui.next_card == 3:
            # end game
            self.parent.stop_game()
        if event.next_level == "win" and gui.current_card == 4:
            self.mode = PLAYING
            self.parent.stop_game()
            return
        if gui.current_card == 5:
            # restart game
            level.player = None
            level.restart_countdown = 0

        if level.player == None or event.end_game:
            if event.start_countdown:
                event.start_countdown = False
                level.restart_countdown = 3.0
            if level.restart_countdown > 0:
                event.message = "Mission Failed"
                event.message_countdown = 3.0
                level.restart_countdown -= env.dt
            else:
                set, path = save.most_recent_save()
                self.init_from_save(path)
        self.check_cutscene()
        if self.mode != CUTSCENE and event.next_level not in ["", "win"]:
            self.loading = True
            level.save()
            self.clean_up_game()
            if event.prefer_saved:
                load_path = save.get_save(event.next_level)
                if load_path != "":
                    self.init_from_save(load_path, True, True)
                    return
            self.init_game(event.next_level, event.keep_ship_config, event.keep_ship_velocity)
Exemple #8
0
 def check_cutscene(self):
     if gui.current_card == 4:
         self.mode = PLAYING
         gui.current_card = None
         for s, l in env.key_bindings.items():
             if self.keys[s]:
                 for u in l:
                     u.activate()
         level.save()
         timer.unpause()
         self.fade_countdown = 0.5
     if len(event.cutscene_queue) > 0:
         for u in physics.unit_update_list:
             if u.uses_keys:
                 u.deactivate()
         self.mode = CUTSCENE
         timer.pause()
         cutscene_card = cutscene.Cutscene("Data/Cutscenes/" + event.cutscene_queue[0] + ".txt", gui.state_goer(4))
         event.cutscene_queue = event.cutscene_queue[1:]
         gui.current_card = cutscene_card
         gui.next_card = None
         gui.transition_time = 0.5
Exemple #9
0
 def EVT_KeyDown(self, event):
     if event.key == pygame.K_ESCAPE:
         self.quit()
     elif event.key == pygame.K_BACKSPACE:
         if len(self.name) > 0:
             self.name = self.name[:-1]
     elif pygame.key.name(event.key).startswith('['):
         if pygame.key.name(event.key)[1:-1] in digits:
             self.name += pygame.key.name(event.key)[1:-1]
     elif pygame.key.name(event.key) in digits:
         if pygame.key.name(event.key) in digits:
             self.name += pygame.key.name(event.key)
     elif pygame.key.name(event.key) in lowercase:
         if self.shift:
             self.name += pygame.key.name(event.key).upper()
         else:
             self.name += pygame.key.name(event.key)
     elif event.key in [pygame.K_RSHIFT, pygame.K_LSHIFT]:
         self.shift = True
     elif event.key in [pygame.K_RETURN, 271] and self.name != '':
         level.save(self.name, self.lvl)
         self.quit()
Exemple #10
0
        yield from level.top(message=message, client=client)


def save():
    global timer
    if time.time() - timer > 3600:
        level.save()
        commands.save()
        timer = time.time()
        logging.debug("Saving...")


if __name__ == "__main__":
    logging.basicConfig(filename=config.LOG_PATH,
                        filemode='w',
                        level=logging.DEBUG)
    timer = time.time()
    commands.load()
    level.load()
    permission.load()
    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(client.start(config.BOT_TOKEN))
    except (KeyboardInterrupt, Exception):
        loop.close()
        client.logout()
        running = False
    finally:
        level.save()
        commands.save()
Exemple #11
0
 def init_from_save(self, path, keep_config=False, keep_velocity=False):
     self.init_pre_load(keep_config)
     level.load_save_from_path(path, keep_config, keep_velocity)
     self.init_post_load()
     level.save()
Exemple #12
0
 def init_game(self, level_name, keep_config=False, keep_velocity=False):
     self.init_pre_load(keep_config)
     level.load(level_name, keep_config, keep_velocity)
     self.init_post_load()
     level.save()
Exemple #13
0
 def EVT_Menu_Yes(self,event):
     level.save(self.pausestate.gamestate.level,'save.lvl')
     self.quit(self.pausestate.gamestate)
Exemple #14
0
 def EVT_Menu_SaveGame(self,event):
     if not os.path.exists('save.lvl'):
         level.save(self.gamestate.level,'save.lvl')
         self.quit(self.gamestate)
     else:
         self.quit(Overwrite(self))
Exemple #15
0
 def save(self):
     path = gui.save_file(default_name="Level_.yaml")
     if path == None: return
     level.save(path)
Exemple #16
0
def autosave():
    level.save()