class TestSpecialTopic(IFPTestCase):
    def setUp(self):
        super().setUp()

        self.actor = Actor(self.game, "shepherd")
        self.actor.moveTo(self.start_room)

        self.verb_keyword = "ask"
        self.subject_phrase = "how come"
        suggestion = " ".join([self.verb_keyword, self.subject_phrase])

        self.text = "He shakes his head sadly."

        topic = SpecialTopic(self.game, suggestion, self.text)
        self.actor.addSpecialTopic(topic)

        self.game.turnMain("hi")

    def test_take_conversation_suggestion_with_verb_keyword(self):
        self.game.turnMain(self.verb_keyword)
        self.assertIn(self.text, self.app.print_stack)

    def test_take_conversation_suggestion_without_verb_keyword(self):
        self.game.turnMain(self.subject_phrase)
        self.assertIn(self.text, self.app.print_stack)
Esempio n. 2
0
class TestTalkTo(IFPTestCase):
    def setUp(self):
        super().setUp()
        self.actor = Actor(self.game, "girl")
        self.actor.moveTo(self.start_room)

    def test_talk_to_non_actor_thing(self):
        item = Thing(self.game, "bit")
        item.moveTo(self.start_room)
        self.game.turnMain("talk to bit")
        self.assertIn("cannot talk to", self.app.print_stack.pop())

    def test_talk_to_actor_with_sticky_topic(self):
        self.actor.sticky_topic = Topic(
            self.game, "Weren't you that guy from yesterday?")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.sticky_topic.text, self.app.print_stack)

    def test_talk_to_actor_with_hermit_topic(self):
        self.actor.hermit_topic = Topic(self.game, "Go away.")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.hermit_topic.text, self.app.print_stack)

    def test_talk_to_actor_with_hi_topic(self):
        self.actor.hi_topic = Topic(self.game, "Oh. Hi.")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.hi_topic.text, self.app.print_stack)

    def test_talk_to_actor_with_returning_hi_topic(self):
        self.actor.return_hi_topic = Topic(self.game, "You're back. Great.")
        self.game.turnMain("hi girl")
        self.assertIn(self.actor.return_hi_topic.text, self.app.print_stack)
Esempio n. 3
0
 def test_look_through_person(self):
     item = Actor(self.game, "dude")
     item.moveTo(self.start_room)
     self.game.turnMain("look through dude")
     self.assertIn("cannot look through the dude", self.app.print_stack.pop())
Esempio n. 4
0
beach.entrance = shackdoor

# Attic

attic = Room(game, "Shack, attic", "You are in a dim, cramped attic. ")
shackladder = LadderConnector(game, startroom, attic)
shackladder.entrance_a.description = (
    "Against the north wall is a ladder leading up to the attic. ")
startroom.north = shackladder
silverkey.moveTo(attic)

# CHARACTERS
# Sarah
sarah = Actor(game, "Sarah")
sarah.makeProper("Sarah")
sarah.moveTo(startroom)


def sarahOpalFunc(game, dobj):
    """
    IntFicPy verbs can be overridden or customized for specific items.
    To do this, find the verb you want to customize in the intficpy.verb module.
    Note
        1) the class name of the verb
        2) whether its verbFunc method takes just a "dobj" (direct object) parameter,
           or an "iobj" (indirect object) as well
           For instance, GetVerb (as in, "get opal") takes only a direct object (here, "opal"),
           while GiveVerb (as in, "give opal to Sarah") takes an indirect object as well
           (here, "Sarah")
    Decide whether you want to override the verb for the direct, or indirect object.
    Create a new function in your game file. The first parameter will always be "game".
Esempio n. 5
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}",
        )
Esempio n. 6
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}",
        )