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 相关文章推荐
Python3基础之函数用法
Aug 13 Python
python进阶教程之文本文件的读取和写入
Aug 29 Python
跟老齐学Python之赋值,简单也不简单
Sep 24 Python
Python写的Tkinter程序屏幕居中方法
Mar 10 Python
深入解析Python中的WSGI接口
May 11 Python
Python使用ntplib库同步校准当地时间的方法
Jul 02 Python
下载python中Crypto库报错:ModuleNotFoundError: No module named ‘Crypto’的解决
Apr 23 Python
Python WSGI的深入理解
Aug 01 Python
Python格式化输出字符串方法小结【%与format】
Oct 29 Python
Python里字典的基本用法(包括嵌套字典)
Feb 27 Python
Python实现bilibili时间长度查询的示例代码
Jan 14 Python
python3实现飞机大战
Nov 29 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
PHP+ajaxfileupload+jcrop插件完美实现头像上传剪裁
2014/06/09 PHP
PHP实现算式验证码和汉字验证码实例
2015/03/09 PHP
PHP中使用jQuery+Ajax实现分页查询多功能操作(示例讲解)
2017/09/17 PHP
jquery实现图片裁剪思路及实现
2013/08/16 Javascript
解决css和js的{}与smarty定界符冲突问题的两种方法
2013/09/10 Javascript
javascript实现数字验证码的简单实例
2014/02/10 Javascript
Jquery实现的角色左右选择特效
2014/05/21 Javascript
JS的location.href跳出框架打开新页面的方法
2014/09/04 Javascript
js正则表达式匹配数字字母下划线等
2015/04/14 Javascript
使用get方式提交表单在地址栏里面不显示提交信息
2017/02/21 Javascript
jQuery Easyui Treegrid实现显示checkbox功能
2017/08/08 jQuery
Three.js利用orbit controls插件(轨道控制)控制模型交互动作详解
2017/09/25 Javascript
在vue项目中安装使用Mint-UI的方法
2017/12/27 Javascript
监听angularJs列表数据是否渲染完毕的方法示例
2018/11/07 Javascript
详解关于React-Router4.0跳转不置顶解决方案
2019/05/10 Javascript
微信小程序下拉框搜索功能的实现方法
2019/07/31 Javascript
微信小程序 select 下拉框组件功能
2019/09/09 Javascript
jQuery操作动画完整实例分析
2020/01/10 jQuery
详解Vue之计算属性
2020/06/20 Javascript
vue项目如何监听localStorage或sessionStorage的变化
2021/01/04 Vue.js
[45:18]2018DOTA2亚洲邀请赛 4.3 突围赛 Optic vs iG 第一场
2018/04/04 DOTA
Python的迭代器和生成器
2015/07/29 Python
举例讲解Python面相对象编程中对象的属性与类的方法
2016/01/19 Python
Python 装饰器深入理解
2017/03/16 Python
python 通过logging写入日志到文件和控制台的实例
2018/04/28 Python
解决pycharm工程启动卡住没反应的问题
2019/01/19 Python
django 捕获异常和日志系统过程详解
2019/07/18 Python
python找出因数与质因数的方法
2019/07/25 Python
如何解决cmd运行python提示不是内部命令
2020/07/01 Python
python函数超时自动退出的实操方法
2020/12/28 Python
如何用 Python 制作一个迷宫游戏
2021/02/25 Python
美国第二大连锁书店:Books-A-Million
2017/12/28 全球购物
ALDO加拿大官网:加拿大女鞋品牌
2018/12/22 全球购物
美国农场商店:Blain’s Farm & Fleet
2020/01/17 全球购物
村安全生产责任书
2014/08/25 职场文书
预备党员学习十八届三中全会精神思想汇报
2014/09/13 职场文书