Update functions.py

This commit is contained in:
KansaiGaijin
2022-01-29 16:09:51 +13:00
committed by GitHub
parent ebcc0d2a03
commit 93b3ce9a49

View File

@@ -9,6 +9,8 @@ def wait():
def startGame(): def startGame():
print("Welcome, stranger.") print("Welcome, stranger.")
while True: while True:
# Initialise age
age = None
# Name # Name
name = input("\n" + "What is your name?" + "\n" + ">> ").title() name = input("\n" + "What is your name?" + "\n" + ">> ").title()
# Gender # Gender
@@ -101,6 +103,7 @@ def get_instructions():
def parse(input_text): def parse(input_text):
command = input_text.lower() command = input_text.lower()
object1 = None object1 = None
remaining_words_index = None
# the .split() function splits the input_text string into a list of individual words # the .split() function splits the input_text string into a list of individual words
words = input_text.split() words = input_text.split()
@@ -109,47 +112,51 @@ def parse(input_text):
if words[0] == "help": if words[0] == "help":
command = "help" command = "help"
if words[0] == "inventory": if words[0] in ("view", "check", "show"):
if words[1] in ("inventory", "bag", "backpack"):
command = "inventory" command = "inventory"
elif words[1] in ("equipment", "equip", "items"):
command = "equipment"
elif words[1] == "stats":
command = "stats"
elif words[1] in ("hp", "hitpoints", "health"):
command = "hp"
elif words[1] == "hit" and words[2] == "points":
command = "hp"
if words[0] == "equip" or words[0] == "equipment": if words[0] in ("equip", "equipment"):
command = "equipment" command = "equipment"
# found_examine_words = False if words[0] in ("inventory", "bag", "backpack"):
# remaining_words_index = 0 command = "inventory"
# if words[0] == "examine" or words[0] == "inspect" or words[0] == "study":
# remaining_words_index = 1 found_examine_words = False
# found_examine_words = True if (words[0] == "examine") and len(words) > 1:
# if words[0] == "look" and words[1] == "at": found_examine_words = True
# remaining_words_index = 2 remaining_words_index = 1
# found_examine_words = True
# if found_examine_words:
# if found_examine_words: remaining_words = ""
# if len(words) > remaining_words_index: for i in range(remaining_words_index, len(words)):
# remaining_words = "" remaining_words += words[i]
# for i in range(remaining_words_index, len(words)): if i < len(words) - 1:
# remaining_words += words[i] remaining_words += " "
# if i < len(words)-1: command = "examine"
# remaining_words += " " object1 = remaining_words
# command = "examine"
# object1 = remaining_words found_take_words = False
# if ((words[0] == "take") and len(words) > 1) or \
# found_take_words = False ((words[0] == "pick") and (words[1] == "up") and len(words) > 2):
# if (words[0] == "take") and len(words) > 1: found_take_words = True
# found_take_words = True remaining_words_index = 1
# remaining_words_index = 1
# if found_take_words:
# if (words[0] == "pick") and (words[1] == "up") and len(words) > 2: remaining_words = ""
# found_take_words = True for i in range(remaining_words_index, len(words)):
# remaining_words_index = 1 remaining_words += words[i]
# if i < len(words) - 1:
# if found_take_words: remaining_words += " "
# remaining_words = "" command = "take"
# for i in range(remaining_words_index, len(words)): object1 = remaining_words
# remaining_words += words[i]
# if i < len(words) - 1:
# remaining_words += " "
# command = "take"
# object1 = remaining_words
return command, object1 return command, object1