python实现的简单文本类游戏实例
作者:feiwen 发布时间:2022-10-22 02:32:51
标签: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('\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程序设计有所帮助。
0
投稿
猜你喜欢
- 需要分件html源代码 此例中的被抓取的html源代码如下 <p align=left>2004年8月24日星期二;白天:晴有时
- Python3 解释器Linux/Unix的系统上,一般默认的 python 版本为 2.x,我们可以将 python3.x 安装在 /us
- 前言k-means算法是无监督的聚类算法,实现起来较为简单,k-means++可以理解为k-means的增强版,在初始化中心点的方式上比k-
- 实现目标:mysql下将自增主键的值,从10000开始,即实现自增主键的种子为10000。方案1)使用alter table `tablen
- JavaScript(JS)网页–动态生成表格,供大家参考,具体内容如下在网页中,动态生成列表的内容,将数组中的object加入到列表中(没
- Python版本 实现了比之前的xxftp更多更完善的功能 1、继续支持多用户 2、继续支持虚拟目录 3、增加支持用户根目录以及映射虚拟目录
- 本文实例讲述了kNN算法python实现和简单数字识别的方法。分享给大家供大家参考。具体如下:kNN算法算法优缺点:优点:精度高、对异常值不
- 1. 警告不是异常你是不是经常在使用一些系统库或者第三方模块的时候,会出现一些既不是异常也不是错误的警告信息?这些警告信息,有时候非常多,对
- 以前写过一个刷校内网的人气的工具,Java的(以后再也不行Java程序了),里面用到了验证码识别,那段代码不是我自己写的:-) 校内的验证是
- 简介这两天更新完Xcode8之后发现Xcode对图标的要求又有了变化,之前用的一个小应用“IconKit”还没赶上节奏,已经不能满足Xcod
- # 判断三角形类型def triangle(a,b,c): if a>0 and b>0 and c>0: &
- 目标嗯,我们知道搜索或浏览网站时会有很多精美、漂亮的图片。我们下载的时候,得鼠标一个个下载,而且还翻页。那么,有没有一种方法,可以使用非人工
- 当你连接到MySQL服务器时,你应使用一个密码。密码不以明文在上传输。客户端连接序列中的密码处理在MySQL 4.1.1中已经升级,很安全。
- 一、环境介绍操作系统: win10 64位python版本: 3.8IDE: 采用vscode用到的相关安装包CSDN打包下载地址: htt
- 一、随机数种子为什么要提出随机数种子呢?咱们前面提到过了,随机数均是模拟出来的, 想要模拟的比较真实,就需要变换种子函数内的数值,一般以时间
- 1比如python提倡简单实用的思想,它就没有switch语句,如果要实现switch语句的效果 的话可以通过2个方法来写把 (1)通过if
- 导语嘿!下午好,木子来上新啦~期待今天的内容嘛?挠头.jpg 日常等更新的小可爱们我来了。看看给大家带来了什么好东西💦💦💦💦💦💦💦💦💦💦💦💦
- Python-OpenCV环境的配置看上一篇OpenCV环境的配置本篇主要介绍一下OpenCV的基本使用和相关函数的介绍。以下所有操作都基于
- 当服务器必须提供与两个或更多个网络或网络子网的连接时,典型的方案是使用多宿主计算机。此计算机通常位于外围网络(也称为 DMZ、外围安全区域或
- 动机: 排序功能让我们页面上的数据显的更人性化,是我们在网站上见过的很普遍的一个功能效果了。以往的自动排序都是用大量的脚本代码来完成的,对一