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.