Text adventure game code The Next CEO of Stack OverflowSmall text adventureSimple text adventure gameFirst text-based adventure gamePartially complete text-based adventure gameText-based Adventure-Game EngineText adventure gameHaskell Text-Adventure GameText Adventure Game in PythonShort text-based adventure gameAdventure Game (text based) in C++

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Newlines in BSD sed vs gsed

Is there always a complete, orthogonal set of unitary matrices?

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

How to avoid supervisors with prejudiced views?

Can we say or write : "No, it'sn't"?

Won the lottery - how do I keep the money?

What steps are necessary to read a Modern SSD in Medieval Europe?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

Reference request: Grassmannian and Plucker coordinates in type B, C, D

How to place nodes around a circle from some initial angle?

Why the difference in type-inference over the as-pattern in two similar function definitions?

RigExpert AA-35 - Interpreting The Information

Does soap repel water?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Plot of histogram similar to output from @risk

Why did CATV standarize in 75 ohms and everyone else in 50?

Are police here, aren't itthey?

Solving system of ODEs with extra parameter

Break Away Valves for Launch

What connection does MS Office have to Netscape Navigator?

Inappropriate reference requests from Journal reviewers

Why do airplanes bank sharply to the right after air-to-air refueling?

Proper way to express "He disappeared them"



Text adventure game code



The Next CEO of Stack OverflowSmall text adventureSimple text adventure gameFirst text-based adventure gamePartially complete text-based adventure gameText-based Adventure-Game EngineText adventure gameHaskell Text-Adventure GameText Adventure Game in PythonShort text-based adventure gameAdventure Game (text based) in C++










8












$begingroup$


I'm just looking for someone to review this and see if it all works, here you go.
I must mention that once you start this code adventure, all answers to questions must be in single quotes (i.e. ') and lowercase.



import time
items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0
def game():
def house():
print ("You walk inside slowly, nearly crying because you are such a baby")
print ("You look around the building, there is a selection of objects on the ground, a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not forget, some mushrooms, picking them up will make you eat them immediately.")
print ("What do you want to do now?")
items1()
def evendeeperhouse():
print ("yeet")
def deeperhouse():
global stupid
global deagle
global stick
print ("You see a Hole In The Wall near the back of the house, do you wish to go inside?[y/n]")
print ("Should you go through the Hole In The Wall, or hang out with the unknown figure creeping up behind you?")
ch5 = str(input("Do you enter? [(enter)y/(pass)n]"))
if ch5 in ['y']:
print ("*LOUD SPRINTING NOISES* You run through the hole as fast as possible. you can hear the other being clanging a metal bar as he attempts to follow you. What do you do.")
if stupid > 4:
print ("Your level of Stupid is",stupid,"so you manage to hit your head on your way through the human sized hole, congrats, you are now even more stupid. Sadly, you did escape deeper into the house. Stupid +4")
stupid += 4
evendeeperhouse()
else:
print ("you now have a small selection of choices")
ch6 = str(input("Wanna use an item? or nah? [stick",stick,",deagle",deagle,"/(keep running)n]"))
if ch6 in ['deagle']:
print ("You turn around and fire 72 rounds into the being, as you investigate the rags remaining, you realize that you recognize the face, then realize that this guy isnt holding a metal bar, and hes wearing a uniform, oh man, you killed a cop, nice going, now they will just leave you here to die, but perhaps his vehicle is still here, you move on.")
time.sleep(3)
if ch6 in ['stick']:
print ("you turn around and stab at the being, shooing them off barely as you head into the deeper house")
print ("The tunnel collapses behind you, hopefully you wont see that creature again.")

else:
print ("You decide to turn away from the hole and end up making conversation with this creature, you both wind up finding a game of chess, playing, talking about eachother and whatnot, and you learn that they just wanted someone to play a game with, wow, fascinating, its a shame you beat a phsychotic murderer at chess, you shouldve let him win.")
time.sleep(.5)
print ("Achievement Get!")
time.sleep(.5)
print ("Metal Bar Lodged Through Spine")
time.sleep(.5)
print ("Shouldve let him win... *sigh*")
time.sleep(2)
game()
def foresttrail():
print("You leave the house with nothing but a backpack, congrats, you will likely die out here. you can see two more buildings ahead, they are in far worse shape, there is a flashlight on the ground as well, what do you do?")
def items1():
global items
global deagle
global backpack
global stick
global stupid
for x in range(4):
ch4 = str(input("Type what you would like to pick up if anything, or say no to move on like a brave little boy. [Deagle/Stick/Backpack/Mushrooms/N]"))
if "backpack" in ch4:
backpack +=1
print ("alright, you got a thug bag now, what would you like to steal?")
print ch4
print backpack
if "deagle" in ch4:
deagle+=1

if stupid > 0:
print ('alright, you got a Loaded Illegal Firearm now, youve got a stupid level of', stupid, 'you sure you know how to use this?')
else:
print ("Alright you got a gun, congrats bud, dont get yourself killed.")
print ch4
print deagle
if "stick" in ch4:
stick +=1
print ("alright, you got a stick now, in your case, this is better than the gun.")
print ch4
print stick

if "mushrooms" in ch4:
stupid +=3
print ("alright, you ate the shrooms, now you are 3 times more stupid, congrats... Stupid +3")
print ch4
print stupid
if ch4 not in items:
stupid +=1
print ("that's not a valid choice. Stupid +1")

if 'n'in ch4:
stupid + 3
print ("Somehow you manage to drop anything you just picked up and decide to leave.")
stick == 0
deagle == 0
backpack == 0

print ("Narrator-No? NO?!?! you just REFUSE?! *Thunder Cracks as a large storm has appeared outside* *The voice is Grim* You've made a mistake, Move Along.")
print ("Probably gonna die tbh")
foresttrail()
deeperhouse()






# game function
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("Welcome to the Text Based Adventure!")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
deagle == 0
backpack == 0
stick == 0
stupid == 0

time.sleep(1.5)

print ("You are walking down a forest trail among a dense stand of trees. Ahead you see a clearing. As you enter the clearing, you see the trail continue off to the south. In the clearing is a little hut about 6 feet tall.")
ch1 = str(input("Do you head down the trail(y)? I think you should go to the trail [y/y]: "))
if ch1 in ['y', 'Y']:
print("Sorry bud, the trail is FILLED with wolves, you are dead.")
game()



# Trail NOT Followed
else:
print("You decide to go look at the house first. How dare you defy me tiny being, you will pay later on.")


print ("Should you knock on the door, or pass by?")
ch2 = str(input("Do you knock? [(knock)y/(pass)n]"))
if ch2 in ['y', 'Y']:
print ("BangBangBang.” You knock on the door, but even if someone was home, your weak arms didnt make enough noise for them to hear you. The door isn’t locked. Should you open it and commit a crime?")
else:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame.")
time.sleep(1)
game()
ch3 = str(input("Do you enter? [y/n]"))
if ch3 in ['y', 'Y']:
house()
elif ch3 in ['n','N']:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame it had to end this way, well, for you, im laughing.")
game()









share|improve this question









New contributor




Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$







  • 3




    $begingroup$
    Is this supposed to be used with Python 2 or Python 3? If it's really Python 3 as the tag suggests, the code is not working correctly, since there are a few spots where you're missing the (...) behind print.
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    Leaving items aside, a text adventure is basically a directed graph: Each room is a node and you can move from one room to another depending on the edges. You could try to separate the game logic (moving between rooms) from the game data (room content, possible answers, connections between rooms). This way, you could add new rooms or change the texts just by modifying some data files without touching the python code. Once you have done this, you could try to implement how the items and the other global variables of your example are handled in a data-driven way.
    $endgroup$
    – pschill
    yesterday











  • $begingroup$
    If your goal is to make a quality text adventure, rather than to learn python, you might want to look into one of the languages specifically designed for them like Inform, TADS, or Hugo. They or their standard libraries handle a lot of common difficult pieces like parsing typed commands, modeling objects and verbs, etc.
    $endgroup$
    – aschepler
    yesterday















8












$begingroup$


I'm just looking for someone to review this and see if it all works, here you go.
I must mention that once you start this code adventure, all answers to questions must be in single quotes (i.e. ') and lowercase.



import time
items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0
def game():
def house():
print ("You walk inside slowly, nearly crying because you are such a baby")
print ("You look around the building, there is a selection of objects on the ground, a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not forget, some mushrooms, picking them up will make you eat them immediately.")
print ("What do you want to do now?")
items1()
def evendeeperhouse():
print ("yeet")
def deeperhouse():
global stupid
global deagle
global stick
print ("You see a Hole In The Wall near the back of the house, do you wish to go inside?[y/n]")
print ("Should you go through the Hole In The Wall, or hang out with the unknown figure creeping up behind you?")
ch5 = str(input("Do you enter? [(enter)y/(pass)n]"))
if ch5 in ['y']:
print ("*LOUD SPRINTING NOISES* You run through the hole as fast as possible. you can hear the other being clanging a metal bar as he attempts to follow you. What do you do.")
if stupid > 4:
print ("Your level of Stupid is",stupid,"so you manage to hit your head on your way through the human sized hole, congrats, you are now even more stupid. Sadly, you did escape deeper into the house. Stupid +4")
stupid += 4
evendeeperhouse()
else:
print ("you now have a small selection of choices")
ch6 = str(input("Wanna use an item? or nah? [stick",stick,",deagle",deagle,"/(keep running)n]"))
if ch6 in ['deagle']:
print ("You turn around and fire 72 rounds into the being, as you investigate the rags remaining, you realize that you recognize the face, then realize that this guy isnt holding a metal bar, and hes wearing a uniform, oh man, you killed a cop, nice going, now they will just leave you here to die, but perhaps his vehicle is still here, you move on.")
time.sleep(3)
if ch6 in ['stick']:
print ("you turn around and stab at the being, shooing them off barely as you head into the deeper house")
print ("The tunnel collapses behind you, hopefully you wont see that creature again.")

else:
print ("You decide to turn away from the hole and end up making conversation with this creature, you both wind up finding a game of chess, playing, talking about eachother and whatnot, and you learn that they just wanted someone to play a game with, wow, fascinating, its a shame you beat a phsychotic murderer at chess, you shouldve let him win.")
time.sleep(.5)
print ("Achievement Get!")
time.sleep(.5)
print ("Metal Bar Lodged Through Spine")
time.sleep(.5)
print ("Shouldve let him win... *sigh*")
time.sleep(2)
game()
def foresttrail():
print("You leave the house with nothing but a backpack, congrats, you will likely die out here. you can see two more buildings ahead, they are in far worse shape, there is a flashlight on the ground as well, what do you do?")
def items1():
global items
global deagle
global backpack
global stick
global stupid
for x in range(4):
ch4 = str(input("Type what you would like to pick up if anything, or say no to move on like a brave little boy. [Deagle/Stick/Backpack/Mushrooms/N]"))
if "backpack" in ch4:
backpack +=1
print ("alright, you got a thug bag now, what would you like to steal?")
print ch4
print backpack
if "deagle" in ch4:
deagle+=1

if stupid > 0:
print ('alright, you got a Loaded Illegal Firearm now, youve got a stupid level of', stupid, 'you sure you know how to use this?')
else:
print ("Alright you got a gun, congrats bud, dont get yourself killed.")
print ch4
print deagle
if "stick" in ch4:
stick +=1
print ("alright, you got a stick now, in your case, this is better than the gun.")
print ch4
print stick

if "mushrooms" in ch4:
stupid +=3
print ("alright, you ate the shrooms, now you are 3 times more stupid, congrats... Stupid +3")
print ch4
print stupid
if ch4 not in items:
stupid +=1
print ("that's not a valid choice. Stupid +1")

if 'n'in ch4:
stupid + 3
print ("Somehow you manage to drop anything you just picked up and decide to leave.")
stick == 0
deagle == 0
backpack == 0

print ("Narrator-No? NO?!?! you just REFUSE?! *Thunder Cracks as a large storm has appeared outside* *The voice is Grim* You've made a mistake, Move Along.")
print ("Probably gonna die tbh")
foresttrail()
deeperhouse()






# game function
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("Welcome to the Text Based Adventure!")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
deagle == 0
backpack == 0
stick == 0
stupid == 0

time.sleep(1.5)

print ("You are walking down a forest trail among a dense stand of trees. Ahead you see a clearing. As you enter the clearing, you see the trail continue off to the south. In the clearing is a little hut about 6 feet tall.")
ch1 = str(input("Do you head down the trail(y)? I think you should go to the trail [y/y]: "))
if ch1 in ['y', 'Y']:
print("Sorry bud, the trail is FILLED with wolves, you are dead.")
game()



# Trail NOT Followed
else:
print("You decide to go look at the house first. How dare you defy me tiny being, you will pay later on.")


print ("Should you knock on the door, or pass by?")
ch2 = str(input("Do you knock? [(knock)y/(pass)n]"))
if ch2 in ['y', 'Y']:
print ("BangBangBang.” You knock on the door, but even if someone was home, your weak arms didnt make enough noise for them to hear you. The door isn’t locked. Should you open it and commit a crime?")
else:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame.")
time.sleep(1)
game()
ch3 = str(input("Do you enter? [y/n]"))
if ch3 in ['y', 'Y']:
house()
elif ch3 in ['n','N']:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame it had to end this way, well, for you, im laughing.")
game()









share|improve this question









New contributor




Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$







  • 3




    $begingroup$
    Is this supposed to be used with Python 2 or Python 3? If it's really Python 3 as the tag suggests, the code is not working correctly, since there are a few spots where you're missing the (...) behind print.
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    Leaving items aside, a text adventure is basically a directed graph: Each room is a node and you can move from one room to another depending on the edges. You could try to separate the game logic (moving between rooms) from the game data (room content, possible answers, connections between rooms). This way, you could add new rooms or change the texts just by modifying some data files without touching the python code. Once you have done this, you could try to implement how the items and the other global variables of your example are handled in a data-driven way.
    $endgroup$
    – pschill
    yesterday











  • $begingroup$
    If your goal is to make a quality text adventure, rather than to learn python, you might want to look into one of the languages specifically designed for them like Inform, TADS, or Hugo. They or their standard libraries handle a lot of common difficult pieces like parsing typed commands, modeling objects and verbs, etc.
    $endgroup$
    – aschepler
    yesterday













8












8








8





$begingroup$


I'm just looking for someone to review this and see if it all works, here you go.
I must mention that once you start this code adventure, all answers to questions must be in single quotes (i.e. ') and lowercase.



import time
items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0
def game():
def house():
print ("You walk inside slowly, nearly crying because you are such a baby")
print ("You look around the building, there is a selection of objects on the ground, a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not forget, some mushrooms, picking them up will make you eat them immediately.")
print ("What do you want to do now?")
items1()
def evendeeperhouse():
print ("yeet")
def deeperhouse():
global stupid
global deagle
global stick
print ("You see a Hole In The Wall near the back of the house, do you wish to go inside?[y/n]")
print ("Should you go through the Hole In The Wall, or hang out with the unknown figure creeping up behind you?")
ch5 = str(input("Do you enter? [(enter)y/(pass)n]"))
if ch5 in ['y']:
print ("*LOUD SPRINTING NOISES* You run through the hole as fast as possible. you can hear the other being clanging a metal bar as he attempts to follow you. What do you do.")
if stupid > 4:
print ("Your level of Stupid is",stupid,"so you manage to hit your head on your way through the human sized hole, congrats, you are now even more stupid. Sadly, you did escape deeper into the house. Stupid +4")
stupid += 4
evendeeperhouse()
else:
print ("you now have a small selection of choices")
ch6 = str(input("Wanna use an item? or nah? [stick",stick,",deagle",deagle,"/(keep running)n]"))
if ch6 in ['deagle']:
print ("You turn around and fire 72 rounds into the being, as you investigate the rags remaining, you realize that you recognize the face, then realize that this guy isnt holding a metal bar, and hes wearing a uniform, oh man, you killed a cop, nice going, now they will just leave you here to die, but perhaps his vehicle is still here, you move on.")
time.sleep(3)
if ch6 in ['stick']:
print ("you turn around and stab at the being, shooing them off barely as you head into the deeper house")
print ("The tunnel collapses behind you, hopefully you wont see that creature again.")

else:
print ("You decide to turn away from the hole and end up making conversation with this creature, you both wind up finding a game of chess, playing, talking about eachother and whatnot, and you learn that they just wanted someone to play a game with, wow, fascinating, its a shame you beat a phsychotic murderer at chess, you shouldve let him win.")
time.sleep(.5)
print ("Achievement Get!")
time.sleep(.5)
print ("Metal Bar Lodged Through Spine")
time.sleep(.5)
print ("Shouldve let him win... *sigh*")
time.sleep(2)
game()
def foresttrail():
print("You leave the house with nothing but a backpack, congrats, you will likely die out here. you can see two more buildings ahead, they are in far worse shape, there is a flashlight on the ground as well, what do you do?")
def items1():
global items
global deagle
global backpack
global stick
global stupid
for x in range(4):
ch4 = str(input("Type what you would like to pick up if anything, or say no to move on like a brave little boy. [Deagle/Stick/Backpack/Mushrooms/N]"))
if "backpack" in ch4:
backpack +=1
print ("alright, you got a thug bag now, what would you like to steal?")
print ch4
print backpack
if "deagle" in ch4:
deagle+=1

if stupid > 0:
print ('alright, you got a Loaded Illegal Firearm now, youve got a stupid level of', stupid, 'you sure you know how to use this?')
else:
print ("Alright you got a gun, congrats bud, dont get yourself killed.")
print ch4
print deagle
if "stick" in ch4:
stick +=1
print ("alright, you got a stick now, in your case, this is better than the gun.")
print ch4
print stick

if "mushrooms" in ch4:
stupid +=3
print ("alright, you ate the shrooms, now you are 3 times more stupid, congrats... Stupid +3")
print ch4
print stupid
if ch4 not in items:
stupid +=1
print ("that's not a valid choice. Stupid +1")

if 'n'in ch4:
stupid + 3
print ("Somehow you manage to drop anything you just picked up and decide to leave.")
stick == 0
deagle == 0
backpack == 0

print ("Narrator-No? NO?!?! you just REFUSE?! *Thunder Cracks as a large storm has appeared outside* *The voice is Grim* You've made a mistake, Move Along.")
print ("Probably gonna die tbh")
foresttrail()
deeperhouse()






# game function
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("Welcome to the Text Based Adventure!")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
deagle == 0
backpack == 0
stick == 0
stupid == 0

time.sleep(1.5)

print ("You are walking down a forest trail among a dense stand of trees. Ahead you see a clearing. As you enter the clearing, you see the trail continue off to the south. In the clearing is a little hut about 6 feet tall.")
ch1 = str(input("Do you head down the trail(y)? I think you should go to the trail [y/y]: "))
if ch1 in ['y', 'Y']:
print("Sorry bud, the trail is FILLED with wolves, you are dead.")
game()



# Trail NOT Followed
else:
print("You decide to go look at the house first. How dare you defy me tiny being, you will pay later on.")


print ("Should you knock on the door, or pass by?")
ch2 = str(input("Do you knock? [(knock)y/(pass)n]"))
if ch2 in ['y', 'Y']:
print ("BangBangBang.” You knock on the door, but even if someone was home, your weak arms didnt make enough noise for them to hear you. The door isn’t locked. Should you open it and commit a crime?")
else:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame.")
time.sleep(1)
game()
ch3 = str(input("Do you enter? [y/n]"))
if ch3 in ['y', 'Y']:
house()
elif ch3 in ['n','N']:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame it had to end this way, well, for you, im laughing.")
game()









share|improve this question









New contributor




Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I'm just looking for someone to review this and see if it all works, here you go.
I must mention that once you start this code adventure, all answers to questions must be in single quotes (i.e. ') and lowercase.



import time
items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0
def game():
def house():
print ("You walk inside slowly, nearly crying because you are such a baby")
print ("You look around the building, there is a selection of objects on the ground, a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not forget, some mushrooms, picking them up will make you eat them immediately.")
print ("What do you want to do now?")
items1()
def evendeeperhouse():
print ("yeet")
def deeperhouse():
global stupid
global deagle
global stick
print ("You see a Hole In The Wall near the back of the house, do you wish to go inside?[y/n]")
print ("Should you go through the Hole In The Wall, or hang out with the unknown figure creeping up behind you?")
ch5 = str(input("Do you enter? [(enter)y/(pass)n]"))
if ch5 in ['y']:
print ("*LOUD SPRINTING NOISES* You run through the hole as fast as possible. you can hear the other being clanging a metal bar as he attempts to follow you. What do you do.")
if stupid > 4:
print ("Your level of Stupid is",stupid,"so you manage to hit your head on your way through the human sized hole, congrats, you are now even more stupid. Sadly, you did escape deeper into the house. Stupid +4")
stupid += 4
evendeeperhouse()
else:
print ("you now have a small selection of choices")
ch6 = str(input("Wanna use an item? or nah? [stick",stick,",deagle",deagle,"/(keep running)n]"))
if ch6 in ['deagle']:
print ("You turn around and fire 72 rounds into the being, as you investigate the rags remaining, you realize that you recognize the face, then realize that this guy isnt holding a metal bar, and hes wearing a uniform, oh man, you killed a cop, nice going, now they will just leave you here to die, but perhaps his vehicle is still here, you move on.")
time.sleep(3)
if ch6 in ['stick']:
print ("you turn around and stab at the being, shooing them off barely as you head into the deeper house")
print ("The tunnel collapses behind you, hopefully you wont see that creature again.")

else:
print ("You decide to turn away from the hole and end up making conversation with this creature, you both wind up finding a game of chess, playing, talking about eachother and whatnot, and you learn that they just wanted someone to play a game with, wow, fascinating, its a shame you beat a phsychotic murderer at chess, you shouldve let him win.")
time.sleep(.5)
print ("Achievement Get!")
time.sleep(.5)
print ("Metal Bar Lodged Through Spine")
time.sleep(.5)
print ("Shouldve let him win... *sigh*")
time.sleep(2)
game()
def foresttrail():
print("You leave the house with nothing but a backpack, congrats, you will likely die out here. you can see two more buildings ahead, they are in far worse shape, there is a flashlight on the ground as well, what do you do?")
def items1():
global items
global deagle
global backpack
global stick
global stupid
for x in range(4):
ch4 = str(input("Type what you would like to pick up if anything, or say no to move on like a brave little boy. [Deagle/Stick/Backpack/Mushrooms/N]"))
if "backpack" in ch4:
backpack +=1
print ("alright, you got a thug bag now, what would you like to steal?")
print ch4
print backpack
if "deagle" in ch4:
deagle+=1

if stupid > 0:
print ('alright, you got a Loaded Illegal Firearm now, youve got a stupid level of', stupid, 'you sure you know how to use this?')
else:
print ("Alright you got a gun, congrats bud, dont get yourself killed.")
print ch4
print deagle
if "stick" in ch4:
stick +=1
print ("alright, you got a stick now, in your case, this is better than the gun.")
print ch4
print stick

if "mushrooms" in ch4:
stupid +=3
print ("alright, you ate the shrooms, now you are 3 times more stupid, congrats... Stupid +3")
print ch4
print stupid
if ch4 not in items:
stupid +=1
print ("that's not a valid choice. Stupid +1")

if 'n'in ch4:
stupid + 3
print ("Somehow you manage to drop anything you just picked up and decide to leave.")
stick == 0
deagle == 0
backpack == 0

print ("Narrator-No? NO?!?! you just REFUSE?! *Thunder Cracks as a large storm has appeared outside* *The voice is Grim* You've made a mistake, Move Along.")
print ("Probably gonna die tbh")
foresttrail()
deeperhouse()






# game function
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("Welcome to the Text Based Adventure!")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
deagle == 0
backpack == 0
stick == 0
stupid == 0

time.sleep(1.5)

print ("You are walking down a forest trail among a dense stand of trees. Ahead you see a clearing. As you enter the clearing, you see the trail continue off to the south. In the clearing is a little hut about 6 feet tall.")
ch1 = str(input("Do you head down the trail(y)? I think you should go to the trail [y/y]: "))
if ch1 in ['y', 'Y']:
print("Sorry bud, the trail is FILLED with wolves, you are dead.")
game()



# Trail NOT Followed
else:
print("You decide to go look at the house first. How dare you defy me tiny being, you will pay later on.")


print ("Should you knock on the door, or pass by?")
ch2 = str(input("Do you knock? [(knock)y/(pass)n]"))
if ch2 in ['y', 'Y']:
print ("BangBangBang.” You knock on the door, but even if someone was home, your weak arms didnt make enough noise for them to hear you. The door isn’t locked. Should you open it and commit a crime?")
else:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame.")
time.sleep(1)
game()
ch3 = str(input("Do you enter? [y/n]"))
if ch3 in ['y', 'Y']:
house()
elif ch3 in ['n','N']:
print ("You walk away from the house slowly because you are too scared, lucky for you, a car happens to pull up, oh no! they cant stop because of the mud, they slam into you and you die on impact, twas a shame it had to end this way, well, for you, im laughing.")
game()






python python-3.x game adventure-game






share|improve this question









New contributor




Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Sᴀᴍ Onᴇᴌᴀ

9,98662166




9,98662166






New contributor




Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Some School KidSome School Kid

412




412




New contributor




Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Some School Kid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 3




    $begingroup$
    Is this supposed to be used with Python 2 or Python 3? If it's really Python 3 as the tag suggests, the code is not working correctly, since there are a few spots where you're missing the (...) behind print.
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    Leaving items aside, a text adventure is basically a directed graph: Each room is a node and you can move from one room to another depending on the edges. You could try to separate the game logic (moving between rooms) from the game data (room content, possible answers, connections between rooms). This way, you could add new rooms or change the texts just by modifying some data files without touching the python code. Once you have done this, you could try to implement how the items and the other global variables of your example are handled in a data-driven way.
    $endgroup$
    – pschill
    yesterday











  • $begingroup$
    If your goal is to make a quality text adventure, rather than to learn python, you might want to look into one of the languages specifically designed for them like Inform, TADS, or Hugo. They or their standard libraries handle a lot of common difficult pieces like parsing typed commands, modeling objects and verbs, etc.
    $endgroup$
    – aschepler
    yesterday












  • 3




    $begingroup$
    Is this supposed to be used with Python 2 or Python 3? If it's really Python 3 as the tag suggests, the code is not working correctly, since there are a few spots where you're missing the (...) behind print.
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    Leaving items aside, a text adventure is basically a directed graph: Each room is a node and you can move from one room to another depending on the edges. You could try to separate the game logic (moving between rooms) from the game data (room content, possible answers, connections between rooms). This way, you could add new rooms or change the texts just by modifying some data files without touching the python code. Once you have done this, you could try to implement how the items and the other global variables of your example are handled in a data-driven way.
    $endgroup$
    – pschill
    yesterday











  • $begingroup$
    If your goal is to make a quality text adventure, rather than to learn python, you might want to look into one of the languages specifically designed for them like Inform, TADS, or Hugo. They or their standard libraries handle a lot of common difficult pieces like parsing typed commands, modeling objects and verbs, etc.
    $endgroup$
    – aschepler
    yesterday







3




3




$begingroup$
Is this supposed to be used with Python 2 or Python 3? If it's really Python 3 as the tag suggests, the code is not working correctly, since there are a few spots where you're missing the (...) behind print.
$endgroup$
– Alex
2 days ago




$begingroup$
Is this supposed to be used with Python 2 or Python 3? If it's really Python 3 as the tag suggests, the code is not working correctly, since there are a few spots where you're missing the (...) behind print.
$endgroup$
– Alex
2 days ago












$begingroup$
Leaving items aside, a text adventure is basically a directed graph: Each room is a node and you can move from one room to another depending on the edges. You could try to separate the game logic (moving between rooms) from the game data (room content, possible answers, connections between rooms). This way, you could add new rooms or change the texts just by modifying some data files without touching the python code. Once you have done this, you could try to implement how the items and the other global variables of your example are handled in a data-driven way.
$endgroup$
– pschill
yesterday





$begingroup$
Leaving items aside, a text adventure is basically a directed graph: Each room is a node and you can move from one room to another depending on the edges. You could try to separate the game logic (moving between rooms) from the game data (room content, possible answers, connections between rooms). This way, you could add new rooms or change the texts just by modifying some data files without touching the python code. Once you have done this, you could try to implement how the items and the other global variables of your example are handled in a data-driven way.
$endgroup$
– pschill
yesterday













$begingroup$
If your goal is to make a quality text adventure, rather than to learn python, you might want to look into one of the languages specifically designed for them like Inform, TADS, or Hugo. They or their standard libraries handle a lot of common difficult pieces like parsing typed commands, modeling objects and verbs, etc.
$endgroup$
– aschepler
yesterday




$begingroup$
If your goal is to make a quality text adventure, rather than to learn python, you might want to look into one of the languages specifically designed for them like Inform, TADS, or Hugo. They or their standard libraries handle a lot of common difficult pieces like parsing typed commands, modeling objects and verbs, etc.
$endgroup$
– aschepler
yesterday










2 Answers
2






active

oldest

votes


















7












$begingroup$

Welcome to CodeReview. Your program is a fun start to programming, and Python is a great way to learn. For the following topics, I'm going to trust your ability to google, but if you can't find the appropriate documentation leave a comment and I'll add some links.



Avoid globals



Sometimes globals can be useful, but more often they hinder a developer's ability to maintain and debug code. It's a better idea to group related variables together into a class. This applies to the following variables:



items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0


Avoid stringly-typed objects



These things:



items = ['backpack','deagle','stick','mushrooms']


are strings. But in this case, it's not very good practice to handle them as strings until they need to be presented to the user. In other words, in this statement:



if "mushrooms" in ch4:


What if you misspelled 'mushrooms'? You wouldn't know until halfway through a program run; in other words, string-typing hinders static analysis, among other problems. One solution to this is to have an enum: a kind of object that can take only one of a set of mutually exclusive values. In other words, an item can be only a backpack, or a deagle, or a stick, or a mushroom. Python IDEs are better able to perform static analysis on this, and programmers make fewer errors when following this strategy.



Indenting



For legibility, you should ensure that each additional level of indentation only introduces 3-4 characters - pick one and stick with it. This:



 def items1():
global items


is too far in for the comfort of most developers.



These aren't assignments



 deagle == 0
backpack == 0
stick == 0
stupid == 0


They're comparisons. Assignments need only one =.



Input comparison



This:



if ch3 in ['y', 'Y']:


is more easily done by first converting the character to lowercase, and then comparing it to a single character; in other words:



if ch3.lower() == 'y':





share|improve this answer











$endgroup$








  • 1




    $begingroup$
    The last time I wanted to convert something to lowercase it was sth.lower() ;-)
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    @Alex thanks; language cross talk.
    $endgroup$
    – Reinderien
    yesterday


















5












$begingroup$

There are a few points I would like to add ontop of the feedback already given by Reinderien.



Remove nested functions



There is no good reason to define house(), deeperhouse(), etc. inside of game(). If your plan was to hide them from the user in this ways, you have probably chosen the wrong language. If you intend to indicate that these are not to be used directly, prefix their name with a leading underscore _house(). This is a common convention to notify others that these functions are not intended to be used by them and are subject to change/removal/... without further notice.



Also think about how you use these functions. Basically, your game's "flow" is encoded in them by calling deeper and deeper into other functions without ever returning.



Break lines to improve readability



Your text message come in super-long lines of text. Most text editors support automatic line breaking or soft wrap to cram those lines to the available screen width, but some don't (like the code preview here) or are deliberately configured not to do so. So be nice and break your lines if they get to long.

Python's official style guide recommends 79/80 characters as maximum line length, although most modern IDEs and their style tools let you get away with about 100 (without manual tweaking) before getting upset.

Python allows you to do this within the parenthesis of a function call without further line continuation markers.



Applying this to house(), your code could look like this:



def house():
print("You walk inside slowly, nearly crying because you are such a baby")
print("You look around the building, there is a selection of objects on the ground, "
"a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not "
"forget, some mushrooms, picking them up will make you eat them immediately.")
print("What do you want to do now?")
items1()


For more information on this refer to the previous link.






share|improve this answer











$endgroup$












  • $begingroup$
    I'm rather startled that you're just telling OP to unindent the nested functions, when they are clearly using function calls as a substitute for goto. Nothing ever returns!
    $endgroup$
    – Kevin
    yesterday











  • $begingroup$
    @Kevin: Yep, that's absolutely true and I'm fully aware of this. I added a note on that topic, but without further explanation towards a solution. Feel free to give the OP feedback yourself, and I will be happy to upvote your answer!
    $endgroup$
    – Alex
    yesterday










  • $begingroup$
    I'd also offer that either a single print with a docstring, or a single print with implicit string concatenation - print("foo" "bar") - are more appropriate than multiple prints.
    $endgroup$
    – Reinderien
    yesterday











Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Some School Kid is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216442%2ftext-adventure-game-code%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









7












$begingroup$

Welcome to CodeReview. Your program is a fun start to programming, and Python is a great way to learn. For the following topics, I'm going to trust your ability to google, but if you can't find the appropriate documentation leave a comment and I'll add some links.



Avoid globals



Sometimes globals can be useful, but more often they hinder a developer's ability to maintain and debug code. It's a better idea to group related variables together into a class. This applies to the following variables:



items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0


Avoid stringly-typed objects



These things:



items = ['backpack','deagle','stick','mushrooms']


are strings. But in this case, it's not very good practice to handle them as strings until they need to be presented to the user. In other words, in this statement:



if "mushrooms" in ch4:


What if you misspelled 'mushrooms'? You wouldn't know until halfway through a program run; in other words, string-typing hinders static analysis, among other problems. One solution to this is to have an enum: a kind of object that can take only one of a set of mutually exclusive values. In other words, an item can be only a backpack, or a deagle, or a stick, or a mushroom. Python IDEs are better able to perform static analysis on this, and programmers make fewer errors when following this strategy.



Indenting



For legibility, you should ensure that each additional level of indentation only introduces 3-4 characters - pick one and stick with it. This:



 def items1():
global items


is too far in for the comfort of most developers.



These aren't assignments



 deagle == 0
backpack == 0
stick == 0
stupid == 0


They're comparisons. Assignments need only one =.



Input comparison



This:



if ch3 in ['y', 'Y']:


is more easily done by first converting the character to lowercase, and then comparing it to a single character; in other words:



if ch3.lower() == 'y':





share|improve this answer











$endgroup$








  • 1




    $begingroup$
    The last time I wanted to convert something to lowercase it was sth.lower() ;-)
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    @Alex thanks; language cross talk.
    $endgroup$
    – Reinderien
    yesterday















7












$begingroup$

Welcome to CodeReview. Your program is a fun start to programming, and Python is a great way to learn. For the following topics, I'm going to trust your ability to google, but if you can't find the appropriate documentation leave a comment and I'll add some links.



Avoid globals



Sometimes globals can be useful, but more often they hinder a developer's ability to maintain and debug code. It's a better idea to group related variables together into a class. This applies to the following variables:



items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0


Avoid stringly-typed objects



These things:



items = ['backpack','deagle','stick','mushrooms']


are strings. But in this case, it's not very good practice to handle them as strings until they need to be presented to the user. In other words, in this statement:



if "mushrooms" in ch4:


What if you misspelled 'mushrooms'? You wouldn't know until halfway through a program run; in other words, string-typing hinders static analysis, among other problems. One solution to this is to have an enum: a kind of object that can take only one of a set of mutually exclusive values. In other words, an item can be only a backpack, or a deagle, or a stick, or a mushroom. Python IDEs are better able to perform static analysis on this, and programmers make fewer errors when following this strategy.



Indenting



For legibility, you should ensure that each additional level of indentation only introduces 3-4 characters - pick one and stick with it. This:



 def items1():
global items


is too far in for the comfort of most developers.



These aren't assignments



 deagle == 0
backpack == 0
stick == 0
stupid == 0


They're comparisons. Assignments need only one =.



Input comparison



This:



if ch3 in ['y', 'Y']:


is more easily done by first converting the character to lowercase, and then comparing it to a single character; in other words:



if ch3.lower() == 'y':





share|improve this answer











$endgroup$








  • 1




    $begingroup$
    The last time I wanted to convert something to lowercase it was sth.lower() ;-)
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    @Alex thanks; language cross talk.
    $endgroup$
    – Reinderien
    yesterday













7












7








7





$begingroup$

Welcome to CodeReview. Your program is a fun start to programming, and Python is a great way to learn. For the following topics, I'm going to trust your ability to google, but if you can't find the appropriate documentation leave a comment and I'll add some links.



Avoid globals



Sometimes globals can be useful, but more often they hinder a developer's ability to maintain and debug code. It's a better idea to group related variables together into a class. This applies to the following variables:



items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0


Avoid stringly-typed objects



These things:



items = ['backpack','deagle','stick','mushrooms']


are strings. But in this case, it's not very good practice to handle them as strings until they need to be presented to the user. In other words, in this statement:



if "mushrooms" in ch4:


What if you misspelled 'mushrooms'? You wouldn't know until halfway through a program run; in other words, string-typing hinders static analysis, among other problems. One solution to this is to have an enum: a kind of object that can take only one of a set of mutually exclusive values. In other words, an item can be only a backpack, or a deagle, or a stick, or a mushroom. Python IDEs are better able to perform static analysis on this, and programmers make fewer errors when following this strategy.



Indenting



For legibility, you should ensure that each additional level of indentation only introduces 3-4 characters - pick one and stick with it. This:



 def items1():
global items


is too far in for the comfort of most developers.



These aren't assignments



 deagle == 0
backpack == 0
stick == 0
stupid == 0


They're comparisons. Assignments need only one =.



Input comparison



This:



if ch3 in ['y', 'Y']:


is more easily done by first converting the character to lowercase, and then comparing it to a single character; in other words:



if ch3.lower() == 'y':





share|improve this answer











$endgroup$



Welcome to CodeReview. Your program is a fun start to programming, and Python is a great way to learn. For the following topics, I'm going to trust your ability to google, but if you can't find the appropriate documentation leave a comment and I'll add some links.



Avoid globals



Sometimes globals can be useful, but more often they hinder a developer's ability to maintain and debug code. It's a better idea to group related variables together into a class. This applies to the following variables:



items = ['backpack','deagle','stick','mushrooms']
stupid = 0
backpack = 0
deagle = 0
stick = 0


Avoid stringly-typed objects



These things:



items = ['backpack','deagle','stick','mushrooms']


are strings. But in this case, it's not very good practice to handle them as strings until they need to be presented to the user. In other words, in this statement:



if "mushrooms" in ch4:


What if you misspelled 'mushrooms'? You wouldn't know until halfway through a program run; in other words, string-typing hinders static analysis, among other problems. One solution to this is to have an enum: a kind of object that can take only one of a set of mutually exclusive values. In other words, an item can be only a backpack, or a deagle, or a stick, or a mushroom. Python IDEs are better able to perform static analysis on this, and programmers make fewer errors when following this strategy.



Indenting



For legibility, you should ensure that each additional level of indentation only introduces 3-4 characters - pick one and stick with it. This:



 def items1():
global items


is too far in for the comfort of most developers.



These aren't assignments



 deagle == 0
backpack == 0
stick == 0
stupid == 0


They're comparisons. Assignments need only one =.



Input comparison



This:



if ch3 in ['y', 'Y']:


is more easily done by first converting the character to lowercase, and then comparing it to a single character; in other words:



if ch3.lower() == 'y':






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered 2 days ago









ReinderienReinderien

4,965925




4,965925







  • 1




    $begingroup$
    The last time I wanted to convert something to lowercase it was sth.lower() ;-)
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    @Alex thanks; language cross talk.
    $endgroup$
    – Reinderien
    yesterday












  • 1




    $begingroup$
    The last time I wanted to convert something to lowercase it was sth.lower() ;-)
    $endgroup$
    – Alex
    2 days ago










  • $begingroup$
    @Alex thanks; language cross talk.
    $endgroup$
    – Reinderien
    yesterday







1




1




$begingroup$
The last time I wanted to convert something to lowercase it was sth.lower() ;-)
$endgroup$
– Alex
2 days ago




$begingroup$
The last time I wanted to convert something to lowercase it was sth.lower() ;-)
$endgroup$
– Alex
2 days ago












$begingroup$
@Alex thanks; language cross talk.
$endgroup$
– Reinderien
yesterday




$begingroup$
@Alex thanks; language cross talk.
$endgroup$
– Reinderien
yesterday













5












$begingroup$

There are a few points I would like to add ontop of the feedback already given by Reinderien.



Remove nested functions



There is no good reason to define house(), deeperhouse(), etc. inside of game(). If your plan was to hide them from the user in this ways, you have probably chosen the wrong language. If you intend to indicate that these are not to be used directly, prefix their name with a leading underscore _house(). This is a common convention to notify others that these functions are not intended to be used by them and are subject to change/removal/... without further notice.



Also think about how you use these functions. Basically, your game's "flow" is encoded in them by calling deeper and deeper into other functions without ever returning.



Break lines to improve readability



Your text message come in super-long lines of text. Most text editors support automatic line breaking or soft wrap to cram those lines to the available screen width, but some don't (like the code preview here) or are deliberately configured not to do so. So be nice and break your lines if they get to long.

Python's official style guide recommends 79/80 characters as maximum line length, although most modern IDEs and their style tools let you get away with about 100 (without manual tweaking) before getting upset.

Python allows you to do this within the parenthesis of a function call without further line continuation markers.



Applying this to house(), your code could look like this:



def house():
print("You walk inside slowly, nearly crying because you are such a baby")
print("You look around the building, there is a selection of objects on the ground, "
"a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not "
"forget, some mushrooms, picking them up will make you eat them immediately.")
print("What do you want to do now?")
items1()


For more information on this refer to the previous link.






share|improve this answer











$endgroup$












  • $begingroup$
    I'm rather startled that you're just telling OP to unindent the nested functions, when they are clearly using function calls as a substitute for goto. Nothing ever returns!
    $endgroup$
    – Kevin
    yesterday











  • $begingroup$
    @Kevin: Yep, that's absolutely true and I'm fully aware of this. I added a note on that topic, but without further explanation towards a solution. Feel free to give the OP feedback yourself, and I will be happy to upvote your answer!
    $endgroup$
    – Alex
    yesterday










  • $begingroup$
    I'd also offer that either a single print with a docstring, or a single print with implicit string concatenation - print("foo" "bar") - are more appropriate than multiple prints.
    $endgroup$
    – Reinderien
    yesterday















5












$begingroup$

There are a few points I would like to add ontop of the feedback already given by Reinderien.



Remove nested functions



There is no good reason to define house(), deeperhouse(), etc. inside of game(). If your plan was to hide them from the user in this ways, you have probably chosen the wrong language. If you intend to indicate that these are not to be used directly, prefix their name with a leading underscore _house(). This is a common convention to notify others that these functions are not intended to be used by them and are subject to change/removal/... without further notice.



Also think about how you use these functions. Basically, your game's "flow" is encoded in them by calling deeper and deeper into other functions without ever returning.



Break lines to improve readability



Your text message come in super-long lines of text. Most text editors support automatic line breaking or soft wrap to cram those lines to the available screen width, but some don't (like the code preview here) or are deliberately configured not to do so. So be nice and break your lines if they get to long.

Python's official style guide recommends 79/80 characters as maximum line length, although most modern IDEs and their style tools let you get away with about 100 (without manual tweaking) before getting upset.

Python allows you to do this within the parenthesis of a function call without further line continuation markers.



Applying this to house(), your code could look like this:



def house():
print("You walk inside slowly, nearly crying because you are such a baby")
print("You look around the building, there is a selection of objects on the ground, "
"a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not "
"forget, some mushrooms, picking them up will make you eat them immediately.")
print("What do you want to do now?")
items1()


For more information on this refer to the previous link.






share|improve this answer











$endgroup$












  • $begingroup$
    I'm rather startled that you're just telling OP to unindent the nested functions, when they are clearly using function calls as a substitute for goto. Nothing ever returns!
    $endgroup$
    – Kevin
    yesterday











  • $begingroup$
    @Kevin: Yep, that's absolutely true and I'm fully aware of this. I added a note on that topic, but without further explanation towards a solution. Feel free to give the OP feedback yourself, and I will be happy to upvote your answer!
    $endgroup$
    – Alex
    yesterday










  • $begingroup$
    I'd also offer that either a single print with a docstring, or a single print with implicit string concatenation - print("foo" "bar") - are more appropriate than multiple prints.
    $endgroup$
    – Reinderien
    yesterday













5












5








5





$begingroup$

There are a few points I would like to add ontop of the feedback already given by Reinderien.



Remove nested functions



There is no good reason to define house(), deeperhouse(), etc. inside of game(). If your plan was to hide them from the user in this ways, you have probably chosen the wrong language. If you intend to indicate that these are not to be used directly, prefix their name with a leading underscore _house(). This is a common convention to notify others that these functions are not intended to be used by them and are subject to change/removal/... without further notice.



Also think about how you use these functions. Basically, your game's "flow" is encoded in them by calling deeper and deeper into other functions without ever returning.



Break lines to improve readability



Your text message come in super-long lines of text. Most text editors support automatic line breaking or soft wrap to cram those lines to the available screen width, but some don't (like the code preview here) or are deliberately configured not to do so. So be nice and break your lines if they get to long.

Python's official style guide recommends 79/80 characters as maximum line length, although most modern IDEs and their style tools let you get away with about 100 (without manual tweaking) before getting upset.

Python allows you to do this within the parenthesis of a function call without further line continuation markers.



Applying this to house(), your code could look like this:



def house():
print("You walk inside slowly, nearly crying because you are such a baby")
print("You look around the building, there is a selection of objects on the ground, "
"a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not "
"forget, some mushrooms, picking them up will make you eat them immediately.")
print("What do you want to do now?")
items1()


For more information on this refer to the previous link.






share|improve this answer











$endgroup$



There are a few points I would like to add ontop of the feedback already given by Reinderien.



Remove nested functions



There is no good reason to define house(), deeperhouse(), etc. inside of game(). If your plan was to hide them from the user in this ways, you have probably chosen the wrong language. If you intend to indicate that these are not to be used directly, prefix their name with a leading underscore _house(). This is a common convention to notify others that these functions are not intended to be used by them and are subject to change/removal/... without further notice.



Also think about how you use these functions. Basically, your game's "flow" is encoded in them by calling deeper and deeper into other functions without ever returning.



Break lines to improve readability



Your text message come in super-long lines of text. Most text editors support automatic line breaking or soft wrap to cram those lines to the available screen width, but some don't (like the code preview here) or are deliberately configured not to do so. So be nice and break your lines if they get to long.

Python's official style guide recommends 79/80 characters as maximum line length, although most modern IDEs and their style tools let you get away with about 100 (without manual tweaking) before getting upset.

Python allows you to do this within the parenthesis of a function call without further line continuation markers.



Applying this to house(), your code could look like this:



def house():
print("You walk inside slowly, nearly crying because you are such a baby")
print("You look around the building, there is a selection of objects on the ground, "
"a stick, a backpack, and a deagle with 100 rounds next to it. oh and lest we not "
"forget, some mushrooms, picking them up will make you eat them immediately.")
print("What do you want to do now?")
items1()


For more information on this refer to the previous link.







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









AlexAlex

1,295418




1,295418











  • $begingroup$
    I'm rather startled that you're just telling OP to unindent the nested functions, when they are clearly using function calls as a substitute for goto. Nothing ever returns!
    $endgroup$
    – Kevin
    yesterday











  • $begingroup$
    @Kevin: Yep, that's absolutely true and I'm fully aware of this. I added a note on that topic, but without further explanation towards a solution. Feel free to give the OP feedback yourself, and I will be happy to upvote your answer!
    $endgroup$
    – Alex
    yesterday










  • $begingroup$
    I'd also offer that either a single print with a docstring, or a single print with implicit string concatenation - print("foo" "bar") - are more appropriate than multiple prints.
    $endgroup$
    – Reinderien
    yesterday
















  • $begingroup$
    I'm rather startled that you're just telling OP to unindent the nested functions, when they are clearly using function calls as a substitute for goto. Nothing ever returns!
    $endgroup$
    – Kevin
    yesterday











  • $begingroup$
    @Kevin: Yep, that's absolutely true and I'm fully aware of this. I added a note on that topic, but without further explanation towards a solution. Feel free to give the OP feedback yourself, and I will be happy to upvote your answer!
    $endgroup$
    – Alex
    yesterday










  • $begingroup$
    I'd also offer that either a single print with a docstring, or a single print with implicit string concatenation - print("foo" "bar") - are more appropriate than multiple prints.
    $endgroup$
    – Reinderien
    yesterday















$begingroup$
I'm rather startled that you're just telling OP to unindent the nested functions, when they are clearly using function calls as a substitute for goto. Nothing ever returns!
$endgroup$
– Kevin
yesterday





$begingroup$
I'm rather startled that you're just telling OP to unindent the nested functions, when they are clearly using function calls as a substitute for goto. Nothing ever returns!
$endgroup$
– Kevin
yesterday













$begingroup$
@Kevin: Yep, that's absolutely true and I'm fully aware of this. I added a note on that topic, but without further explanation towards a solution. Feel free to give the OP feedback yourself, and I will be happy to upvote your answer!
$endgroup$
– Alex
yesterday




$begingroup$
@Kevin: Yep, that's absolutely true and I'm fully aware of this. I added a note on that topic, but without further explanation towards a solution. Feel free to give the OP feedback yourself, and I will be happy to upvote your answer!
$endgroup$
– Alex
yesterday












$begingroup$
I'd also offer that either a single print with a docstring, or a single print with implicit string concatenation - print("foo" "bar") - are more appropriate than multiple prints.
$endgroup$
– Reinderien
yesterday




$begingroup$
I'd also offer that either a single print with a docstring, or a single print with implicit string concatenation - print("foo" "bar") - are more appropriate than multiple prints.
$endgroup$
– Reinderien
yesterday










Some School Kid is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Some School Kid is a new contributor. Be nice, and check out our Code of Conduct.












Some School Kid is a new contributor. Be nice, and check out our Code of Conduct.











Some School Kid is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216442%2ftext-adventure-game-code%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output

PDF-ში გადმოწერა სანავიგაციო მენიუproject page