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 test_intransitive_commands_should_not_throw_exceptions(self):
     for word in self.words:
         game = Game()
         load_advent_dat(game)
         game.start()
         game.do_command(['no'])  # WOULD YOU LIKE INSTRUCTIONS?
         game.do_command([word])
Exemplo n.º 3
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.º 4
0
    def setUp(self):
        self.data = Mock()
        self.player = Mock()
        self.token_processor = Mock()
        self.token_processor.process_tokens.return_value = "goodbye"

        self.game = Game(self.data, self.player)
        self.game.token_processor = self.token_processor
Exemplo n.º 5
0
    def start(self) -> str:
        if self.game:
            raise GameAlreadyStartedError

        self.game = Game()
        adventure.load_advent_dat(self.game)
        self.game.start()
        return self.game.output
 def maybe_end_game(self):
     # end game if no interaction for 10 mins
     if self.playing:
         timed_out = time.time() - self.last_interaction > 10 * 3600
         # disable save and gameplay
         if self.game.is_finished or timed_out:
             self.disable_intent("Save")
             self.playing = False
             self.game = Game()
             load_advent_dat(self.game)
         # save game to allow restoring if timedout
         if timed_out:
             self.handle_save()
Exemplo n.º 7
0
    def parse_file(self, json_content):
        resolvers = self.init_resolvers()

        data, player, validation = self.parse_content(json_content, resolvers)
        if validation:
            with open(DataParser.VALIDATION_MESSAGE_FILENAME,
                      "w") as validation_file:
                for validation_line in validation:
                    validation_file.write(
                        validation_line.get_formatted_message() + "\n")
            print("Validation errors found, see {0}.".format(
                DataParser.VALIDATION_MESSAGE_FILENAME))

        resolvers.argument_resolver.init_data(data)
        resolvers.command_handler.init_data(data)
        resolvers.vision_resolver.init_data(data)
        resolvers.event_resolver.init_data(data)
        resolvers.life_resolver.init_data(data)

        return Game(data, player)
Exemplo n.º 8
0
 def setUp(self):
     game = Game()
     load_advent_dat(game)
     self.words = set(w.synonyms[0].text for w in game.vocabulary.values())
     self.words.remove('suspend')
Exemplo n.º 9
0
 def help_prompt() -> str:
     game = Game()
     adventure.load_advent_dat(game)
     return str(game.messages[51])
 def initialize(self):
     self.game = Game()
     load_advent_dat(self.game)
     self.last_interaction = time.time()
     self._init_padatious()
     self.disable_intent("save.intent")