示例#1
0
)


def sarahDefault(game):
    game.addText(sarah.default_topic)
    storm_concept.makeKnown(me)
    sarah.addSpecialTopic(howgethere)


sarah.defaultTopic = sarahDefault

opalTopic = Topic(
    game,
    '"I should never it from the cave," says Sarah. "I want nothing to do with it. If you\'re smart, you\'ll leave it where you found it."',
)
sarah.addTopic("asktell", opalTopic, opal)

shackTopic = Topic(
    game,
    '"It\'s not such a bad place, this shack," Sarah says. "It\'s warm. Safe."'
)
sarah.addTopic("asktell", shackTopic, shack_concept)

key2Topic = Topic(
    game,
    '"Leave that be," Sarah says, a hint of anxiety in her voice. "Some things are better left untouched."',
)
sarah.addTopic("asktellgiveshow", key2Topic, silverkey)

sarahTopic = Topic(
    game,
示例#2
0
class TestShow(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.actor = Actor(self.game, "girl")
        self.actor.moveTo(self.start_room)
        self.item = Thing(self.game, "mess")
        self.item.moveTo(self.start_room)
        self.CANNOT_TALK_MSG = "You cannot talk to that. "
        self.topic = Topic(self.game,
                           '"Ah, yes," says the girl mysteriously. ')
        self.sticky_topic = Topic(
            self.game, '"But remember about the thing!" insists the girl. ')
        self.game.turnMain("l")

    def test_show_with_topic(self):
        self.actor.addTopic("show", self.topic, self.item)

        ShowVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried show verb for topic in ask topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_show_with_topic_and_sticky_topic(self):
        self.actor.addTopic("show", self.topic, self.item)
        self.actor.sticky_topic = self.sticky_topic

        self.game.turnMain("show girl mess")
        msg2 = self.app.print_stack.pop()
        msg1 = self.app.print_stack.pop()

        self.assertEqual(
            msg1,
            self.topic.text,
            "Tried show verb for topic in show topics. Expected topic text "
            f"{self.topic.text}, received {msg1}",
        )
        self.assertEqual(
            msg2,
            self.sticky_topic.text,
            "Tried show verb for topic in show topics. Expected topic text "
            f"{self.topic.text}, received {msg2}",
        )

    @unittest.expectedFailure
    def test_show_actor_themselves(self):
        self.actor.addTopic("show", self.topic, self.actor)

        self.game.turnMain("show girl herself")
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried show verb for topic in show topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_show_no_defined_topic(self):
        default = self.actor.default_topic

        self.assertNotIn(
            self.item.ix,
            self.actor.show_topics,
        )

        ShowVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            default,
            "Tried show verb for topic not in show topics. Expected default topic "
            f"{default}, received {msg}",
        )

    def test_show_with_no_defined_topic_and_sticky_topic(self):
        self.actor.sticky_topic = self.sticky_topic

        self.game.turnMain("show girl mess")
        msg2 = self.app.print_stack.pop()
        msg1 = self.app.print_stack.pop()

        self.assertEqual(
            msg1,
            self.actor.default_topic,
            "Expected topic text "
            f"{self.topic.text}, received {msg1}",
        )
        self.assertEqual(
            msg2,
            self.sticky_topic.text,
            "Expected topic text "
            f"{self.topic.text}, received {msg2}",
        )

    def test_show_with_hermit_topic(self):
        self.actor.hermit_topic = self.topic

        self.assertNotIn(
            self.item.ix,
            self.actor.show_topics,
        )  # make sure this topic isn't triggered because it was added for the item

        self.game.turnMain("show girl mess")
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_show_with_hi_topic(self):
        self.actor.hi_topic = self.topic

        self.assertNotIn(
            self.item.ix,
            self.actor.show_topics,
        )  # make sure this topic isn't triggered because it was added for the item

        self.game.turnMain("show girl mess")
        msg = self.app.print_stack.pop(
            -2)  # last response will be default_topic3

        self.assertEqual(
            msg,
            self.topic.text,
            "Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_show_inanimate(self):
        ShowVerb()._runVerbFuncAndEvents(self.game, self.item, self.item)
        msg = self.app.print_stack.pop()
        self.assertEqual(
            msg,
            self.CANNOT_TALK_MSG,
            "Tried ask verb with an inanimate dobj. Expected msg "
            f"{self.CANNOT_TALK_MSG}, received {msg}",
        )
class TestConversationVerbs(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.item = Thing(self.game, "mess")
        self.actor = Actor(self.game, "Jenny")
        self.start_room.addThing(self.item)
        self.start_room.addThing(self.actor)
        self.CANNOT_TALK_MSG = "You cannot talk to that. "
        self.topic = Topic(self.game, '"Ah, yes," says Jenny mysteriously. ')

    def test_ask_inanimate(self):
        AskVerb()._runVerbFuncAndEvents(self.game, self.item, self.actor)
        msg = self.app.print_stack.pop()
        self.assertEqual(
            msg,
            self.CANNOT_TALK_MSG,
            "Tried ask verb with an inanimate dobj. Expected msg "
            f"{self.CANNOT_TALK_MSG}, received {msg}",
        )

    def test_tell_inanimate(self):
        TellVerb()._runVerbFuncAndEvents(self.game, self.item, self.actor)
        msg = self.app.print_stack.pop()
        self.assertEqual(
            msg,
            self.CANNOT_TALK_MSG,
            "Tried ask verb with an inanimate dobj. Expected msg "
            f"{self.CANNOT_TALK_MSG}, received {msg}",
        )

    def test_give_inanimate(self):
        GiveVerb()._runVerbFuncAndEvents(self.game, self.item, self.item)
        msg = self.app.print_stack.pop()
        self.assertEqual(
            msg,
            self.CANNOT_TALK_MSG,
            "Tried ask verb with an inanimate dobj. Expected msg "
            f"{self.CANNOT_TALK_MSG}, received {msg}",
        )

    def test_show_inanimate(self):
        ShowVerb()._runVerbFuncAndEvents(self.game, self.item, self.item)
        msg = self.app.print_stack.pop()
        self.assertEqual(
            msg,
            self.CANNOT_TALK_MSG,
            "Tried ask verb with an inanimate dobj. Expected msg "
            f"{self.CANNOT_TALK_MSG}, received {msg}",
        )

    def test_ask_no_defined_topic(self):
        self.actor.defaultTopic(self.game)
        self.game.runTurnEvents()
        default = self.app.print_stack.pop()

        self.assertNotIn(
            self.item.ix,
            self.actor.ask_topics,
        )

        AskVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            default,
            "Tried ask verb for topic not in ask topics. Expected default topic "
            f"{default}, received {msg}",
        )

    def test_tell_no_defined_topic(self):
        self.actor.defaultTopic(self.game)
        self.game.runTurnEvents()
        default = self.app.print_stack.pop()

        self.assertNotIn(
            self.item.ix,
            self.actor.tell_topics,
        )

        TellVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            default,
            "Tried tell verb for topic not in tell topics. Expected default topic "
            f"{default}, received {msg}",
        )

    def test_give_no_defined_topic(self):
        self.actor.defaultTopic(self.game)
        self.game.runTurnEvents()
        default = self.app.print_stack.pop()

        self.assertNotIn(
            self.item.ix,
            self.actor.give_topics,
        )

        GiveVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            default,
            "Tried give verb for topic not in give topics. Expected default topic "
            f"{default}, received {msg}",
        )

    def test_show_no_defined_topic(self):
        self.actor.defaultTopic(self.game)
        self.game.runTurnEvents()
        default = self.app.print_stack.pop()

        self.assertNotIn(
            self.item.ix,
            self.actor.show_topics,
        )

        ShowVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            default,
            "Tried show verb for topic not in show topics. Expected default topic "
            f"{default}, received {msg}",
        )

    def test_ask_with_topic(self):
        self.actor.addTopic("ask", self.topic, self.item)

        AskVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried ask verb for topic in ask topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_tell_with_topic(self):
        self.actor.addTopic("tell", self.topic, self.item)

        TellVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried tell verb for topic in ask topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_give_with_topic(self):
        self.actor.addTopic("give", self.topic, self.item)

        GiveVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried give verb for topic in ask topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_show_with_topic(self):
        self.actor.addTopic("show", self.topic, self.item)

        ShowVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried show verb for topic in ask topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )
示例#4
0
class TestGive(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.actor = Actor(self.game, "girl")
        self.actor.moveTo(self.start_room)
        self.item = Thing(self.game, "mess")
        self.item.moveTo(self.start_room)
        self.CANNOT_TALK_MSG = "You cannot talk to that. "
        self.topic = Topic(self.game,
                           '"Ah, yes," says the girl mysteriously. ')
        self.sticky_topic = Topic(
            self.game, '"But remember about the thing!" insists the girl. ')
        self.game.turnMain("l")

    def test_give_no_defined_topic(self):
        default = self.actor.default_topic

        self.assertNotIn(
            self.item.ix,
            self.actor.give_topics,
        )

        GiveVerb()._runVerbFuncAndEvents(self.game, self.actor, self.item)
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            default,
            "Tried give verb for topic not in give topics. Expected default topic "
            f"{default}, received {msg}",
        )

    def test_give_with_topic_and_sticky_topic(self):
        self.actor.addTopic("give", self.topic, self.item)
        self.actor.sticky_topic = self.sticky_topic

        self.game.turnMain("give girl mess")
        msg2 = self.app.print_stack.pop()
        msg1 = self.app.print_stack.pop()

        self.assertEqual(
            msg1,
            self.topic.text,
            "Tried show verb for topic in show topics. Expected topic text "
            f"{self.topic.text}, received {msg1}",
        )
        self.assertEqual(
            msg2,
            self.sticky_topic.text,
            "Tried show verb for topic in show topics. Expected topic text "
            f"{self.topic.text}, received {msg2}",
        )

    def test_give_actor_you(self):
        self.game.turnMain("give girl me")
        msg = self.app.print_stack.pop()

        self.assertIn(
            "cannot give yourself away",
            msg,
        )

    def test_give_actor_person(self):
        self.game.turnMain("give girl to girl")
        msg = self.app.print_stack.pop()

        self.assertIn(
            "cannot take a person",
            msg,
        )

    def test_give_with_topic(self):
        self.actor.addTopic("give", self.topic, self.item)

        self.game.turnMain("give girl mess")
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried give verb for topic in ask topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_give_with_topic_and_give_enabled(self):
        self.actor.addTopic("give", self.topic, self.item)
        self.item.give = True

        self.game.turnMain("give girl mess")
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Tried give verb for topic in ask topics. Expected topic text "
            f"{self.topic.text}, received {msg}",
        )
        self.assertTrue(self.actor.containsItem(self.item))

    def test_give_with_no_defined_topic_and_sticky_topic(self):
        self.actor.sticky_topic = self.sticky_topic

        self.game.turnMain("give girl mess")
        msg2 = self.app.print_stack.pop()
        msg1 = self.app.print_stack.pop()

        self.assertEqual(
            msg1,
            self.actor.default_topic,
            "Expected topic text "
            f"{self.topic.text}, received {msg1}",
        )
        self.assertEqual(
            msg2,
            self.sticky_topic.text,
            "Expected topic text "
            f"{self.topic.text}, received {msg2}",
        )

    def test_give_with_hermit_topic(self):
        self.actor.hermit_topic = self.topic

        self.assertNotIn(
            self.item.ix,
            self.actor.give_topics,
        )  # make sure this topic isn't triggered because it was added for the item

        self.game.turnMain("give girl mess")
        msg = self.app.print_stack.pop()

        self.assertEqual(
            msg,
            self.topic.text,
            "Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_give_with_hi_topic(self):
        self.actor.hi_topic = self.topic

        self.assertNotIn(
            self.item.ix,
            self.actor.give_topics,
        )  # make sure this topic isn't triggered because it was added for the item

        self.game.turnMain("give girl mess")
        msg = self.app.print_stack.pop(
            -2)  # last response will be default_topic3

        self.assertEqual(
            msg,
            self.topic.text,
            "Expected topic text "
            f"{self.topic.text}, received {msg}",
        )

    def test_give_inanimate(self):
        GiveVerb()._runVerbFuncAndEvents(self.game, self.item, self.item)
        msg = self.app.print_stack.pop()
        self.assertEqual(
            msg,
            self.CANNOT_TALK_MSG,
            "Tried ask verb with an inanimate dobj. Expected msg "
            f"{self.CANNOT_TALK_MSG}, received {msg}",
        )