コード例 #1
0
ファイル: test_mice.py プロジェクト: rcarmo/divmod.org
 def test_mouseCanSqueak(self):
     events.runEventTransaction(self.store, self.mousehood.squeak)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertEquals(
         commandutils.flatten(event.otherMessage.plaintext(self.player)),
         u"SQUEAK!")
コード例 #2
0
 def test_mouseCanSqueak(self):
     events.runEventTransaction(self.store, self.mousehood.squeak)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertEquals(
         commandutils.flatten(event.otherMessage.plaintext(self.player)),
         u"SQUEAK!")
コード例 #3
0
 def test_randomHiragana(self):
     """
     When explicitly told to challenge without specifying a syllable, the
     mouse should say a random one.
     """
     events.runEventTransaction(self.store, self.mousehood.challenge)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertChallenge(event)
コード例 #4
0
ファイル: test_japanese.py プロジェクト: ashfall/imaginary
 def test_randomHiragana(self):
     """
     When explicitly told to challenge without specifying a syllable, the
     mouse should say a random one.
     """
     events.runEventTransaction(self.store, self.mousehood.challenge)
     self.assertEquals(len(self.playerIntelligence.concepts), 1)
     event = self.playerIntelligence.concepts[0]
     self.assertChallenge(event)
コード例 #5
0
    def runEventTransaction(self, player, line, match):
        """
        Take a player, line, and dictionary of parse results and execute the
        actual Action implementation.

        @param player: A provider of C{self.actorInterface}
        @param line: A unicode string containing the original input
        @param match: A dictionary containing some parse results to pass
        through to the C{run} method.

        """
        events.runEventTransaction(player.store, self.run, player, line,
                                   **match)
コード例 #6
0
ファイル: action.py プロジェクト: rcarmo/divmod.org
    def runEventTransaction(self, player, line, match):
        """
        Take a player, line, and dictionary of parse results and execute the
        actual Action implementation.

        @param player: A provider of C{self.actorInterface}
        @param line: A unicode string containing the original input
        @param match: A dictionary containing some parse results to pass
        through to the C{run} method.

        """
        events.runEventTransaction(
            player.store, self.run, player, line, **match)
コード例 #7
0
    def test_mouseCanSqueak(self):
        """
        When explicitly told to challenge with a given romaji syllable, the
        mouse should say a hiragana letter.
        """
        events.runEventTransaction(self.store,
                                   self.mousehood.challenge,
                                   character=u"\N{HIRAGANA LETTER A}")

        self.assertEquals(len(self.playerIntelligence.concepts), 1)
        event = self.playerIntelligence.concepts[0]
        self.assertEquals(
            commandutils.flatten(event.otherMessage.plaintext(self.player)),
            u"A %s says, '\N{HIRAGANA LETTER A}'" % (self.mouseName, ))
コード例 #8
0
ファイル: test_japanese.py プロジェクト: ashfall/imaginary
    def test_mouseCanSqueak(self):
        """
        When explicitly told to challenge with a given romaji syllable, the
        mouse should say a hiragana letter.
        """
        events.runEventTransaction(
            self.store,
            self.mousehood.challenge,
            character=u"\N{HIRAGANA LETTER A}")

        self.assertEquals(len(self.playerIntelligence.concepts), 1)
        event = self.playerIntelligence.concepts[0]
        self.assertEquals(
            commandutils.flatten(event.otherMessage.plaintext(self.player)),
            u"A %s says, '\N{HIRAGANA LETTER A}'" % (self.mouseName,))
コード例 #9
0
ファイル: action.py プロジェクト: mithrandi/imaginary
    def runEventTransaction(self, player, line, match):
        """
        Take a player, input, and dictionary of parse results, resolve those
        parse results into implementations of appropriate interfaces in the
        game world, and execute the actual Action implementation (contained in
        the 'do' method) in an event transaction.

        This is the top level of action invocation.

        @param player: A L{Thing} representing the actor's body.

        @param line: A unicode string containing the original input

        @param match: A dictionary containing some parse results to pass
            through to this L{Action}'s C{do} method as keyword arguments.

        @raise eimaginary.AmbiguousArgument: if multiple valid targets are
            found for an argument.
        """
        def thunk():
            begin = time.time()
            try:
                actor = self.actorInterface(player)
                for (k, v) in match.items():
                    try:
                        objs = self.resolve(player, k, v)
                    except NotImplementedError:
                        pass
                    else:
                        if len(objs) == 1:
                            match[k] = objs[0]
                        elif len(objs) == 0:
                            self.cantFind(player, actor, k, v)
                        else:
                            raise eimaginary.AmbiguousArgument(
                                self, k, v, objs)
                return self.do(actor, line, **match)
            finally:
                end = time.time()
                log.msg(interface=iaxiom.IStatEvent,
                        stat_actionDuration=end - begin,
                        stat_actionExecuted=1)

        events.runEventTransaction(player.store, thunk)
コード例 #10
0
ファイル: action.py プロジェクト: exarkun/imaginary
    def runEventTransaction(self, player, line, match):
        """
        Take a player, input, and dictionary of parse results, resolve those
        parse results into implementations of appropriate interfaces in the
        game world, and execute the actual Action implementation (contained in
        the 'do' method) in an event transaction.

        This is the top level of action invocation.

        @param player: A L{Thing} representing the actor's body.

        @param line: A unicode string containing the original input

        @param match: A dictionary containing some parse results to pass
            through to this L{Action}'s C{do} method as keyword arguments.

        @raise eimaginary.AmbiguousArgument: if multiple valid targets are
            found for an argument.
        """
        def thunk():
            begin = time.time()
            try:
                actor = self.actorInterface(player)
                for (k, v) in match.items():
                    try:
                        objs = self.resolve(player, k, v)
                    except NotImplementedError:
                        pass
                    else:
                        if len(objs) == 1:
                            match[k] = objs[0]
                        elif len(objs) == 0:
                            self.cantFind(player, actor, k, v)
                        else:
                            raise eimaginary.AmbiguousArgument(self, k, v, objs)
                return self.do(actor, line, **match)
            finally:
                end = time.time()
                log.msg(interface=iaxiom.IStatEvent,
                        stat_actionDuration=end - begin,
                        stat_actionExecuted=1)
        events.runEventTransaction(player.store, thunk)