diff --git a/functions.py b/functions.py index 0f1bfc5..8bcce59 100644 --- a/functions.py +++ b/functions.py @@ -10,7 +10,7 @@ def wait(): def startGame(): print("Welcome, stranger.") - while True: + while True: # Global check to see if Name, Age, and Gender are correct # Initialise age age = None # Name @@ -18,14 +18,13 @@ def startGame(): while len(name) < 2: name = input(f'Input name was too short. Try again. \nWhat is your name?\n >> ').title() # Gender - gender = None - gender_select = input("What is your gender?\n" - "1) Male\n2) Female\n3) Other\n >> ").lower() while True: + gender = None + gender_select = input("What is your gender?\n" + "1) Male\n2) Female\n3) Other\n >> ").lower() if gender_select not in ("male", "female", "other", "1", "2", "3"): - print("Sorry I didn't recognise that gender. Please select from the following:\n" - "1) Male\n2) Female\n3) Other") - gender_select = input(">> ").lower() + print("Sorry I didn't recognise that gender. Please try again.") + continue else: break if gender_select in ("1", "male"): @@ -57,10 +56,11 @@ def startGame(): elif correct in ['n', 'no']: continue break - while True: + + while True: # Global check to see if Race and Job are correct. # Race - race = input("Please select a race to learn more about it: Elf, Dwarf, or Human.\n >> ").title() while True: + race = input("Please select a race to learn more about it: Elf, Dwarf, or Human.\n >> ").title() if race not in ("Elf", "Dwarf", "Human", None): race = input("Sorry I didn't recognise that race. " "Please select 'Elf', 'Dwarf', or 'Human'.\n >> ").title() @@ -82,8 +82,8 @@ def startGame(): race = None continue # Job - job = input("Please select a job to learn more about it: Barbarian, Cleric, or Wizard.\n >> ").title() while True: + job = input("Please select a job to learn more about it: Barbarian, Cleric, or Wizard.\n >> ").title() if job not in ("Barbarian", "Cleric", "Wizard", None): job = input("Sorry I didn't recognise that job. " "Please select 'Barbarian', 'Cleric', or 'Wizard'.\n >> ").title() @@ -104,21 +104,17 @@ def startGame(): elif proceed in ('2', 'view', 'view another', 'view another job'): job = None continue - - # Final check - correct = input(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n >> ").lower() - if correct in ['y', 'yes']: - break - elif correct in ['n', 'no']: - continue - else: - print("Sorry, I didn't catch that.\n") - correct = input(f"You are a {race} {job}. \nIs this correct? Y/N\n >> ").lower() + while True: + # Final check + correct = input(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n >> ").lower() if correct in ['y', 'yes']: break elif correct in ['n', 'no']: continue - return name, gender, age, race, job + else: + print("Sorry, I didn't catch that. Please try again.\n") + continue + return name, gender, age, race, job def startGame_PreGen(): @@ -126,70 +122,154 @@ def startGame_PreGen(): def query_equip(): - print("Do you want to:\n" - "1) View your equipped items\n" - "2) Change your equipped items - Weapons complete\n" - "3) Return") - response = input(">> ") - if response == "1": - return "view" - elif response == "2": - return "change" - elif response == "3": - return None + while True: + print("Do you want to:\n" + "1) View your equipped items\n" + "2) Change your equipped items\n" + "3) Return") + response = input(">> ") + if response == "1": + current_equipment() + elif response == "2": + change_equip() + elif response == "3": + break def change_equip(): - response = input("Which equipment slot would you like to change?\n" - "1) Weapon\n" - "2) Armor\n" - "3) Other\n" - "4) Return\n" - ">> ").title() - if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"): - print("Sorry I didn't recognise that. Please try again.\n") - change_equip() - elif response == "1" or "Weapon": # Weapon - itemlist = [] # create blank list for items - print(f"You currently have equipped: \n" - f"{view_equippedweapon()}") - - for item_key, item_value in Inventory.items(): # item, attribute - for key, value in item_value.items(): # attribute, stat - if key == "object" and value == Weapon: # if item = class `Weapon` - itemlist.append(item_key) - if item_key in Equipment.values(): - itemlist.remove(item_key) - - print("What would you like to equip?\n") - option = "" - for i, name in enumerate(itemlist, start=1): - option = f'{i}) {name}' - print(option) - - selection = int(input(">> ")) - for i, name in enumerate(itemlist, start=1): - if selection == i: - if name.itemType == "Weapon": - if name.slot == Slots.MainHand: - equip = {"Main Hand": name} - Equipment.update(equip) - elif not name.versatile: - equip = {"Off Hand": name} - Equipment.update(equip) - else: - equip = {"Main Hand": None, "Off Hand": None, "Two Handed": name} - Equipment.update(equip) + while True: + response = input("Which equipment slot would you like to change?\n" + "1) Weapon\n" + "2) Armor\n" + "3) Other\n" + "4) Return\n" + ">> ").title() + if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"): + print("Sorry I didn't recognise that. Please try again.\n") + change_equip() + elif response in ("1", "Weapon"): # Weapon + itemlist = ["Return"] # create blank list for items + view_equippedweapon() + for item_key, item_value in Inventory.items(): # item, attribute + for key, value in item_value.items(): # attribute, stat + if key == "object" and value == Weapon: # if item = class `Weapon` + itemlist.append(item_key) + if item_key in Equipment.values(): + itemlist.remove(item_key) + if len(itemlist) == 1: + print("You have nothing available to equip.\n") else: - print("That wasn't an option.") - print(f"You currently have equipped: \n" - f"{view_equippedweapon()}") - elif response == "2" or "Armor": - pass - elif response == "3" or "Other": - pass - elif response == "4" or "Return": - pass + print("What would you like to equip?\n") + for i, name in enumerate(itemlist, start=1): + option = f'{i}) {name}' + print(option) + selection = int(input(">> ")) + for i, name in enumerate(itemlist, start=1): + if selection == i: + if name == "Return": + break + elif name.itemType == Weapon: + try: + if name.attunement: + print("Not coded attunement yet") # if item has attunement - check availability + except AttributeError: # if no attunement + if name.slot == Slots.MainHand: + equip = {"Main Hand": name} + Equipment.update(equip) + elif not name.versatile: + equip = {"Off Hand": name} + Equipment.update(equip) + else: + equip = {"Main Hand": None, "Off Hand": None, "Two Handed": name} + Equipment.update(equip) + print(f"You now have equipped: \n" + f"{view_equippedweapon()}") + elif response in ("2", "Armor"): # Armor + itemlist = ["Return"] # create blank list for items + view_equippedarmor() + for item_key, item_value in Inventory.items(): # item, attribute + for key, value in item_value.items(): # attribute, stat + if key == "object" and value == Armor: # if item = class `Weapon` + itemlist.append(item_key) # Add item type to list + if item_key in Equipment.values(): + itemlist.remove(item_key) # remove from list if currently equipped - + # consider if holding multiple objects + if len(itemlist) == 1: + print("You have nothing available to equip.\n") + else: + print("What would you like to equip?\n") + for i, name in enumerate(itemlist, start=1): + option = f'{i}) {name}' + print(option) + selection = int(input(">> ")) + for i, name in enumerate(itemlist, start=1): + if selection == i: + if name == "Return": + break + elif name.itemType == Armor: + try: + if name.attunment: + print("Not coded attunement yet") # if item has attunement - check availability + except AttributeError: # if no attunement + if name.slot == Slots.Helm: + equip = {"Helm": name} + Equipment.update(equip) + elif name.slot == Slots.Chest: + equip = {"Chest": name} + Equipment.update(equip) + elif name.slot == Slots.Wrists: + equip = {"Wrists": name} + Equipment.update(equip) + elif name.slot == Slots.Feet: + equip = {"Feet": name} + Equipment.update(equip) + print(f"You now have equipped: \n" + f"{view_equippedarmor()}") + elif response in ("3", "Other"): # Other + itemlist = ["Return"] # create blank list for items + view_equippedother() + for item_key, item_value in Inventory.items(): # item, attribute + for key, value in item_value.items(): # attribute, stat + if key == "object" and value == Armor: # if item = class `Weapon` + itemlist.append(item_key) # Add item type to list + if item_key in Equipment.values(): + itemlist.remove(item_key) # remove from list if currently equipped - + # consider if holding multiple objects + if len(itemlist) == 1: + print("You have nothing available to equip.\n") + else: + print("What would you like to equip?\n") + for i, name in enumerate(itemlist, start=1): + option = f'{i}) {name}' + print(option) + selection = int(input(">> ")) + for i, name in enumerate(itemlist, start=1): + if selection == i: + if name == "Return": + break + elif name.itemType == Armor: + try: + if name.attunment: + print("Not coded attunement yet") # if item has attunement - check availability + except AttributeError: # if no attunement + if name.slot == Slots.Neck: + equip = {"Neck": name} + Equipment.update(equip) + elif name.slot == Slots.Cloak: + equip = {"Cloak": name} + Equipment.update(equip) + elif name.slot == Slots.LeftRing: + equip = {"Left Ring": name} + Equipment.update(equip) + elif name.slot == Slots.RightRing: + equip = {"Right Ring": name} + Equipment.update(equip) + print(f"You now have equipped: \n" + f"{view_equippedother()}") + elif response in ("4", "Return"): + break + else: + print("That wasn't an option.") def view_equippedweapon(): @@ -197,7 +277,27 @@ def view_equippedweapon(): for slot, equipment in Equipment.items(): if slot in ("Main Hand", "Off Hand", "Two Handed") and equipment is not None: equipped = equipped + f'{slot}: {equipment} \n' - return equipped + return "You currently have equipped: \n" + equipped + else: + return "You have nothing equipped!" + + +def view_equippedarmor(): + equipped = "" + for slot, equipment in Equipment.items(): + if slot in ("Helm", "Chest", "Wrists", "Feet") and equipment is not None: + equipped = equipped + f'{slot}: {equipment} \n' + return "You currently have equipped: \n" + equipped + else: + return "You have nothing equipped!" + + +def view_equippedother(): + equipped = "" + for slot, equipment in Equipment.items(): + if slot in ("Neck", "Cloak", "Left Ring", "Right Ring") and equipment is not None: + equipped = equipped + f'{slot}: {equipment} \n' + return "You currently have equipped: \n" + equipped else: return "You have nothing equipped!" @@ -320,14 +420,6 @@ def skill_check(skill): Return value to compare vs a hardcoded DC""" -def parse_input(input_string): - if input_string.strip() in {"1", "2", "3", "4", "5", "6"}: - return int(input_string) - else: - print("Please enter a number from 1 to 6.") - raise SystemExit(1) - - def roll_dice(num_dice): roll_results = [] for _ in range(num_dice): @@ -345,7 +437,7 @@ def current_inventory(): values_list = list(values) # turn variable into a list count_value = values_list[0] # take the first value from list - why? print(f'{item_key.name} x {count_value}\n' - f' {item_key.description}') + f' {item_key.description}\n') def current_equipment(): @@ -353,12 +445,15 @@ def current_equipment(): print(f'You are currently wearing:') for item_key, item_value in Equipment.items(): # string, dictionary if item_value is not None: - if item_value.itemType == ItemType.WEAPON: + if item_value.itemType == ItemType.Weapon: print(f'{item_key}: {item_value.name} - {item_value.damage1H}\n' - f' {item_value.description}') - elif item_value.itemType == ItemType.ARMOR: + f' {item_value.description}\n') + elif item_value.itemType == ItemType.Armor: print(f'{item_key}: {item_value.name} - AC {item_value.ac}\n' - f' {item_value.description}') + f' {item_value.description}\n') + elif item_value.itemType == ItemType.Item: + print(f'{item_key}: {item_value.name}\n' + f' {item_value.description}\n') def calc_weight():