Ejemplo n.º 1
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))
Ejemplo 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])
Ejemplo 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
Ejemplo n.º 4
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
Ejemplo 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()
Ejemplo n.º 7
0
    def process_message(self, message):
        if "subtype" in message:
            if message["subtype"] == "message_changed":
                self.process_message(message["message"])
                return

        text = message["text"].lower()
        if not text.startswith(self.short_name + ":"):
            return

        cmd = text[len(self.short_name) + 1:].strip()  # Get actual command
        splt_cmd = cmd.split()

        if (splt_cmd[0] == "restart"):
            self.game = adventure.game.Game()
            adventure.load_advent_dat(self.game)
            self.game.start()
            self.saypush(utils.correct_case(self.game.output))
            self.saypush("(Use \"ad: <command>\")")
        elif (splt_cmd[0] == "save"):
            if len(splt_cmd) >= 2:
                filename = str(splt_cmd[1]) + ".adv"
                self.game.output = ""
                self.game.t_suspend("save", filename)
                self.saypush(utils.correct_case(self.game.output))
            else:
                self.game.output = ""
                self.game.t_suspend("save", self.savefile)
                self.saypush(utils.correct_case(self.game.output))
        elif (splt_cmd[0] == "load"):
            if len(splt_cmd) >= 2:
                filename = str(splt_cmd[1]) + ".adv"
                if not os.path.isfile(filename):
                    self.saypush("No file with that name!")
                else:
                    self.game = adventure.game.Game.resume(filename)
                    self.saypush(utils.correct_case(self.game.do_command(["look"])))
            else:
                self.game = adventure.game.Game.resume(self.savefile)
                self.saypush(utils.correct_case(self.game.do_command(["look"])))
        elif (splt_cmd[0] == "saves"):
            self.say("Save files:\n")
            for f in os.listdir("."):
                if f.endswith(".adv"):
                    self.say("\t" + f + "\n")
            self.push()
        else:
            self.saypush(utils.correct_case(self.game.do_command(splt_cmd)))
Ejemplo n.º 8
0
    def __init__(self, api_key, channel):
        super(AdventureBot, self).__init__(api_key, channel)

        self.short_name = "ad"
        self.savefile = "main.adv"

        self.game = None

        if not os.path.isfile(self.savefile):
            self.game = adventure.game.Game()
            adventure.load_advent_dat(self.game)
            self.game.start()
            self.saypush(utils.correct_case(self.game.output))
            self.saypush("(Use \"ad: <command>\")")
        else:
            self.game = adventure.game.Game.resume(self.savefile)
            self.saypush(utils.correct_case(self.game.do_command(["look"])))
Ejemplo n.º 9
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')
Ejemplo n.º 10
0
 def setUp(self):
     from adventure.data import Data
     from adventure import load_advent_dat
     self.data = Data()
     load_advent_dat(self.data)
Ejemplo n.º 11
0
 def __init__(self):
     self.running = False
     self.game = adventure.game.Game()
     adventure.load_advent_dat(self.game)
Ejemplo n.º 12
0
 def setUp(self):
     from adventure.data import Data
     from adventure import load_advent_dat
     self.data = Data()
     load_advent_dat(self.data)
Ejemplo n.º 13
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")