Developed the possible text inputs to be parsed

This commit is contained in:
kansaigaijin
2025-07-13 20:37:55 +12:00
parent 356957bd0f
commit d7d69fa3d1

View File

@@ -16,8 +16,7 @@ def startGame():
# Loop for initial choice: Create or Pre-generated # Loop for initial choice: Create or Pre-generated
while True: while True:
start = input("Would you like to create your own character or use pre-generated stats?" start = input("Would you like to create your own character or use pre-generated stats?"
"\n 1) Create a new character\n 2) Pre-generated\n >> ") "\n 1) Create a new character\n 2) Quick Setup\n 3) Pre-Gen Character\n >> ")
if start in ("1", "Create"): if start in ("1", "Create"):
# --- Character Basic Info (Name, Gender, Age) --- # --- Character Basic Info (Name, Gender, Age) ---
name, gender, age = None, None, None # Initialize name, gender, age = None, None, None # Initialize
@@ -134,7 +133,7 @@ def startGame():
break # Break out of this inner loop to restart the outer race/job loop break # Break out of this inner loop to restart the outer race/job loop
correct = input(f"\n{name}, you are a {race.name_adjective} {job.name}.\nIs this correct? Y/N\n >> ") correct = input(f"\n{name}, you are a {race.name_adjective} {job.name}.\nIs this correct? Y/N\n >> ")
if correct.lower() in ['y', 'yes']: if correct.lower() in ['y', 'yes']:
return name, gender, age, race, job # All confirmed, return values return name, gender, age, race, job, None# All confirmed, return values
elif correct.lower() in ['n', 'no']: elif correct.lower() in ['n', 'no']:
# If not correct, break this loop to re-enter race/job selection # If not correct, break this loop to re-enter race/job selection
break break
@@ -142,13 +141,13 @@ def startGame():
print("Sorry, I didn't catch that. Please try again.\n") print("Sorry, I didn't catch that. Please try again.\n")
continue continue
elif start in ("2", "pre-generated"): elif start in ("2", "Quick Setup"):
print("Please be prepared to enter a name, gender, age, race, and class, from those available in the game." print("Please be prepared to enter a name, gender, age, race, and class, from those available in the game."
"\nIf you are unsure what the options are, please go back and create a new character.") "\nIf you are unsure what the options are, please go back and create a new character.")
create = input("Do you wish to continue? Y/N\n >> ").lower() create = input("Do you wish to continue? Y/N\n >> ").lower()
if create in ("y", "yes"): if create in ("y", "yes"):
name = input("Name: ") name = input("Name: ")
gender = input("Gender: ") gender = input("Gender (Male, Female, Other): ")
age = int(input("Age: ")) age = int(input("Age: "))
race_str = input("Race (Elf, Dwarf, Human): ") race_str = input("Race (Elf, Dwarf, Human): ")
job_str = input("Job (Barbarian, Cleric, Wizard): ") job_str = input("Job (Barbarian, Cleric, Wizard): ")
@@ -161,29 +160,43 @@ def startGame():
actual_job = job_map.get(job_str.lower()) actual_job = job_map.get(job_str.lower())
if actual_race and actual_job: if actual_race and actual_job:
return name, gender, age, actual_race, actual_job return name, gender, age, actual_race, actual_job, None
else: else:
print("Invalid race or job entered for pre-generated character. Please try again.") print("Invalid race or job entered for pre-generated character. Please try again.")
# Force restart to character creation choice by setting 'start' to '1'
# and then continue the outermost loop.
start = "1" start = "1"
continue continue
elif create in ("n", "no"): elif create in ("n", "no"):
# If 'n', re-prompt the initial choice. # If 'n', re-prompt the initial choice.
start = input("Would you like to create your own character or use pre-generated stats?" start = input("Would you like to create your own character or use pre-generated stats?"
"\n 1) Create a new character\n 2) Pre-generated\n >> ") "\n 1) Create a new character\n 2) Quick Setup\n 3) Pre-Gen Character\n >> ")
continue continue
else: else:
print("Invalid input. Please enter Y or N.") print("Invalid input. Please enter Y or N.")
# If invalid, re-prompt the initial choice. # If invalid, re-prompt the initial choice.
start = input("Would you like to create your own character or use pre-generated stats?" start = input("Would you like to create your own character or use pre-generated stats?"
"\n 1) Create a new character\n 2) Pre-generated\n >> ") "\n 1) Create a new character\n 2) Quick Setup\n 3) Pre-Gen Character\n >> ")
continue continue
elif start in ("3", "Pre-generated Character"):
print("You have chosen a pre-generated character.")
# Define pre-generated character details
name = "Elias"
gender = "Male"
age = 30
race = Human # Direct reference to the object
job = Barbarian # Direct reference to the object
pre_allocated_stats = {
"Strength": 15,
"Dexterity": 14,
"Constitution": 13,
"Intelligence": 12,
"Wisdom": 10,
"Charisma": 8
}
print(f"\nPre-generated Character: {name}, a {age} year old {race.name_adjective} {job.name}.")
return name, gender, age, race, job, pre_allocated_stats
else: else:
print("Invalid input. Please select '1' or '2'.") print("Invalid input. Please select '1', '2', or '3'.\n.")
# Re-prompt the initial choice.
start = input("Would you like to create your own character or use pre-generated stats?"
"\n 1) Create a new character\n 2) Pre-generated\n >> ")
continue continue
def query_equip(player: Player): def query_equip(player: Player):
@@ -255,7 +268,7 @@ def change_equip(player: Player):
itemlist = [item_obj for item_obj, item_data in player.inventory.items.items() itemlist = [item_obj for item_obj, item_data in player.inventory.items.items()
if item_data["object"] == ItemType.Armor and if item_data["object"] == ItemType.Armor and
item_obj not in [player.inventory.equipped_items[Slots.Helm], item_obj not in [player.inventory.equipped_items[Slots.Helm],
player.inventory.equipped_items[Slots.Chest], player.inventory.equipped_items[Slots.Armor],
player.inventory.equipped_items[Slots.Wrists], player.inventory.equipped_items[Slots.Wrists],
player.inventory.equipped_items[Slots.Feet]]] player.inventory.equipped_items[Slots.Feet]]]
itemlist.append("Return") itemlist.append("Return")
@@ -280,8 +293,8 @@ def change_equip(player: Player):
# Logic for equipping armor based on its intended slot # Logic for equipping armor based on its intended slot
if chosen_item.slot == Slots.Helm: if chosen_item.slot == Slots.Helm:
player.inventory.equip_item(chosen_item, Slots.Helm) player.inventory.equip_item(chosen_item, Slots.Helm)
elif chosen_item.slot == Slots.Chest: elif chosen_item.slot == Slots.Armor:
player.inventory.equip_item(chosen_item, Slots.Chest) player.inventory.equip_item(chosen_item, Slots.Armor)
elif chosen_item.slot == Slots.Wrists: elif chosen_item.slot == Slots.Wrists:
player.inventory.equip_item(chosen_item, Slots.Wrists) player.inventory.equip_item(chosen_item, Slots.Wrists)
elif chosen_item.slot == Slots.Feet: elif chosen_item.slot == Slots.Feet:
@@ -347,14 +360,14 @@ def change_equip(player: Player):
def get_instructions(): def get_instructions():
descrip1 = ("There are certain commands that will be available almost anytime you are able to type,\n" descrip1 = ("There are certain commands that will be available almost anytime you are able to type\n"
"such as viewing your inventory, checking your equipped items, and also changing them.\n" "such as viewing your inventory, checking your equipped items, and also changing them.\n"
"You can also view your stats including your current and max hp.\n") "You can also view your stats including your current and max hp.\n")
descrip2 = ("Some examples are: 'Check inventory', 'Check equipment', and 'View stats'.\n" descrip2 = ("Some examples are: 'Check inventory', 'Check equipment', and 'View stats'.\n"
"To travel to a new area, just type 'Go north' or 'enter cave' etc.\n" "To travel to a new area, just type 'Go north' or 'Enter cave' etc.\n"
"To replay the description of the current area, type 'location'.") "To replay the description of the current area, type 'Location', or 'Scene'.")
print(descrip1) print(descrip1)
time.sleep(1) # Reduced sleep for faster testing time.sleep(3) # Reduced sleep for faster testing
print(descrip2) print(descrip2)
@@ -376,7 +389,7 @@ def parse(input_text):
if words[0] == "check" and words[1] in ("inventory", "bag", "backpack"): if words[0] == "check" and words[1] in ("inventory", "bag", "backpack"):
command = "inventory" command = "inventory"
return command, object1 return command, object1
elif words[0] == "check" and words[1] in ("equipment", "equip", "items"): elif words[0] == "check" and words[1] in ("equipment", "equipped", "items"):
command = "equipment" command = "equipment"
return command, object1 return command, object1
elif words[0] == "check" and words[1] == "stats": elif words[0] == "check" and words[1] == "stats":
@@ -385,7 +398,7 @@ def parse(input_text):
elif words[0] == "check" and words[1] in ("hp", "hitpoints", "health"): elif words[0] == "check" and words[1] in ("hp", "hitpoints", "health"):
command = "hp" command = "hp"
return command, object1 return command, object1
elif words[0] == "go": elif words[0] in ("go", "enter"):
command = "go" command = "go"
object1 = " ".join(words[1:]) # The rest of the words are the direction object1 = " ".join(words[1:]) # The rest of the words are the direction
return command, object1 return command, object1
@@ -393,15 +406,19 @@ def parse(input_text):
command = "take" command = "take"
object1 = " ".join(words[2:]) object1 = " ".join(words[2:])
return command, object1 return command, object1
elif words[0] == "look" and words[1] == "around" and len(words) > 2:
command = "look"
object1 = " ".join(words[2:])
return command, object1
# Single-word commands # Single-word commands
if words[0] == "help": if words[0] == "help":
command = "help" command = "help"
elif words[0] == "scene" or words[0] == "location": # Added 'location' as an alias elif words[0] in ("scene", "location"):
command = "scene" command = "scene"
elif words[0] in ("inventory", "bag", "backpack"): elif words[0] in ("inventory", "bag", "backpack"):
command = "inventory" command = "inventory"
elif words[0] in ("equip", "equipment"): elif words[0] in ("equipped", "equipment"):
command = "equipment" command = "equipment"
elif words[0] == "stats": elif words[0] == "stats":
command = "stats" command = "stats"
@@ -428,6 +445,13 @@ def parse(input_text):
else: else:
command = "loot" # User needs to specify what to loot command = "loot" # User needs to specify what to loot
object1 = None object1 = None
elif words[0] == "open":
if len(words) > 1:
command = "open"
object1 = " ".join(words[1:])
else:
command = "open" # User needs to specify what to open
object1 = None
elif words[0] == "drop": elif words[0] == "drop":
if len(words) > 1: if len(words) > 1:
command = "drop" command = "drop"
@@ -435,6 +459,7 @@ def parse(input_text):
else: else:
command = "drop" # User needs to specify what to drop command = "drop" # User needs to specify what to drop
object1 = None object1 = None
elif words[0] == "quit": elif words[0] == "quit":
command = "quit" command = "quit"
else: else: