我正在用Python编写一个非常短的游戏(3.5.2)。我只需要定义

时间:2016-10-12 08:33:16

标签: python python-3.x definitions

所以我正在编写一个非常短的游戏来完成一项不会那么长的作业。然而,在这个游戏中有很多选择。

有这么多的选择,很难组织变量的定义,并在选择变量时尝试运行某些选择。我想知道是否有某个订单我必须为变量设定定义?

如果我在选择和故事之后加上定义,则表示名称未定义'。 所以我想我要问的是:有什么方法可以转发声明定义吗? 因为每次我将定义移到开头它它不会从游戏的一开始就运行,而是运行首先定义的代码行。

我真的需要知道是否有办法组织我的定义,或者是否需要将它们放入特定的订单中,因为到目前为止我的代码还没有工作!

我需要得到所有帮助,因为我是蟒蛇新手并且非常无知。

非常感谢您的帮助!

import time
import sys
import random

def viewinstructions():
print("You will be faced with a scenario. You will be required to input an answer that is your desired action after all the text has appeared. Your answer should include a keyword from the scenario that indicates your choice. Your choices will impact the events of the game, so choose wisely!")
time.sleep(8)
start()

# This choice happens after forest_sequence
def bush_choice():
input("Do you stealthily approach the girl or jump out at her to protect her from what might be her? (approach or jump) ")
if bush_choice == "approach":
sally_sandwich_sequence()
if bush_choice == "jump":
jumpoutatgirl_scene()

def forest_sequence():

print('The harsh rain stops and the storm clouds disappear.')
time.sleep(2)
print('You venture into the forest, trying to source where you heard the bloodcurdling scream.')
time.sleep(3)
print("Vines dangle from the canopies of the trees. You trudge past the bushes, pushing them out of your way as you cautiously walk towards the scream.")
time.sleep(5)
print("Your feet make a large crunching sound everytime you step on the forest floor which is littered with a thick layer of decomposing, withered leaves.")
time.sleep(5)
print("You can hear the noise more clearly now. It has changed from screams of horror to a loud sobs and crying.")
time.sleep(4)
print("You hide behind a bush, ready and alert, trying to prepare yourself for what you might encounter.")
time.sleep(4)
print("You part the ferns of the bush to make a window for yourself. You peer through the leaves and see a massive opening in the forest clear of trees.")
time.sleep(5)
print("In the centre of the glade, you see a girl clutching her leg and sitting on the grass, crying.")
time.sleep(5)

bush_choice()

def choice_1():

print("Which way do you choose to go? (forest or cave)" )
choice_1 = input()
if 'cave' in choice_1:
cave_sequence()
elif 'Cave' in choice_1:
cave_sequence()
if 'forest' in choice_1:
forest_sequence()
elif 'Forest' in choice_1:
forest_sequence()

def start():
print()
print("-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
print()
print("You slowly open your eyes")

print("You look up to the sky")

print("It is a dark and stormy night. The heavy rain falls onto your face.")

print("You look to your left")

print("There is an eerie and spooky cave.")

print("You look to your right")

print("You see a forest full of towering trees with no visible path and hear a loud scream from within.")

#First choice in the forest story

choice_1()







# This sequence happens right after either jumpoutatgirl_scene or bush_choice, depending on which one the user chooses
def sally_sandwich_sequence():

 print("""\
       .-,
      (("))
       / \  /
  ----/   \/
     /_____\
      _| |_
""")


print("'Oh! Finally! I was so frightened!'")
time.sleep(3)
print("'Thank you so much for coming to help me! I was shouting for so long I didn't think anybody would help!'")
time.sleep(5)
print("The girl wipes away the tears from her face. She stands up and dusts off the grass from her clothes.")
time.sleep(4)
print("You reassure the girl and console her, telling her everything is alright now and that she is safe. You ask her why she was in danger and if she was hurt.")
time.sleep(6)
print("'Yes! I was in grave danger! It's a miracle I haven't collapsed on the floor dead!'")
time.sleep(3)
print("You ready your fists and stand alert, guarding the girl from the dangers that lurk in the surrounding forest.")
time.sleep(3)
print("You ask the lady what her name is and what attacked her.")
time.sleep(3)
print("She clears her throat and begins to speak softly while rubbing her arm.")
time.sleep(3)
print("'My name is Sally. I live in a nice little rustic log cabin in these woods and I love going for walks here.'")
time.sleep(4)
print("'I made myself the best grilled cheese sandwich the world has ever seen. I was so proud of my magnificent creation of culinary brilliance that I couldn't eat it inside. I had to enjoy my perfect grilled cheese in the lush, green grass of this grove.'")
time.sleep(10)
print("'I walked out here with the sandwich. I held it in my hands the whole way here, resisting every urge and temptation to bite into the golden-brown, perfectly toasted, crunchy bread with the glistening, molten cheese oozing out of the sides.'")
time.sleep(9)
print("Your mouth begins to salivate")
time.sleep(2)
print("'So I stood on the grass. Right over there.'")
time.sleep(2)
print("Sally extends her arm and points a shaking finger towards a spot on the forest floor where the long, lush grass has been gently tramped forming 2 footprint marks.")
time.sleep(5)
print("Sally begins choking up and her eyes begin to water. She tries to hold back her tears.")
time.sleep(3)
print("She sniffles. 'I'm really sorry' she says, fanning her face with her hands. 'This part is really difficult for me.'")
time.sleep(4)
print("You pat her on the back in an attempt to console her.")
time.sleep(2)
print("'So there I was... *sniff* ...standing there... and I was just about to...' she wipes her nose with her sleeve and regains her composure. 'I was just about to bite into my grilled cheese sandwich... and... *sniff* something bumps into me...'")
time.sleep(10)
print("Tears are flowing down her face.")
time.sleep(5)
print("'AND I DROP MY GRILLED CHEESE SANDWICH!!!!!!!'")
time.sleep(4)
print("Sally collapses to her knees with her hands clutched to her face. The crying is uncontrollable. She wails loudly and laments the tragic loss of her sandwich. Her cries gradually increase in volume and tears gush out of her bawling eyes like water flowing from a waterfall.")
time.sleep(10)
print("You are shocked by the horrific, terrible and depressing story you have been told. You try to calm Sally down and comfort her. You pledge to catch whatever it was that did this to her and her sandwich.")
time.sleep(5)
print("You stand up and walk towards the scene of the crime. You see a half-eaten grilled cheese sandwich lying in the grass. It is very hard to look at without crying.")
time.sleep(6)
sandwichchoice()


def jumpoutatgirl_scene():
print("You jump out of the bush at the girl!")
time.sleep(2)
print("The girl is startled.")
time.sleep(2)
sally_sandwich_sequence()

# This should happen straight after sally_sandwich_sequence
def sandwichchoice():
input("Do you make a grave for the sandwich and give it the proper burial it deserves or do you try and find the perpetrator of this horrendous crime? (grave or csi)")
if sally_sandwich_sequence == 'grave':
sandwich_grave()
if sally_sandwich_sequence == 'csi':
csi()

#The CSI choice should lead to here
def houseorcreature():
input("Do you go to Sally's house or chase the creature? (house or creature)")
if houseorcreature == 'house':
sallyhouse()
if houseorcreature == 'creature':
dragonhunt()

# This scene should happen straight after sandwich_choice
def csi():
print("'It ran towards the East. But it was really big and menacing. Whatever it was, it wasn't human. When I felt it bump into me, I could sense freezing cold scales.")
time.sleep(5)
print("'You should properly arm yourself. Stop by my house, its North from here, about a 10 minute walk. In my living room there is a chest. Take what you need from it. I still need a moment here.'")
time.sleep(7)
print("Sally looks back at the Sandwich grave and frowns.")
time.sleep(2)
houseorcreature()

# The alternative choice in sandwich_choice. This should lead to CSI
def sandwich_grave():

 print("You kick a shallow hole in the dirt and gently lay the half eaten sandwich in the hole.")
 time.sleep(3)
 print("Sally weeps.")
 time.sleep(3)
 print("Picking up two sticks and plucking a long blade of grass from the ground, you form a cross with the sticks and tie them together at the centre with the grass strand.")
 time.sleep(4)
 print("You plant the cross into the ground just above the hole and you begin to cover the sandwich with dirt.")
 time.sleep(3)
 print("You stand up, bow your head and shut your eyes, paying your respects for the sandwich.")
 time.sleep(5)
 print("After a minute's silence, you ask Sally where the sandwich murderer went.")
 time.sleep(3)
 csi()

 def falling_choice():
 input("Do you accept that your life is meaningless, that the universe and everything in it is chaotic, absurd and pointless and that you will finally retreat into void of nothingness which you were born out of once you finally die and that every waking moment of your existence was excruciatingly painful and that the sweet release of death is your one and only salvation OR do you try to live and break your fall by curling up in a ball in the hopes that you'll somehow survive? (Type 'accept your death or 'try to live')" )
if falling_choice == 'accept your death':
savedbywizard()
if falling_choice == 'try to live':
youdie()

# this should play as soon as cave_sequence is finished
def cave_sequence_fightorflight():

 input("Your survival instincts activate and the adrenaline surges through your veins. Do you fight or flee?")
cavefightorflight1 = input()
if 'fight' in cavefightorflight1:
  cavefight1_sequence()
if 'flee' in cavefightorflight1:
  caveflee1_sequence()

#This should be the first part after you choose "cave" in choice 1()  
def cave_sequence():
print('You sprint toward the cave, desperately taking refuge from the relentless shards of intense rain')
time.sleep(4)
print('As you approach the cave, you realise that darkness radiating from it gets stronger. The mouth of the cave is gets increasingly darker until you cannot see anything.')
time.sleep(6) 
print('You are aware that you are in the cave because you cannot feel the harsh rain pounding against your skin.')
time.sleep(5)
print('You regain your breath, but blink rapidly and rub your eyes because you cannot see anything. There is a complete, total absense of light')
time.sleep(6)
print("The darkness consumes you.")
time.sleep(6)
print("You know you are in a cave but you collapse to the floor to collect your breath.")
time.sleep(6)
print("The sensation of being alone in pitch black void becomes overwhelming. You think that you now understand what it means to be dead.")
time.sleep(7)
print("Suddenly, you hear footsteps echoing through the cave and you snap out of your state of insensibility and are brought back to reality.")
time.sleep(6)
print("Thud")
time.sleep(2)
print("Thud")
time.sleep(2)
print("Thud")
time.sleep(2)
cave_sequence_fightorflight()



instructions = input("Before the game begins, would you like to read the   instructions? ")

if 'yes' in instructions:
viewinstructions()
elif 'Yes' in instructions:
viewinstructions()
else:
start()

#This should play if you run away and choose "flee" in the fight or flight choice
def caveflee1_sequence():

print("You run away as fast as you can, away from the source of the round.")
time.sleep(3)
print("You run madly in the dark.")
time.sleep(2)
print("You hear shouting from behind you. Whatever it was that you are running away from is trying to tell you something.")
time.sleep(4)
print("You can just make out the shouting from the sound echoing in the cave. You hear the words 'STOP! COME BACK!'")
time.sleep(5)
print("You run even faster now, but just as you begin speeding down the cave, you place one foot in front of the other but are shocked that it has not landed on the ground.")
time.sleep(7)
print("You realise you have just stepped off a ledge and begin to freefall in the darkness.")
time.sleep(4)
print("You plummet through the air, falling faster and faster with every second.")
print("'This is it' you think. 'This is where I die...'")
time.sleep(4)
print("You close your eyes for one last time as you continue falling in the darkness.")
time.sleep(6)
falling_choice()


#This code should run if you choose "fight"
def cavefight1_sequence():
 print("A man with his mighty sword ready to strike is standing before you!")
 print('''
\
 \    O
 _\|  |  }
   M_/|\_|}
      |  }
     / \
   _/   \_''')















def playagain():
input("Would you like to play again?")
if playagain == 'yes':
run()
if playagain == 'no':
END

def youdie():
 print("""


@@@@@                                        @@@@@
@@@@@@@                                      @@@@@@@
@@@@@@@           @@@@@@@@@@@@@@@            @@@@@@@
 @@@@@@@@       @@@@@@@@@@@@@@@@@@@        @@@@@@@@
     @@@@@     @@@@@@@@@@@@@@@@@@@@@     @@@@@
       @@@@@  @@@@@@@@@@@@@@@@@@@@@@@  @@@@@
         @@  @@@@@@@@@@@@@@@@@@@@@@@@@  @@
            @@@@@@@    @@@@@@    @@@@@@
            @@@@@@      @@@@      @@@@@
            @@@@@@      @@@@      @@@@@
             @@@@@@    @@@@@@    @@@@@
              @@@@@@@@@@@  @@@@@@@@@@
               @@@@@@@@@@  @@@@@@@@@
           @@   @@@@@@@@@@@@@@@@@   @@
           @@@@  @@@@ @ @ @ @ @@@@  @@@@
          @@@@@   @@@ @ @ @ @ @@@   @@@@@
        @@@@@      @@@@@@@@@@@@@      @@@@@
      @@@@          @@@@@@@@@@@          @@@@
   @@@@@              @@@@@@@              @@@@@
  @@@@@@@                                 @@@@@@@
   @@@@@                                   @@@@@


▓██   ██▓ ▒█████   █    ██    ▓█████▄  ██▓▓█████ 
 ▒██  ██▒▒██▒  ██▒ ██  ▓██▒   ▒██▀ ██▌▓██▒▓█   ▀ 
  ▒██ ██░▒██░  ██▒▓██  ▒██░   ░██   █▌▒██▒▒███   
  ░ ▐██▓░▒██   ██░▓▓█  ░██░   ░▓█▄   ▌░██░▒▓█  ▄ 
  ░ ██▒▓░░ ████▓▒░▒▒█████▓    ░▒████▓ ░██░░▒████▒
   ██▒▒▒ ░ ▒░▒░▒░ ░▒▓▒ ▒ ▒     ▒▒▓  ▒ ░▓  ░░ ▒░ ░
 ▓██ ░▒░   ░ ▒ ▒░ ░░▒░ ░ ░     ░ ▒  ▒  ▒ ░ ░ ░  ░
 ▒ ▒ ░░  ░ ░ ░ ▒   ░░░ ░ ░     ░ ░  ░  ▒ ░   ░   
 ░ ░         ░ ░     ░           ░     ░     ░  ░
 ░ ░                           ░                 


""")
time.sleep(1)
playagain()





start()

0 个答案:

没有答案