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:
285
functions.py
285
functions.py
@@ -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
|
||||||
gender = None
|
|
||||||
gender_select = input("What is your gender?\n"
|
|
||||||
"1) Male\n2) Female\n3) Other\n >> ").lower()
|
|
||||||
while True:
|
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"):
|
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,21 +104,17 @@ 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']:
|
|
||||||
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()
|
|
||||||
if correct in ['y', 'yes']:
|
if correct in ['y', 'yes']:
|
||||||
break
|
break
|
||||||
elif correct in ['n', 'no']:
|
elif correct in ['n', 'no']:
|
||||||
continue
|
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():
|
def startGame_PreGen():
|
||||||
@@ -126,70 +122,154 @@ def startGame_PreGen():
|
|||||||
|
|
||||||
|
|
||||||
def query_equip():
|
def query_equip():
|
||||||
print("Do you want to:\n"
|
while True:
|
||||||
"1) View your equipped items\n"
|
print("Do you want to:\n"
|
||||||
"2) Change your equipped items - Weapons complete\n"
|
"1) View your equipped items\n"
|
||||||
"3) Return")
|
"2) Change your equipped items\n"
|
||||||
response = input(">> ")
|
"3) Return")
|
||||||
if response == "1":
|
response = input(">> ")
|
||||||
return "view"
|
if response == "1":
|
||||||
elif response == "2":
|
current_equipment()
|
||||||
return "change"
|
elif response == "2":
|
||||||
elif response == "3":
|
change_equip()
|
||||||
return None
|
elif response == "3":
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def change_equip():
|
def change_equip():
|
||||||
response = input("Which equipment slot would you like to change?\n"
|
while True:
|
||||||
"1) Weapon\n"
|
response = input("Which equipment slot would you like to change?\n"
|
||||||
"2) Armor\n"
|
"1) Weapon\n"
|
||||||
"3) Other\n"
|
"2) Armor\n"
|
||||||
"4) Return\n"
|
"3) Other\n"
|
||||||
">> ").title()
|
"4) Return\n"
|
||||||
if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"):
|
">> ").title()
|
||||||
print("Sorry I didn't recognise that. Please try again.\n")
|
if response not in ("1", "2", "3", "4", "Weapon", "Armor", "Other", "Return"):
|
||||||
change_equip()
|
print("Sorry I didn't recognise that. Please try again.\n")
|
||||||
elif response == "1" or "Weapon": # Weapon
|
change_equip()
|
||||||
itemlist = [] # create blank list for items
|
elif response in ("1", "Weapon"): # Weapon
|
||||||
print(f"You currently have equipped: \n"
|
itemlist = ["Return"] # create blank list for items
|
||||||
f"{view_equippedweapon()}")
|
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")
|
||||||
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)
|
|
||||||
else:
|
else:
|
||||||
print("That wasn't an option.")
|
print("What would you like to equip?\n")
|
||||||
print(f"You currently have equipped: \n"
|
for i, name in enumerate(itemlist, start=1):
|
||||||
f"{view_equippedweapon()}")
|
option = f'{i}) {name}'
|
||||||
elif response == "2" or "Armor":
|
print(option)
|
||||||
pass
|
selection = int(input(">> "))
|
||||||
elif response == "3" or "Other":
|
for i, name in enumerate(itemlist, start=1):
|
||||||
pass
|
if selection == i:
|
||||||
elif response == "4" or "Return":
|
if name == "Return":
|
||||||
pass
|
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():
|
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():
|
||||||
|
|||||||
Reference in New Issue
Block a user