Skip to content

Instantly share code, notes, and snippets.

@moycs777
Created May 31, 2021 01:20
Show Gist options
  • Save moycs777/ab6c6fe8abbbbbafeb061ca4c01fba0f to your computer and use it in GitHub Desktop.
Save moycs777/ab6c6fe8abbbbbafeb061ca4c01fba0f to your computer and use it in GitHub Desktop.
print ('Zombie´s Escape')
questions = {
'introduction': {
'question': 'Wellcome to year 2033! a zombie just appeared, do you want to kill him or run?',
'level': 1
},
'run_from_zombie': {
'question': 'You just ran from the zombie, now there are 2 sick zombie-dogs behind you, do you want to hide or keep running from the dogs?',
'level': 2
},
'kill_zombie': {
'question': 'You just killed a zombie, now do you want to hide or to explore more areas?',
'level': 2
},
'after_killing_zombie_and_hide': {
'question' : 'You just hide and you found a match and a flashlight',
'level': 3
},
'after_killing_zombie_and_explore': {
'question': 'You are exploring and suddenly you found a building, what do you choose?',
'level': 3
}
}
answers = {
'introduction': [
{
'name': 'run',
'type': 'next',
'next_question': 'run_from_zombie',
'consequence': ''
},
{
'name': 'kill',
'type': 'next',
'next_question': 'kill_zombie',
'consequence': ''
},
],
'run_from_zombie': [
{
'name': 'run',
'type': 'good_ending',
'next_question': '',
'consequence': 'You are a great runer, you manage to escape from the dogs'
},
{
'name': 'hide',
'type': 'end',
'next_question': '',
'consequence': 'You managed to hide but you stayed for a long time and you starved'
},
{
'name': 'surrender',
'type': 'end',
'next_question': '',
'consequence': 'The dogs ate you!'
}
],
'kill_zombie': [
{
'name': 'hide',
'type': 'next',
'next_question': 'after_killing_zombie_and_hide',
'consequence': ''
},
{
'name': 'explore',
'type': 'next',
'next_question': 'after_killing_zombie_and_explore',
'consequence': ''
}
],
'after_killing_zombie_and_hide': [
{
'name': 'match',
'type': 'end',
'next_question': '',
'consequence': 'You burned the forest'
},
{
'name': 'flashlight',
'type': 'good_ending',
'next_question': '',
'consequence': 'You used the flashlight to see the way to escape'
}
],
'after_killing_zombie_and_explore': [
{
'name': 'enter',
'type': 'end',
'next_question': '',
'consequence': 'You enter to the building a the zombies ate you'
},
{
'name': 'continue',
'type': 'good_ending',
'next_question': '',
'consequence': 'You found a car and manage to escape'
}
]
}
def repeat_question(question):
print("")
print("You wrote a wrong option, please make a valid choice!")
process_question(question)
def verify_answer(user_answer, question):
actual_answer = None
answer_exists = False
for key in answers[question]:
option = key['name']
if key['name'] == user_answer:
actual_answer = key
answer_exists = True
if answer_exists == False:
repeat_question(question)
else:
if actual_answer['type'] == 'next':
process_question(actual_answer['next_question'])
elif actual_answer['type'] == 'good_ending':
print(actual_answer['consequence'])
print('You win!')
else:
print(actual_answer['consequence'])
print('Game over!')
def process_answer(user_answer, question):
verify_answer(user_answer, question)
def process_question(question):
print("")
print(questions[question]['question'])
for answer in answers[question]:
print(answer['name'])
print("")
user_answer = input("your answer: ")
process_answer(user_answer.lower(), question)
process_question("introduction")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment