python实现的简单文本类游戏实例
作者:feiwen 时间:2022-10-22 02:32:51
本文实例讲述了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('\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 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:
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('\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(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,文本,游戏
0
投稿
猜你喜欢
SQLite5-使用Python来读写数据库
2024-01-15 23:44:08
将python运行结果保存至本地文件中的示例讲解
2024-01-03 04:01:52
Python操作word文档插入图片和表格的实例演示
2023-09-20 08:21:09
webpack构建的详细流程探底
2024-04-10 10:38:39
PyTorch简单手写数字识别的实现过程
2021-07-12 17:17:52
Python高效编程技巧
2023-08-19 17:29:56
python爬虫爬取快手视频多线程下载功能
2021-10-29 09:24:04
前淘宝前端开发工程师阿当的PPT中有JS技术理念问题
2024-05-25 15:17:53
python import模块时有错误红线的原因
2021-03-19 13:59:30
在django项目中,如何单独运行某个python文件
2023-04-27 07:37:22
Oracle存储过程基本语法介绍
2023-06-27 14:00:26
python实现动态规划算法的示例代码
2023-03-03 09:43:22
快速一键生成Python爬虫请求头
2022-05-21 01:00:53
python将pandas datarame保存为txt文件的实例
2021-11-17 06:21:51
golang 切片截取参数方法详解
2024-04-25 15:31:22
python通过pil模块获得图片exif信息的方法
2021-08-26 14:31:21
一文搞懂MySQL索引所有知识点
2024-01-27 14:01:43
用1行Python代码识别身份证信息实例
2022-04-28 12:57:27
一文教你彻底解决Python包下载慢问题
2023-04-02 20:29:32
GO语言操作Elasticsearch示例分享
2023-09-03 03:38:00