Exemplo n.º 1
0
def parse_single_target_command(user_input, player):
    command = user_input[0]
    if command in Constants.EXAMINE:
        return Commands.parse_examine_command(user_input, player)
    if command in Constants.TAKE:
        return Commands.parse_take_command(user_input, player)
    if command in Constants.TALK:
        return Commands.parse_talk_command(user_input, player)
    return Constants.INVALID_COMMAND_GIVEN_STRING
Exemplo n.º 2
0
    def test_take_command_item_not_present(self):
        user_input = ["take", "test not present"]
        player = copy.copy(Test_Objects.TEST_PLAYER)
        room = Room.Room("Test Room", "This is a test room for testing.", {},
                         [Test_Objects.TEST_ITEM_ON_GROUND], [])
        item = copy.copy(Test_Objects.TEST_ITEM_NOT_PRESENT)

        self.assertTrue(item not in room.items)
        self.assertTrue(item not in player.inventory)

        actual = Commands.parse_take_command(user_input, player)
        self.assertTrue(item not in room.items)
        self.assertTrue(item not in player.inventory)
        self.assertEqual(Constants.ITEM_NOT_VISIBLE_STRING, actual)
Exemplo n.º 3
0
    def test_take_command_item_with_keyword(self):
        user_input = ["take", "keyword"]
        item = Item.Item("test 2", ["keyword"], "Short desc 2", "Long desc 2",
                         True, True)
        room = Room.Room("Test Room", "This is a test room for testing.", {},
                         [item], [])
        player = Player.Player(room, [Test_Objects.TEST_ITEM_IN_INVENTORY])

        self.assertTrue(item in room.items)
        self.assertTrue(item not in player.inventory)

        actual = Commands.parse_take_command(user_input, player)
        self.assertTrue(item not in room.items)
        self.assertTrue(item in player.inventory)
        self.assertEqual("You take the test 2.", actual)