Stupid way to learn Python exercise 42 plus points exercise

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.