Examples of simple text-class games implemented by Python

Source: Internet
Author: User
This paper introduces the implementation method of simple text class game implemented by Python. Share to everyone for your reference. The implementation method is as follows:

#############################################################-My version on the game "Dragon Realms". #-Taken from the B Ook "invent with Python" by Al sweigart.#-Thanks for a great book Mr. Sweigart.#-this code takes advantage of Python 3. ############################################################ #files. Pyimport randomimport timeprint (' \n\n[-- system--] One file is a bad good. Guess the right one.\n ') print (' \n\nconnecting ... ') time.sleep (1) print (' ... ') time.sleep (1) print (' ... ') time.sleep (1) Print (' ... ') time.sleep (1) print (' \nconnection established ') def Displayintro (): Print ('------------') print ('  SYSTEM FILES ') print ('------------\ n ') print (' 1.) file. ') Print (' 2.) file.\n ') def chooseoption (): option = ' while option! = ' 1 ' and option! = ' 2 ': Print (' which file to downl Oad?   1 or 2 ') option = input (' user:> ') return optiondef checkoption (chosenoption): Print (' \nintialising download .... ') Time.sleep (1) print (' Accessing file .... ') time.sleep (1) Print (' Downloading ... ') time.sleep (1) print (' ... ') time.sleep (1) print (' ... ') time.sleep (1) goodfile = Random.randint (1    , 2) if chosenoption = = str (goodfile): Print (' \ndownload complete. ')    Print (' \ngame over ') else:print (' \nfile corrupt ') print (' System infected. ') Print (' \ngame over ') Playagain = ' yes ' while playagain = = ' Yes ': Displayintro () Optionnumber = Chooseoption () checkoption (optionnumber) print (' \ndownload again? .... (yes or no) ') Playagain = input (' user:> ')

#############################################################-My version of the game "guess the number". #-Taken from T He book ' Invent with Python ' by Al sweigart.#-Thanks for a great book Mr. Sweigart.#-this code takes advantage of Pytho N 3.#############################################################-note-this program would crash if a number is not typed . #digitcode. pyimport randomimport timeguessestaken = 0print (' \n\n\n\n\n[--system--] Enter code in the trys to avoid lockout \ n ') print (' \nconnecting ... ') time.sleep (1) print (' ... ') time.sleep (1) print (' ... ') time.sleep (1) print (' ... ') Time.sleep (1) print (' Connection established\n ') print ('---------------------') print (' Mainframe-login ') print ('---- -----------------') print (' \nenter 3 digit access code.. ') Number = Random.randint (999) while Guessestaken < 15:print () guess = input (' user:> ') guess = int (guess) gu Essestaken = Guessestaken + 1 if guess < Number:print (' \naccess-denied-code to low ') if guess >Number:print (' \naccess-denied-code to High ') if guess = = Number:breakif Guess = = Number:guessestaken = str (g Uessestaken) print (' \nverifying ... ') time.sleep (1) print (' \nauthenticating .... ') time.sleep (1) print (' ... ') time  . Sleep (1) print (' ... ') time.sleep (1) print (' \naccess-granted ') print (' \ngame over\n ') exit (0) if guess! = number:  Number = str (number) print (' \ n ... ') time.sleep (1) print (' \ n ... ') time.sleep (1) print (' \nsystem locked-the code was ' + number ' print () exit (0)

Hopefully this article will help you with Python programming.

  • 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.