Learn python the hard-to-do exercise 45-making a game

Source: Internet
Author: User

Little white self-taught python.

 fromSysImportExit fromRandomImportRandintclassScene (object):defEnter (self):Print "it ' s no use"Exit (1)        classEngine (object):def __init__(self,scene_map): Self.scene_map=Scene_mapdefPlay (self): Current_scene=Self.scene_map.opening_scene () whileTrue:Print "------"Next_scene_name=current_scene.enter () Current_scene=Self.scene_map.next_scene (next_scene_name)classchoosebike (Scene): Model= {        'Bike1':'You got a Merida bike',        'Bike2':'You got a giant bike',        'Bike3':'Congratuations,you got a specialized bike!'        }    defEnter (self):Print """There has three bike they is bike1, Bike2, Bike3.            If you can choose your bike, which would you choose? """Bike= Raw_input (">")                        ifBike = ='Bike1' orBike = ='Bike2' orBike = ='Bike3':                    PrintChoosebike.model[bike]Print "Now , to complete your race with your bike!"            Print "Good luck!"                    return 'Lock'        Else:            Print"Oh no"            Print "Please input agian"            return 'Choosebike'        classLock (Scene):defEnter (self):Print "Oh my god! the bike has locked"        Print "ah! It has a note"        Print "it say ' should guess the number correctly and you can go '"        Print "And you should take notice to your time"        Print "You just"        Print "Please input the number which are a double-digit you guess!" Number="%d%d"% (Randint (0,9), Randint (0,9)) Guess= Raw_input (" -") guesses=0return 'Speedorno'         whileGuess! = number andGuesses < 20: Guesses+ = 1Print "Input Again"Guess= Raw_input (" -")                    ifGuess = =Number :Print "Ahhh You is so samartly"            Print "Now , continue your race"                        return 'Speedorno'                    Else:            Print "\a\a\a\a"            Print "so sorry, your times are uesd out"            Print "You has no time to compelete the race"Exit (1)classSpeedorno (Scene): Results= [            'You is so cool and you got the no.1!! congratuations!!',            'Oh it\ 's a nice race, you got the No.2, Congratuations',            'I belive you'll be the next time!',            'e...it\ ' s really a little pity, you're the No.4, but you're very good,you would better next time!']    defEnter (self):Print "You'll Compelete race immediately,"        Print "want speed, but"        Print "If you speed,your leg could hurted and can ' t go on"        Print "If you aren't speed, you are not speed , and you may win"        Print "But it's probability is smaller and then the speed"        Print "Would you speed ?"Spdorno= Raw_input (">")                Print "You choose%r"%SpdornoPrintSpeedorno.results[randint (1,4)]        return 'finished'classMap (object): Scenes= {        'Choosebike': Choosebike (),'Lock': Lock (),'Speedorno': Speedorno ()}def __init__(self, start_scene): Self.start_scene=Start_scenedefNext_scene (self, scene_name):#The function of Next_scene        returnMap.scenes.get (Scene_name)#system function. get-dictionary            defOpening_scene (self):#The function of Opening_scene and use function next scene        returnSelf.next_scene (self.start_scene) Start= Map ('Choosebike') Game=Engine (start) game.play ()

Some places cite the previous exercise 44, although it is just a simple word game, no meaning.

Learn python the hard-to-do exercise 45-making a game

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.