Update functions.py

Updated equipment change. Links its together an stays in menu until you exit. Lets you return on each menu. Doesn't list anything if there's nothing to list and is clear about it. - Requires further testing with test items.
Updated Character Generation by keeping things in their own loops.
This commit is contained in:
KansaiGaijin
2022-10-30 14:39:21 +13:00
committed by GitHub
parent 6ea09f7ee6
commit b9a7705f42

View File

@@ -10,7 +10,7 @@ def wait():
def startGame(): def startGame():
print("Welcome, stranger.") print("Welcome, stranger.")
while True: while True: # Global check to see if Name, Age, and Gender are correct
# Initialise age # Initialise age
age = None age = None
# Name # Name
@@ -18,14 +18,13 @@ def startGame():
while len(name) < 2: while len(name) < 2:
name = input(f'Input name was too short. Try again. \nWhat is your name?\n >> ').title() name = input(f'Input name was too short. Try again. \nWhat is your name?\n >> ').title()
# Gender # Gender
while True:
gender = None gender = None
gender_select = input("What is your gender?\n" gender_select = input("What is your gender?\n"
"1) Male\n2) Female\n3) Other\n >> ").lower() "1) Male\n2) Female\n3) Other\n >> ").lower()
while True:
if gender_select not in ("male", "female", "other", "1", "2", "3"): 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" print("Sorry I didn't recognise that gender. Please try again.")
"1) Male\n2) Female\n3) Other") continue
gender_select = input(">> ").lower()
else: else:
break break
if gender_select in ("1", "male"): if gender_select in ("1", "male"):
@@ -57,10 +56,11 @@ def startGame():
elif correct in ['n', 'no']: elif correct in ['n', 'no']:
continue continue
break break
while True:
while True: # Global check to see if Race and Job are correct.
# Race # Race
race = input("Please select a race to learn more about it: Elf, Dwarf, or Human.\n >> ").title()
while True: 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): if race not in ("Elf", "Dwarf", "Human", None):
race = input("Sorry I didn't recognise that race. " race = input("Sorry I didn't recognise that race. "
"Please select 'Elf', 'Dwarf', or 'Human'.\n >> ").title() "Please select 'Elf', 'Dwarf', or 'Human'.\n >> ").title()
@@ -82,8 +82,8 @@ def startGame():
race = None race = None
continue continue
# Job # Job
job = input("Please select a job to learn more about it: Barbarian, Cleric, or Wizard.\n >> ").title()
while True: 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): if job not in ("Barbarian", "Cleric", "Wizard", None):
job = input("Sorry I didn't recognise that job. " job = input("Sorry I didn't recognise that job. "
"Please select 'Barbarian', 'Cleric', or 'Wizard'.\n >> ").title() "Please select 'Barbarian', 'Cleric', or 'Wizard'.\n >> ").title()
@@ -104,7 +104,7 @@ def startGame():
elif proceed in ('2', 'view', 'view another', 'view another job'): elif proceed in ('2', 'view', 'view another', 'view another job'):
job = None job = None
continue continue
while True:
# Final check # Final check
correct = input(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n >> ").lower() correct = input(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n >> ").lower()
if correct in ['y', 'yes']: if correct in ['y', 'yes']:
@@ -112,11 +112,7 @@ def startGame():
elif correct in ['n', 'no']: elif correct in ['n', 'no']:
continue continue
else: else:
print("Sorry, I didn't catch that.\n") print("Sorry, I didn't catch that. Please try again.\n")
correct = input(f"You are a {race} {job}. \nIs this correct? Y/N\n >> ").lower()
if correct in ['y', 'yes']:
break
elif correct in ['n', 'no']:
continue continue
return name, gender, age, race, job return name, gender, age, race, job
@@ -126,20 +122,22 @@ def startGame_PreGen():
def query_equip(): def query_equip():
while True:
print("Do you want to:\n" print("Do you want to:\n"
"1) View your equipped items\n" "1) View your equipped items\n"
"2) Change your equipped items - Weapons complete\n" "2) Change your equipped items\n"
"3) Return") "3) Return")
response = input(">> ") response = input(">> ")
if response == "1": if response == "1":
return "view" current_equipment()
elif response == "2": elif response == "2":
return "change" change_equip()
elif response == "3": elif response == "3":
return None break
def change_equip(): def change_equip():
while True:
response = input("Which equipment slot would you like to change?\n" response = input("Which equipment slot would you like to change?\n"
"1) Weapon\n" "1) Weapon\n"
"2) Armor\n" "2) Armor\n"
@@ -149,28 +147,32 @@ def change_equip():
if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"): if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"):
print("Sorry I didn't recognise that. Please try again.\n") print("Sorry I didn't recognise that. Please try again.\n")
change_equip() change_equip()
elif response == "1" or "Weapon": # Weapon elif response in ("1", "Weapon"): # Weapon
itemlist = [] # create blank list for items itemlist = ["Return"] # create blank list for items
print(f"You currently have equipped: \n" view_equippedweapon()
f"{view_equippedweapon()}")
for item_key, item_value in Inventory.items(): # item, attribute for item_key, item_value in Inventory.items(): # item, attribute
for key, value in item_value.items(): # attribute, stat for key, value in item_value.items(): # attribute, stat
if key == "object" and value == Weapon: # if item = class `Weapon` if key == "object" and value == Weapon: # if item = class `Weapon`
itemlist.append(item_key) itemlist.append(item_key)
if item_key in Equipment.values(): if item_key in Equipment.values():
itemlist.remove(item_key) itemlist.remove(item_key)
if len(itemlist) == 1:
print("You have nothing available to equip.\n")
else:
print("What would you like to equip?\n") print("What would you like to equip?\n")
option = ""
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
option = f'{i}) {name}' option = f'{i}) {name}'
print(option) print(option)
selection = int(input(">> ")) selection = int(input(">> "))
for i, name in enumerate(itemlist, start=1): for i, name in enumerate(itemlist, start=1):
if selection == i: if selection == i:
if name.itemType == "Weapon": 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: if name.slot == Slots.MainHand:
equip = {"Main Hand": name} equip = {"Main Hand": name}
Equipment.update(equip) Equipment.update(equip)
@@ -180,16 +182,94 @@ def change_equip():
else: else:
equip = {"Main Hand": None, "Off Hand": None, "Two Handed": name} equip = {"Main Hand": None, "Off Hand": None, "Two Handed": name}
Equipment.update(equip) 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: else:
print("That wasn't an option.") 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
def view_equippedweapon(): def view_equippedweapon():
@@ -197,7 +277,27 @@ def view_equippedweapon():
for slot, equipment in Equipment.items(): for slot, equipment in Equipment.items():
if slot in ("Main Hand", "Off Hand", "Two Handed") and equipment is not None: if slot in ("Main Hand", "Off Hand", "Two Handed") and equipment is not None:
equipped = equipped + f'{slot}: {equipment} \n' 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: else:
return "You have nothing equipped!" return "You have nothing equipped!"
@@ -320,14 +420,6 @@ def skill_check(skill):
Return value to compare vs a hardcoded DC""" 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): def roll_dice(num_dice):
roll_results = [] roll_results = []
for _ in range(num_dice): for _ in range(num_dice):
@@ -345,7 +437,7 @@ def current_inventory():
values_list = list(values) # turn variable into a list values_list = list(values) # turn variable into a list
count_value = values_list[0] # take the first value from list - why? count_value = values_list[0] # take the first value from list - why?
print(f'{item_key.name} x {count_value}\n' print(f'{item_key.name} x {count_value}\n'
f' {item_key.description}') f' {item_key.description}\n')
def current_equipment(): def current_equipment():
@@ -353,12 +445,15 @@ def current_equipment():
print(f'You are currently wearing:') print(f'You are currently wearing:')
for item_key, item_value in Equipment.items(): # string, dictionary for item_key, item_value in Equipment.items(): # string, dictionary
if item_value is not None: 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' print(f'{item_key}: {item_value.name} - {item_value.damage1H}\n'
f' {item_value.description}') f' {item_value.description}\n')
elif item_value.itemType == ItemType.ARMOR: elif item_value.itemType == ItemType.Armor:
print(f'{item_key}: {item_value.name} - AC {item_value.ac}\n' 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(): def calc_weight():