3. Create a new version that uses two classes, one of which is Map and the other is the Engine. Tip: Put the play into the Engine. 、
#coding =utf-8
From sys import exit
From random import Randint
Class Map (object):
def __init__ (self):
Self.quips = ["You died. Kinda suck at the "," Your mom would be proud. If she were smarter. "," Such a luser. "," I hava a small puppy that's better at this. "
def death (self):
Print Self.quips[randint (0,len (self.quips)-1)]
Exit (1)
def central_corridor (self):
Action = Raw_input (">>>")
if action = = "shoot!":
Return ' death '
elif action = = "dodge!":
Return ' death '
elif action = = "Tell a joke":
Return ' Laser_weapon_armory '
Else
Return ' Central_corridor '
def laser_weapon_armory (self):
Code = "%d%d%d"% (Randint (1,9)), (Randint (1,9)), (Randint (1,9))
Guess = Raw_input ("[keypad]>>>")
guesses = 0
While guess!=code and guesses < 10:
Print "bzzzzeddd!"
guesses + = 1
guesses = Raw_input ("[keypad]>>>")
If guess = = code:
Return ' The_bridge '
Else
Return ' death '
def the_bridge (self):
Action = Raw_input (">>>")
if action = = "Throw The Bomb":
Return ' death '
elif action = = "Slowly Place the bomb":
Return ' Escape_pod '
Else
Return ' The_bridge '
def escape_pod (self):
Good_pod = Randint (1,5)
Guess = Raw_input ("[Pod #]>>>")
if int (guess)! = good_pod:
Return ' death '
Else
Exit (0)
Class Engine (MAP):
def __init__ (Self,start):
Self.start = Start
def play (self):
Next = Self.start
While True:
print "\ n-----------"
GetAttr (Self,next)
Next = Guest ()
A_game = Engine ("Central_corridor")
A_game.play () Remark: Beginner young novice, Welcome to the great God teach you
Stupid way to learn Python exercise 42 plus points exercise