我通過供電肖捷思銳的LPTHW我的方式,我已經在(新的)練習43加分3.蟒蛇文檔字符串打印機發出
所以在這裏我想做一個功能,臨到碰釘子打印另一個大文檔字符串的功能。
這裏是發動機
class Game(object):
def __init__(self, start):
self.quips = [
"You died. You kinda suck at this.",
"Your mom would be proud. If she were smarter.",
"Such a luser.",
"I have a small puppy that's better at this."
]
self.start = start
def play(self):
# next_room_name is taken from init argument start
next_room_name = self.start
while True:
print "\n--------"
# set variable room to get function from next_room_name
room = getattr(self, next_room_name)
# unpacks function from next_room_name into room
next_room_name = room()
room = current_room
print current_room.__doc__
這裏是一些我想打電話開始遊戲的功能。
def central_corridor(self):
"""
The Gothons of Planet Percal #25 have invaded your ship and destroyed
your entire crew. You are the last surviving member and your last
mission is to get the neutron destruct bomb from the Weapons Armory,
put it in the bridge, and blow the ship up after getting into an
escape pod.
You're running down the central corridor to the Weapons Armory when
a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume
flowing around his hate filled body. He's blocking the door to the
Armory and about to pull a weapon to blast you.
"""
action = raw_input("> ")
if action == "shoot!":
print "Quick on the draw you yank out your blaster and fire it at the Gothon."
print "His clown costume is flowing and moving around his body, which throws"
print "off your aim. Your laser hits his costume but misses him entirely. This"
print "completely ruins his brand new costume his mother bought him, which"
print "makes him fly into an insane rage and blast you repeatedly in the face until"
print "you are dead. Then he eats you."
return 'death'
elif action == "dodge!":
print "Like a world class boxer you dodge, weave, slip and slide right"
print "as the Gothon's blaster cranks a laser past your head."
print "In the middle of your artful dodge your foot slips and you"
print "bang your head on the metal wall and pass out."
print "You wake up shortly after only to die as the Gothon stomps on"
print "your head and eats you."
return 'death'
elif action == "tell a joke":
print "Lucky for you they made you learn Gothon insults in the academy."
print "You tell the one Gothon joke you know:"
print "Lbhe zbgure vf fb sng, jura fur fvgf nebhaq gur ubhfr, fur fvgf nebhaq gur ubhfr."
print "The Gothon stops, tries not to laugh, then busts out laughing and can't move."
print "While he's laughing you run up and shoot him square in the head"
print "putting him down, then jump through the Weapon Armory door."
return 'laser_weapon_armory'
else:
print "DOES NOT COMPUTE!"
return 'central_corridor'
這裏是如何它在主程序
a_game = Game("central_corridor")
a_game.play()
調用,但我得到的是
--------
>
編輯:爲了順利完成練習,我需要編輯引擎打印出文檔,而不是編輯該功能。
爲什麼不縮進文檔字符串?我認爲它看起來很醜,因爲你在函數體中有縮進和非縮進的行。 如果您想縮進文檔字符串的文本,您可以按照[文檔](http://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation) – Bakuriu
中的示例進行操作,米總noob,我有一些麻煩,讓它看起來不錯,在控制檯,虐待研究該示例有點 – lerugray