[Python] python编写的两个简单的文本类游戏 →→→→→进入此内容的聊天室

来自 , 2019-10-20, 写在 Python, 查看 214 次.
URL http://www.code666.cn/view/e6abb662
  1. ############################################################
  2. # - My version on the game "Dragon Realm".
  3. # - taken from the book "invent with python" by Al Sweigart.
  4. # - thanks for a great book Mr Sweigart.
  5. # - this code takes advantage of python 3.
  6. ############################################################
  7.  
  8. #files.py
  9. import random
  10. import time
  11. print('\n\n[--system--] one file is bad the other is good ..guess the right one.\n')
  12. print('\n\nconnecting....')
  13. time.sleep(1)
  14. print('....')
  15. time.sleep(1)
  16. print('....')
  17. time.sleep(1)
  18. print('....')
  19. time.sleep(1)
  20. print('\nconnection established')
  21.  
  22. def displayIntro():
  23.         print('------------')
  24.         print('SYSTEM FILES')
  25.         print('------------\n')
  26.         print('1.) file.')
  27.         print('2.) file.\n')
  28.        
  29. def chooseOption():
  30.         option = ''
  31.         while option != '1' and option != '2':
  32.                 print('which file to download? 1 or 2')
  33.                 option = input('user:> ')
  34.                
  35.         return option
  36.        
  37. def checkOption(chosenOption):
  38.         print('\nintialising download....')
  39.         time.sleep(1)
  40.         print('accessing file....')
  41.         time.sleep(1)
  42.         print('downloading....')
  43.         time.sleep(1)
  44.         print('....')
  45.         time.sleep(1)
  46.         print('....')
  47.         time.sleep(1)
  48.        
  49.         goodfile = random.randint(1, 2)
  50.        
  51.         if chosenOption == str(goodfile):
  52.                 print('\ndownload complete.')
  53.                 print('\nGAME OVER')
  54.         else:
  55.                 print('\nfile corrupt')
  56.                 print('system infected.')
  57.                 print('\nGAME OVER')
  58.                
  59.                
  60. playAgain = 'yes'
  61. while playAgain == 'yes':
  62.         displayIntro()
  63.         optionNumber = chooseOption()
  64.         checkOption(optionNumber)
  65.        
  66.         print('\ndownload again? .... (yes or no)')
  67.         playAgain = input('user:> ')
  68.  
  69. ############################################################
  70. # - My version of the game "guess the number".
  71. # - taken from the book "invent with python" by Al Sweigart.
  72. # - thanks for a great book Mr Sweigart.
  73. # - this code takes advantage of python 3.
  74. ############################################################
  75.  
  76. # -NOTE - this program will crash if a number is not typed.
  77.  
  78. #digitcode.py
  79. import random
  80. import time
  81.  
  82. guessesTaken = 0
  83.  
  84. print('\n\n\n\n\n[--system--] enter code in 15 trys to avoid lockout\n')
  85. print('\nconnecting....')
  86. time.sleep(1)
  87. print('....')
  88. time.sleep(1)
  89. print('....')
  90. time.sleep(1)
  91. print('....')
  92. time.sleep(1)
  93. print('connection established\n')
  94. print('---------------------')
  95. print('  MAINFRAME - LOGIN  ')
  96. print('---------------------')
  97. print('\nenter 3 digit access code..')
  98.  
  99. number = random.randint(000, 999)
  100. while guessesTaken < 15:
  101.         print()
  102.         guess = input('user:> ')
  103.         guess = int(guess)
  104.        
  105.         guessesTaken = guessesTaken + 1
  106.        
  107.         if guess < number:
  108.                 print('\nACCESS - DENIED  -code to low')
  109.                
  110.         if guess > number:
  111.                 print('\nACCESS - DENIED  -code to high')
  112.                
  113.         if guess == number:
  114.                 break
  115.                
  116. if guess == number:
  117.         guessesTaken = str(guessesTaken)
  118.         print('\nverifying ....')
  119.         time.sleep(1)
  120.         print('\nauthenticating ....')
  121.         time.sleep(1)
  122.         print('....')
  123.         time.sleep(1)
  124.         print('....')
  125.         time.sleep(1)
  126.         print('\nACCESS - GRANTED')
  127.         print('\nGAME OVER\n')
  128.         exit(0)
  129.        
  130. if guess != number:
  131.         number = str(number)
  132.         print('\n....')
  133.         time.sleep(1)
  134.         print('\n....')
  135.         time.sleep(1)
  136.         print('\nSYSTEM LOCKED  -the code was ' + number)
  137.         print()
  138.         exit(0)
  139.        
  140.        
  141.  
  142. #//python/8167

回复 "python编写的两个简单的文本类游戏"

这儿你可以回复上面这条便签

captcha