Exemplo n.º 1
0
 def __init__(self, event, conversation):
     match = self.regex.match(event['body'])
     if not match:
         if Adventure in conversation.data:
             game = conversation.data[Adventure]
             words = re.findall('\w+', event['body'])
             event.reply(game.do_command(words).strip()).send()
             if not game.is_finished:
                 conversation.handler = Adventure
         else:
             log.warn('An adventure session was lost.')
             event.reply('You have to start an adventure first.').send()
     elif match.group('cmd') == 'start':
         game = Game()
         load_advent_dat(game)
         savefile = settings['textadventure']['file'].format(conversation.jid)
         game.i_suspend = _make_suspend(game, savefile)
         game.t_suspend = game.i_suspend
         game.start()
         conversation.handler = Adventure
         event.reply(game.output.strip()).send()
         conversation.data[Adventure] = game
     else:
         savefile = settings['textadventure']['file'].format(conversation.jid)
         game = Game.resume(savefile)
         game.i_suspend = _make_suspend(game, savefile)
         game.t_suspend = game.i_suspend
         event.reply('GAME RESTORED').send()
         conversation.handler = Adventure
         conversation.data[Adventure] = game
Exemplo n.º 2
0
def loop(args):
    parser = argparse.ArgumentParser(
        description='Adventure into the Colossal Caves.',
        prog='{} -m adventure'.format(os.path.basename(sys.executable)))
    parser.add_argument('savefile',
                        nargs='?',
                        help='The filename of game you have saved.')
    args = parser.parse_args(args)

    if args.savefile is None:
        game = Game()
        load_advent_dat(game)
        game.start()
        baudout(game.output)

    else:
        game = Game.resume(args.savefile)
        baudout('GAME RESTORED\n')

    while not game.is_finished:
        # line = input('> ').lower()
        # words = re.findall(r'\w+', line)
        line = recognition()
        line = line.lower()
        words = re.findall(r'\w+', line)
        print(words)
        if words:
            baudout(game.do_command(words))
Exemplo n.º 3
0
 def __init__(self, event, conversation):
     match = self.regex.match(event['body'])
     if not match:
         if Adventure in conversation.data:
             game = conversation.data[Adventure]
             words = re.findall('\w+', event['body'])
             event.reply(game.do_command(words).strip()).send()
             if not game.is_finished:
                 conversation.handler = Adventure
         else:
             log.warn('An adventure session was lost.')
             event.reply('You have to start an adventure first.').send()
     elif match.group('cmd') == 'start':
         game = Game()
         load_advent_dat(game)
         savefile = settings['textadventure']['file'].format(
             conversation.jid)
         game.i_suspend = _make_suspend(game, savefile)
         game.t_suspend = game.i_suspend
         game.start()
         conversation.handler = Adventure
         event.reply(game.output.strip()).send()
         conversation.data[Adventure] = game
     else:
         savefile = settings['textadventure']['file'].format(
             conversation.jid)
         game = Game.resume(savefile)
         game.i_suspend = _make_suspend(game, savefile)
         game.t_suspend = game.i_suspend
         event.reply('GAME RESTORED').send()
         conversation.handler = Adventure
         conversation.data[Adventure] = game
Exemplo n.º 4
0
def resume(savefile, quiet=False):
    global _game

    _game = Game.resume(savefile)
    install_words(_game)
    if not quiet:
        print('GAME RESTORED\n')
 def handle_restore(self, message):
     if exists(self.save_file):
         self.playing = True
         self.game = Game.resume(self.save_file)
         self.speak_dialog("restore.game")
     else:
         self.speak_dialog("save.not.found")
         new_game = self.ask_yesno("new.game")
         if new_game:
             self.handle_play()
Exemplo n.º 6
0
    def resume(self, save: io.BytesIO) -> None:
        if self.game:
            raise GameAlreadyStartedError

        self.game = Game.resume(save)