This article illustrates a simple text-class game implementation method implemented by Python. Share to everyone for your reference. The implementation methods are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the |
############################################################ #-my version on the game "Dragon Realm". #-taken from the book ' Invent with Python ' by Al Sweigart. #-For a great the book Mr Sweigart. #-This code takes advantage of Python 3. ############################################################ #files. py Import Random Import time print (' nn[-- system--] One file is bad the other is good. Guess the right ONE.N ') print (' nnconnecting ... ') 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 download? 1 or 2 ') option = input (' user:> ') return option Def 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:p Rint (' nfile corrupt ') print (' System infected. ') print (' Ngame over ') Playagain = ' yes ' while playagain = ' yes ': displayint RO () Optionnumber = Chooseoption () checkoption (optionnumber) print (' Ndownload again ..... (yes or no) ') Playagain = input (' user:> ') |
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the only of the "a" of the--------------- TD style= "BORDER:0;PADDING:0;" > ############################################################ #-My version of the game "guess". #-taken from the book ' Invent with Python ' by Al Sweigart. #-For a great the book Mr Sweigart. #-This code takes advantage of Python 3. ############################################################ #-note-this program would crash if a is not typed. #digitcode. py Import Random import time Guessestaken = 0 print (' nnnnn[--system--] Enter code into trys to avoid lockoutn ' Print (' nconnecting ... ') time.sleep (1) print (' ... ') time.sleep (1) print (' ... ') time.sleep (1) print (' ... ') Time.sleep (1) print (' Connection Establishedn ') 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) Guessestaken = guessestaken + 1 if guess < Number:print (' Nacce Ss-denied-code to Low ') if guess > Number:print (' Naccess-denied-code to High ') if guess = = Number:break if gues s = = Number:guessestaken = str (guessestaken) print (' nverifying ... ') time.sleep (1) print (' nauthenticating ... ') time.s Leep (1) print (' ... ') time.sleep (1) print (' ... ') time.sleep (1) print (' naccess-granted ') print (' Ngame overn ') exit (0) I F guess!= number:number = str (number) print (' n ... ') time.sleep (1) print (' n ... ') time.sleep (1) print (' Nsystem locked-t He code is ' + number ' print () exit (0) |
I hope this article will help you with your Python programming.