Update functions.py
This commit is contained in:
78
functions.py
78
functions.py
@@ -1,89 +1,67 @@
|
|||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
def typingPrint(text, time, end='\n'):
|
|
||||||
for character in text:
|
|
||||||
print(character, end="")
|
|
||||||
time.sleep(0.09)
|
|
||||||
if end:
|
|
||||||
print(end, end='')
|
|
||||||
|
|
||||||
|
|
||||||
def typingInput(text, time, end='\n'):
|
|
||||||
for character in text:
|
|
||||||
print(character, end="")
|
|
||||||
time.sleep(0.09)
|
|
||||||
if end:
|
|
||||||
print(end, end='')
|
|
||||||
value = input()
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
# start game
|
# start game
|
||||||
def startGame():
|
def startGame():
|
||||||
typingPrint("Welcome, stranger.", time)
|
print("Welcome, stranger.")
|
||||||
while True:
|
while True:
|
||||||
# Name
|
# Name
|
||||||
name = typingInput("\n" + "What is your name?" + "\n" + ">> ", time).title()
|
name = input("\n" + "What is your name?" + "\n" + ">> ").title()
|
||||||
# Gender
|
# Gender
|
||||||
gender = typingInput("What is your gender? Male, Female, or Other." + "\n" + ">> ", time)
|
gender = input("What is your gender? Male, Female, or Other." + "\n" + ">> ").lower()
|
||||||
while True:
|
while True:
|
||||||
if gender.lower() not in ("male", "female", "other"):
|
if gender not in ("male", "female", "other"):
|
||||||
typingPrint("Sorry I didn't recognise that gender. Please select 'Male', 'Female', or 'Other'.", time)
|
print("Sorry I didn't recognise that gender. Please select 'Male', 'Female', or 'Other'.")
|
||||||
gender = typingInput("\n" + ">> ", time)
|
gender = input("\n" + ">> ").lower()
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
while True:
|
while True:
|
||||||
# Age
|
# Age
|
||||||
try:
|
try:
|
||||||
age = typingInput("How old are you?" + "\n" + ">> ", time)
|
age = input("How old are you?" + "\n" + ">> ")
|
||||||
age = int(age)
|
age = int(age)
|
||||||
break
|
break
|
||||||
except ValueError:
|
except ValueError:
|
||||||
typingPrint("Sorry I didn't recognise that age. Please type in a whole number.", time)
|
print("Sorry I didn't recognise that age. Please type in a whole number.")
|
||||||
continue
|
continue
|
||||||
# Double check responses
|
# Double check responses
|
||||||
correct = typingInput(f"Hello, {name}. You are a {age} year old {gender}.\nIs this correct? Y/N\n>> ", time)
|
correct = input(f"Hello, {name}. You are a {age} year old {gender}.\nIs this correct? Y/N\n>> ").lower()
|
||||||
if correct.lower() in ['y', 'yes']:
|
if correct in ['y', 'yes']:
|
||||||
break
|
break
|
||||||
elif correct.lower() in ['n', 'no']:
|
elif correct in ['n', 'no']:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
typingPrint("Sorry, I didn't catch that.\n", time)
|
print("Sorry, I didn't catch that.\n")
|
||||||
correct = typingInput(f"You are a {age} year old {gender}. \nIs this correct? Y/N\n>> ", time)
|
correct = input(f"You are a {age} year old {gender}. \nIs this correct? Y/N\n>> ").lower()
|
||||||
if correct.lower() in ['y', 'yes']:
|
if correct in ['y', 'yes']:
|
||||||
break
|
break
|
||||||
elif correct.lower() in ['n', 'no']:
|
elif correct in ['n', 'no']:
|
||||||
continue
|
continue
|
||||||
while True:
|
while True:
|
||||||
# Race
|
# Race
|
||||||
race = typingInput("Please select a race from: Human, Elf, or Dwarf.\n>> ", time)
|
race = input("Please select a race from: Human, Elf, or Dwarf.\n>> ").title()
|
||||||
while True:
|
while True:
|
||||||
if race.lower() not in ("human", "elf", "dwarf"):
|
if race.lower() not in ("human", "elf", "dwarf"):
|
||||||
race = typingInput("Sorry I didn't recognise that race. Please select 'Human', 'Elf', or 'Dwarf'.\n>> ",
|
race = input("Sorry I didn't recognise that race. Please select 'Human', "
|
||||||
time)
|
"'Elf', or 'Dwarf'.\n>> ").title()
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
# Job
|
# Job
|
||||||
job = typingInput("Please select a class from: Warrior, Ranger, or Mage.\n>> ", time)
|
job = input("Please select a class from: Warrior, Ranger, or Mage.\n>> ").lower()
|
||||||
while True:
|
while True:
|
||||||
if job.lower() not in ("warrior", "ranger", "mage"):
|
if job not in ("warrior", "ranger", "mage"):
|
||||||
job = typingInput("Sorry I didn't recognise that class. Please select 'Warrior',"
|
job = input("Sorry I didn't recognise that class. Please select 'Warrior', 'Ranger', or 'Mage'.\n>> ")
|
||||||
" 'Ranger', or 'Mage'.\n>> ", time)
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
# Final check
|
# Final check
|
||||||
correct = typingInput(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n>> ", time)
|
correct = input(f"{name}, you are a {race} {job}.\nIs this correct? Y/N\n>> ").lower()
|
||||||
if correct.lower() in ['y', 'yes']:
|
if correct in ['y', 'yes']:
|
||||||
break
|
break
|
||||||
elif correct.lower() in ['n', 'no']:
|
elif correct in ['n', 'no']:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
typingPrint("Sorry, I didn't catch that.\n", time)
|
print("Sorry, I didn't catch that.\n")
|
||||||
correct = typingInput(f"You are a {race} {job}. \nIs this correct? Y/N\n>> ", time)
|
correct = input(f"You are a {race} {job}. \nIs this correct? Y/N\n>> ").lower()
|
||||||
if correct.lower() in ['y', 'yes']:
|
if correct in ['y', 'yes']:
|
||||||
break
|
break
|
||||||
elif correct.lower() in ['n', 'no']:
|
elif correct in ['n', 'no']:
|
||||||
continue
|
continue
|
||||||
return name, gender, age, race, job
|
return name, gender, age, race, job
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user