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爬豆瓣电影实例
Feb 23 Python
python批量设置多个Excel文件页眉页脚的脚本
Mar 14 Python
pycharm 将django中多个app放到同个文件夹apps的处理方法
May 30 Python
python生成ppt的方法
Jun 07 Python
使用python list 查找所有匹配元素的位置实例
Jun 11 Python
anaconda中更改python版本的方法步骤
Jul 14 Python
Django工程的分层结构详解
Jul 18 Python
Python3.7安装keras和TensorFlow的教程图解
Jun 18 Python
Django --Xadmin 判断登录者身份实例
Jul 03 Python
python利用tkinter实现图片格式转换的示例
Sep 28 Python
python+selenium爬取微博热搜存入Mysql的实现方法
Jan 27 Python
Pytorch 如何实现常用正则化
May 27 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
五款常用mysql slow log分析工具的比较分析
2011/05/22 PHP
php代码运行时间查看类代码分享
2011/08/06 PHP
PHP CodeIgniter分页实例及多条件查询解决方案(推荐)
2017/05/20 PHP
PHP实现的简单组词算法示例
2018/04/10 PHP
phpinfo无法显示的原因及解决办法
2019/02/15 PHP
漂亮的widgets,支持换肤和后期开发新皮肤(2007-4-27已更新1.7alpha)
2007/04/27 Javascript
js用正则表达式来验证表单(比较齐全的资源)
2013/11/17 Javascript
JSON+HTML实现国家省市联动选择效果
2014/05/18 Javascript
利用AJAX实现WordPress中的文章列表及评论的分页功能
2016/05/17 Javascript
基于BootStrap环境写jQuery tabs插件
2016/07/12 Javascript
微信小程序开发之大转盘 仿天猫超市抽奖实例
2016/12/08 Javascript
Node.js连接mongodb实例代码
2017/06/06 Javascript
浅谈react 同构之样式直出
2017/11/07 Javascript
编写React组件项目实践分析
2018/03/04 Javascript
对Vue.js之事件的绑定(v-on: 或者 @ )详解
2018/09/15 Javascript
7个好用的JavaScript技巧分享(译)
2019/05/07 Javascript
vue-property-decorator用法详解
2019/12/12 Javascript
在Uni中使用Vue的EventBus总线机制操作
2020/07/31 Javascript
jQuery实现动态加载瀑布流
2020/09/01 jQuery
Vue3.0的优化总结
2020/10/16 Javascript
[04:44]DOTA2西游记战队视频彩蛋流出 师徒开黑巧遇林书豪
2016/08/03 DOTA
python生成指定长度的随机数密码
2014/01/23 Python
python使用三角迭代计算圆周率PI的方法
2015/03/20 Python
Python中输出ASCII大文字、艺术字、字符字小技巧
2015/04/28 Python
Python实现二叉树结构与进行二叉树遍历的方法详解
2016/05/24 Python
pandas中去除指定字符的实例
2018/05/18 Python
对python条件表达式的四种实现方法小结
2019/01/30 Python
python自动识别文本编码格式代码
2019/12/26 Python
解决Tensorboard 不显示计算图graph的问题
2020/02/15 Python
python GUI库图形界面开发之PyQt5工具栏控件QToolBar的详细使用方法与实例
2020/02/28 Python
pycharm 2018 激活码及破解补丁激活方式
2020/09/21 Python
什么时候用assert
2015/05/08 面试题
公司年底活动方案
2014/08/17 职场文书
关于社会实践的心得体会(2016最新版)
2016/01/25 职场文书
2016个人先进事迹材料范文
2016/03/01 职场文书
幼儿园2016圣诞节活动总结
2016/03/31 职场文书