Exemplo n.º 1
0
def create_item(*item_id):
    """(Item) Creates an item (this function can be thought of as a item factory)

    Parameters:
        item_id (*tuple): N-length tuple to uniquely identify the item,
        often comprised of strings, but not necessarily (arguments are grouped
        into a single tuple)

    Examples:
        >>> create_item("dirt")
        BlockItem('dirt')
        >>> create_item("hands")
        HandItem('hands')
        >>> create_item("pickaxe", "stone")  # *without* Task 2.1.2 implemented
        Traceback (most recent call last):
        ...
        NotImplementedError: "Tool creation is not yet handled"
        >>> create_item("pickaxe", "stone")  # *with* Task 2.1.2 implemented
        ToolItem('stone_pickaxe')
    """
    if len(item_id) == 2:

        if item_id[0] in MATERIAL_TOOL_TYPES and item_id[
                1] in TOOL_DURABILITIES:
            raise NotImplementedError("Tool creation is not yet handled")

    elif len(item_id) == 1:

        item_type = item_id[0]

        if item_type == "hands":
            return HandItem("hands")

        elif item_type == "dirt":
            return BlockItem(item_type)

        # Task 1.4 Basic Items: Create wood & stone here
        elif item_type == "wood" or item_type == "stone":
            return BlockItem(item_type)

        elif item_type == "apple":
            return FoodItem(item_type, 2)

        elif item_type == "crafting_table":
            return BlockItem(item_type)

        elif item_type == "stick":
            return SimpleItem(item_type)

    raise KeyError(f"No item defined for {item_id}")
Exemplo n.º 2
0
def create_item(*item_types):
    if len(item_types) == 2:

        if item_types[0] in MATERIAL_TOOL_TYPES and item_types[
                1] in TOOL_DURABILITIES:
            raise NotImplementedError("Tool creation is not yet handled")

    elif len(item_types) == 1:

        item_type = item_types[0]

        if item_type == "hands":
            return HandItem("hands")

        elif item_type == "dirt":
            return BlockItem(item_type)

        # Task 1.4 Basic Items: Create wood & stone here
        # ...

    raise KeyError(f"No item defined for {item_types}")
Exemplo n.º 3
0
def create_item(*item_id):
    """(Item) Creates an item (this function can be thought of as a item factory)

    Parameters:
        item_id (*tuple): N-length tuple to uniquely identify the item,
        often comprised of strings, but not necessarily (arguments are grouped
        into a single tuple)

    Examples:
        >>> create_item("dirt")
        BlockItem('dirt')
        >>> create_item("hands")
        HandItem('hands')
        >>> create_item("pickaxe", "stone")  # *without* Task 2.1.2 implemented
        Traceback (most recent call last):
        ...
        NotImplementedError: "Tool creation is not yet handled"
        >>> create_item("pickaxe", "stone")  # *with* Task 2.1.2 implemented
        ToolItem('stone_pickaxe')
    """
    if len(item_id) == 2:

        if item_id[0] in MATERIAL_TOOL_TYPES and item_id[
                1] in TOOL_DURABILITIES:
            if item_id[0] == "pickaxe" and item_id[1] == "stone":
                return ToolItem("stone_pickaxe", "pickaxe", 132)
            elif item_id[0] == "pickaxe" and item_id[1] == "diamond":
                return ToolItem("diamond_pickaxe", "pickaxe", 1562)
            elif item_id[0] == "pickaxe" and item_id[1] == "wood":
                return ToolItem('wood_pickaxe', "pickaxe", 60)
            elif item_id[0] == "axe" and item_id[1] == "wood":
                return ToolItem('wood_axe', "axe", 60)
            elif item_id[0] == "shovel" and item_id[1] == "wood":
                return ToolItem('wood_shovel', "shovel", 60)
            elif item_id[0] == "sword" and item_id[1] == "wood":
                return ToolItem('wood_sword', "sword", 60)
            elif item_id[0] == "axe" and item_id[1] == "stone":
                return ToolItem('stone_axe', "axe", 132)
            elif item_id[0] == "shovel" and item_id[1] == "stone":
                return ToolItem('stone_shovel', "shovel", 132)
            elif item_id[0] == "sword" and item_id[1] == "stone":
                return ToolItem('stone_sword', "sword", 132)
            elif item_id[0] == "bow" and item_id[1] == "arrow":
                return BowArrowItem('bow_arrow', 'arrow', 'inf')

    elif len(item_id) == 1:

        item_type = item_id[0]

        if item_type == "hands":
            return HandItem("hands")

        elif item_type == "bow":
            return SimpleItem("bow")

        elif item_type == "arrow":
            return SimpleItem("arrow")

        elif item_type == "dirt":
            return BlockItem(item_type)

        # Task 1.4 Basic Items: Create wood & stone here
        # ...

        elif item_type == "wood":
            return BlockItem(item_type)

        elif item_type == "stone":
            return BlockItem(item_type)

        elif item_type == "apple":
            return FoodItem(item_type, 2)

        elif item_type == "stick":
            return SimpleItem(item_type)

        elif item_type == "crafting_table":
            return BlockItem(item_type)

        elif item_type == "wool":
            return BlockItem(item_type)

        elif item_type == "bed":
            return BlockItem(item_type)

        elif item_type == "honey":
            return BlockItem(item_type)

        elif item_type == "furnace":
            return BlockItem(item_type)

        elif item_type == "diamond":
            return BlockItem(item_type)

        elif item_type == "swarming_bee":
            return Bee("_draw_bee", 5)

        elif item_type == "hive":
            return BlockItem(item_type)

    raise KeyError(f"No item defined for {item_id}")