Пример #1
0
    def save(self, tree_name):
        tree = Building.save(self, tree_name)

        # Specify nature
        nature = etree.SubElement(tree, 'type')
        nature.text = 'shop'

        # Specify content
        items = etree.SubElement(tree, 'items')
        for it in self.items:
            item = etree.SubElement(items, 'item')
            name = etree.SubElement(item, 'name')
            name.text = it.name

        return tree
def load_building(building, from_save, gap_x, gap_y):
    # Static data
    name = building.find('name').text.strip()
    x = int(building.find('position/x').text) * TILE_SIZE + gap_x
    y = int(building.find('position/y').text) * TILE_SIZE + gap_y
    pos = (x, y)
    sprite = building.find('sprite').text.strip()
    interaction = building.find('interaction')
    interaction_el = {}
    if interaction is not None:
        talks = interaction.find('talks')
        if talks is not None:
            interaction_el['talks'] = []
            for talk in talks.findall('talk'):
                interaction_el['talks'].append(talk.text.strip())
        else:
            interaction_el['talks'] = []
        interaction_el['gold'] = \
            int(interaction.find('gold').text.strip()) if interaction.find('gold') is not None else 0
        interaction_el['item'] = parse_item_file(interaction.find('item').text.strip()) \
            if interaction.find('item') is not None else None

    nature = building.find('type')
    if nature is not None:
        nature = nature.text.strip()
        if nature == "shop":
            stock = []
            for it in building.findall('items/item'):
                entry = {
                    'item': parse_item_file(it.find('name').text.strip()),
                    'quantity': int(it.find('quantity').text.strip())
                }
                stock.append(entry)
            loaded_building = Shop(name, pos, sprite, None, stock)
        else:
            print("Error : building type isn't recognized : ", type)
            raise SystemError
    else:
        loaded_building = Building(name, pos, sprite, interaction_el)

    # Dynamic data
    if from_save:
        locked = building.find('state').text.strip()
        if locked == "True":
            loaded_building.remove_interaction()

    return loaded_building
Пример #3
0
    def save(self, tree_name):
        tree = Building.save(self, tree_name)

        # Specify nature
        nature = etree.SubElement(tree, 'type')
        nature.text = 'shop'

        # Specify content
        items = etree.SubElement(tree, 'items')
        for entry in self.stock:
            item = etree.SubElement(items, 'item')

            name = etree.SubElement(item, 'name')
            name.text = entry['item'].name

            quantity = etree.SubElement(item, 'quantity')
            quantity.text = str(entry['quantity'])

        return tree
def random_building(is_interactive=True,
                    min_talks=0,
                    max_talks=10,
                    talks=True,
                    min_gold=0,
                    gold=True,
                    item=True):
    name = random_string()
    pos = random_pos()
    sprite = 'imgs/houses/blue_house.png'
    interaction = {}
    if is_interactive:
        talks_el = [
            random_string(min_len=10, max_len=100)
            for _ in range(rd.randint(min_talks, max_talks))
        ]
        interaction = {
            'talks': talks_el if talks else [],
            'gold': rd.randint(min_gold, 1000) if gold else 0,
            'item': random_item() if item else None
        }
    print(interaction)
    return Building(name, pos, sprite, interaction)
Пример #5
0
 def __init__(self, name, pos, sprite, interaction, items):
     Building.__init__(self, name, pos, sprite, interaction)
     self.items = items
Пример #6
0
 def __init__(self, name, pos, sprite, interaction, stock):
     Building.__init__(self, name, pos, sprite, interaction)
     self.stock = stock
     self.menu = MenuCreatorManager.create_shop_menu(self.stock, 0)