python实现的简单文本类游戏实例


Posted in Python onApril 28, 2015

本文实例讲述了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 相关文章推荐
python爬虫入门教程--正则表达式完全指南(五)
May 25 Python
python实现百万答题自动百度搜索答案
Jan 16 Python
将pip源更换到国内镜像的详细步骤
Apr 07 Python
django中使用Celery 布式任务队列过程详解
Jul 29 Python
对Python 中矩阵或者数组相减的法则详解
Aug 26 Python
Python unittest单元测试框架及断言方法
Apr 15 Python
PyCharm+Pipenv虚拟环境开发和依赖管理的教程详解
Apr 16 Python
python中 _、__、__xx__()区别及使用场景
Jun 30 Python
Python 数据的累加与统计的示例代码
Aug 03 Python
Python logging模块原理解析及应用
Aug 13 Python
python如何控制进程或者线程的个数
Oct 16 Python
pandas数值排序的实现实例
Jul 25 Python
初步解析Python下的多进程编程
Apr 28 #Python
python实现将pvr格式转换成pvr.ccz的方法
Apr 28 #Python
简单介绍Python中的JSON使用
Apr 28 #Python
浅析Python中的序列化存储的方法
Apr 28 #Python
详解在Python和IPython中使用Docker
Apr 28 #Python
在Python程序中进行文件读取和写入操作的教程
Apr 28 #Python
介绍Python中的文档测试模块
Apr 28 #Python
You might like
通过JavaScript或PHP检测Android设备的代码
2011/03/09 PHP
php curl模拟post提交数据示例
2013/12/31 PHP
PHP函数strip_tags的一个bug浅析
2014/05/22 PHP
php内存缓存实现方法
2015/01/24 PHP
PHP时间函数使用详解
2019/03/21 PHP
Yii框架视图、视图布局、视图数据块操作示例
2019/10/14 PHP
jquery 实现返回顶部功能
2014/11/17 Javascript
jQuery实现移动端手机商城购物车功能
2016/09/24 Javascript
javascript按顺序加载运行js方法
2017/12/01 Javascript
微信小程序实现红包雨功能
2018/07/11 Javascript
vue 实现click同时传入事件对象和自定义参数
2021/01/29 Vue.js
python实现的udp协议Server和Client代码实例
2014/06/04 Python
基于wxpython实现的windows GUI程序实例
2015/05/30 Python
神经网络(BP)算法Python实现及应用
2018/04/16 Python
Django后台获取前端post上传的文件方法
2018/05/28 Python
Python实现程序判断季节的代码示例
2019/01/28 Python
详解Django项目中模板标签及模板的继承与引用(网站中快速布置广告)
2019/03/27 Python
python Tkinter的图片刷新实例
2019/06/14 Python
10款最好的Python开发编辑器
2019/07/03 Python
Python求两点之间的直线距离(2种实现方法)
2019/07/07 Python
Django 缓存配置Redis使用详解
2019/07/23 Python
python3实现mysql导出excel的方法
2019/07/31 Python
python与js主要区别点总结
2020/09/13 Python
python爬取股票最新数据并用excel绘制树状图的示例
2021/03/01 Python
webView加载html图片遇到的问题解决
2019/10/08 HTML / CSS
Priority Pass机场贵宾室会籍计划:全球超过1200间机场贵宾室
2018/08/26 全球购物
高一生物教学反思
2014/01/17 职场文书
初一家长会邀请函
2014/01/31 职场文书
物业管理毕业生的自我评价
2014/02/17 职场文书
十佳护士获奖感言
2014/02/18 职场文书
售后服务承诺书
2014/03/26 职场文书
公司户外活动总结
2014/07/04 职场文书
校园主题婚礼活动策划方案
2014/09/15 职场文书
农贸批发市场管理制度
2015/08/07 职场文书
JavaScript实现淘宝商品图切换效果
2021/04/29 Javascript
Golang 遍历二叉树
2022/04/19 Golang