python实现的简单⽂本类游戏实例本⽂实例讲述了python实现的简单⽂本类游戏实现⽅法。分享给⼤家供⼤家参考。具体实现⽅法如下:>>>>>>>>>>>>
# - My version on the game "Dragon Realm".
# - taken from the book "invent with python" by Al Sweigart.
# - thanks for a great book Mr Sweigart.
# - this code takes advantage of python 3.
>>>>>>>>>>>>
#files.py
import random
import time
print('\n\n[--system--] one file is bad the other is good ..guess the right one.\n')
print('\')
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('\')
time.sleep(1)
print('')
time.sleep(1)
print('')
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 the book "invent with python" by Al Sweigart.
# - thanks for a great book Mr Sweigart.
# - this code takes advantage of python 3.
>>>>>>>>>>>>
# -NOTE - this program will crash if a number is not typed.
#digitcode.py
import random
import time
guessesTaken = 0
print('\n\n\n\n\n[--system--] enter code in 15 trys to avoid lockout\n')
print('\')
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(000, 999)
while guessesTaken < 15:
print()
guess = input('user:> ')
guess = int(guess)
guessesTaken = guessesTaken + 1
if guess < number:
print('\nACCESS - DENIED -code to low')
if guess > number:
print('\nACCESS - DENIED -code to high')
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken)
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)
python可以做什么游戏希望本⽂所述对⼤家的Python程序设计有所帮助。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
python应用实例
« 上一篇
python游戏代码
下一篇 »
热门文章
-
excel文字递增函数公式
2025-02-08 -
数字递增公式
2025-02-08 -
notepad 正则变量运算
2025-02-08 -
C++regex库常用函数及实例
2025-02-08 -
js正则表达式之前瞻后顾与非捕获分组
2025-02-08 -
indesign正则数字和英文之间的空格
2025-02-08 -
C#匹配中文字符串的4种正则表达式分享
2025-02-08 -
PHP正则表达式匹配中文字符
2025-02-08 -
匹配中文汉字的正则表达式介绍
2025-02-08 -
Python正则表达式如何进行字符串替换
2025-02-08 -
orcl中用正则表达式
2025-02-08 -
sql正则表达式excel
2025-02-08 -
dataframe正则表达式
2025-02-08 -
postgress sql正则
2025-02-08 -
el-upload accept 正则表达式
2025-02-08 -
半小时 正则表达式
2025-02-08 -
判断科学计数法的正则
2025-02-08 -
根据url判断静态资源的方法
2025-02-08 -
Java正则表达式-匹配正负浮点数
2025-02-08 -
替换模糊匹配正则-hive
2025-02-08
最新文章
-
一种基于正则表达式的DBC文件解析及报文分析方法[发明专利]
2025-02-08 -
能被5整除的十进制整数的正规表达式
2025-02-08 -
大于0小于等于1的正则表达式
2025-02-08 -
linux grep 26个字母
2025-02-08 -
java pattern 正则表达式
2025-02-08 -
掌握文本编辑器中的搜索和替换技巧
2025-02-08
发表评论