def list_owned_items(data): """Display a list of owned items.""" owned_items = [item["name"] for item in data["items"].values() if "owned" in item["attributes"]] if len(owned_items) == 0: printer.warn(data["prefix"], "You don't own any items, better go buy some in the shop~!") else: printer.yard(data["prefix"], "You currently own a {0}".format(", and a ".join(owned_items)))
def try_to_place(data, item): """Attempt item placement in yard.""" if sum([toy["size"] for toy in data["yard"]]) + item["size"] < data["space"]: data["yard"].append(item) item["in_yard"] = True printer.success(data["prefix"], "Nice! Your yard now consists of a {0}".format(", and a ".join([toy["name"] for toy in data["yard"]]))) else: printer.warn(data["prefix"], "Oops that won't fit in your yard! Would you like to remove an item?") offer_replace(data, item)
def offer_replace(data, item): """Replace an existing item in yard.""" yard_items = [toy["name"] for toy in data["yard"]] printer.yard(data["prefix"], "Currently in your yard you have: a {0}".format(", and a".join(yard_items))) data["completer"].set_actions(yard_items) inp = input("{.YARD}{}{.ENDC} Would you like to replace any of the items in your yard? Which one? ".format(printer.PColors, data["prefix"], printer.PColors)) if inp in yard_items: remove_from_yard(data, inp) try_to_place(data, item) else: printer.warn(data["prefix"], "Sorry I don't see that item in your yard")
def buy_item(data): """Buy an item.""" buyable_items = [item for item in data["items"].keys() if data["items"][item]["attributes"] == []] data["completer"].set_actions(buyable_items) inp = input("{.SHOP}{}{.ENDC} What item would you like to buy? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in buyable_items: try_to_buy(data, inp) else: printer.warn(data["prefix"], "Uhhh sorry, we don't carry that item.")
def check_food(data): """Check food in yard.""" if data["food_remaining"] == 0: printer.warn( data["prefix"], "Your yard currently doesn't have any food in it! No cats will come if there's no food!" ) else: printer.success( data["prefix"], "Your yard currently has a {0} in it with {1} time remaining". format(data["food"], data["food_remaining"]))
def buy_item(data): """Buy an item.""" buyable_items = [ item for item in data["items"].keys() if data["items"][item]["attributes"] == [] ] inp = input("{.SHOP}{}{.ENDC} What item would you like to buy? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in buyable_items: try_to_buy(data, inp) else: printer.warn(data["prefix"], "Uhhh sorry, we don't carry that item.")
def ex_item(data): """Examine item.""" items = data["items"].keys() printer.shop(data["prefix"], "Here are the items you can see: " + ", ".join(items)) inp = input("{.SHOP}{}{.ENDC} which would you like to examine? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in items: print("{.SHOP}{}{.ENDC}".format(printer.PColors, data["items"][inp]["description"], printer.PColors)) else: printer.warn(data["prefix"], "Uhhh sorry, I don't see that item.")
def list_yard_items(data): """Display list of items placed in yard.""" if len(data["yard"]) > 0: items = [item for item in data["yard"]] for item in items: cats = "no one" if item["occupied"]: cats = ", and ".join([cat["name"] for cat in item["occupant"]]) printer.yard(data["prefix"], "Your yard currently has a {0} in it, occupied by {1}".format(item["name"], cats)) # TODO: add cat descriptions else: printer.warn(data["prefix"], "You currently have nothing in your yard, how sad") check_food(data)
def list_owned_items(data): """Display a list of owned items.""" owned_items = [ item["name"] for item in data["items"].values() if "owned" in item["attributes"] ] if len(owned_items) == 0: printer.warn( data["prefix"], "You don't own any items, better go buy some in the shop~!") else: printer.yard( data["prefix"], "You currently own a {0}".format(", and a ".join(owned_items)))
def ex_item(data): """Examine item.""" items = data["items"].keys() printer.shop( data["prefix"], "Here are the items you can see: " + ", ".join(items)) data["completer"].set_actions(items) inp = input("{.SHOP}{}{.ENDC} which would you like to examine? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in items: print("{.SHOP}{}{.ENDC}".format( printer.PColors, data["items"][inp]["description"], printer.PColors)) else: printer.warn(data["prefix"], "Uhhh sorry, I don't see that item.")
def cats(data): """Allow you to look at the cats in your yard""" cats_in_yard = [] [cats_in_yard.extend(obj["occupant"]) for obj in data["yard"] if obj["occupied"]] cat_names = [cat for cat in cats_in_yard] data["completer"].set_actions(cat_names) printer.yard(data["prefix"], "These are the cats in your yard:") for cat in cat_names: printer.yard(data["prefix"],cat) inp = input("{.YARD}{}{.ENDC} Which cat would you like to look at? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in cat_names: desc_cat(data, [cat for cat in data["cats"] if cat == inp][0]) else: printer.warn(data["prefix"], "I'm sorry that cat isn't in your yard!")
def offer_replace(data, item): """Replace an existing item in yard.""" yard_items = [toy["name"] for toy in data["yard"]] printer.yard( data["prefix"], "Currently in your yard you have: a {0}".format( ", and a".join(yard_items))) inp = input( "{.YARD}{}{.ENDC} Would you like to replace any of the items in your yard? Which one? " .format(printer.PColors, data["prefix"], printer.PColors)) if inp in yard_items: remove_from_yard(data, inp) try_to_place(data, item) else: printer.warn(data["prefix"], "Sorry I don't see that item in your yard")
def try_to_place(data, item): """Attempt item placement in yard.""" if sum([toy["size"] for toy in data["yard"]]) + item["size"] < data["space"]: data["yard"].append(item) item["in_yard"] = True printer.success( data["prefix"], "Nice! Your yard now consists of a {0}".format( ", and a ".join([toy["name"] for toy in data["yard"]]))) else: printer.warn( data["prefix"], "Oops that won't fit in your yard! Would you like to remove an item?" ) offer_replace(data, item)
def list_yard_items(data): """Display list of items placed in yard.""" if len(data["yard"]) > 0: items = [item for item in data["yard"]] for item in items: cats = "no one" if item["occupied"]: cats = ", and ".join([cat["name"] for cat in item["occupant"]]) printer.yard( data["prefix"], "Your yard currently has a {0} in it, occupied by {1}".format( thing[0], cat)) # TODO: add cat descriptions else: printer.warn(data["prefix"], "You currently have nothing in your yard, how sad") check_food(data)
def place(data): """Place item in yard.""" items_list = [item for item in data["items"].values() if "owned" in item["attributes"] and not item["in_yard"]] # TODO: this is ultra gross placable_items = {} for item in items_list: #deliniate placable items from things like food if item["size"] < 6: placable_items[item["name"]] = item data["completer"].set_actions(placable_items.keys()) printer.yard(data["prefix"], "Here are the items that you can put in your yard: {0}".format(", ".join(placable_items.keys()))) inp = input("{.YARD}{}{.ENDC} Which item would you like to place? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in placable_items.keys(): try_to_place(data, placable_items[inp]) else: printer.warn(data["prefix"], "I'm sorry I didn't recognize that item")
def cats(data): """Allow you to look at the cats in your yard""" cats_in_yard = [] [ cats_in_yard.extend(obj["occupant"]) for obj in data["yard"] if obj["occupied"] ] cat_names = [cat for cat in cats_in_yard] data["completer"].set_actions(cat_names) printer.yard(data["prefix"], "These are the cats in your yard:") for cat in cat_names: printer.yard(data["prefix"], cat) inp = input( "{.YARD}{}{.ENDC} Which cat would you like to look at? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in cat_names: desc_cat(data, [cat for cat in data["cats"] if cat == inp][0]) else: printer.warn(data["prefix"], "I'm sorry that cat isn't in your yard!")
def place(data): """Place item in yard.""" items_list = [ item for item in data["items"].values() if "owned" in item["attributes"] and not item["in_yard"] ] # TODO: this is ultra gross placable_items = {} for item in items_list: #deliniate placable items from things like food if item["size"] < 6: placable_items[item["name"]] = item printer.yard( data["prefix"], "Here are the items that you can put in your yard: {0}".format( ", ".join(placable_items.keys()))) inp = input("{.YARD}{}{.ENDC} Which item would you like to place? ".format( printer.PColors, data["prefix"], printer.PColors)) if inp in placable_items.keys(): try_to_place(data, placable_items[inp]) else: printer.warn(data["prefix"], "I'm sorry I didn't recognize that item")
def check_food(data): """Check food in yard.""" if data["food_remaining"] == 0: printer.warn(data["prefix"], "Your yard currently doesn't have any food in it! No cats will come if there's no food!") else: printer.success(data["prefix"], "Your yard currently has a {0} in it with {1} time remaining".format(data["food"], data["food_remaining"]))