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 合并文件的具体实例
Aug 08 Python
Python程序员鲜为人知但你应该知道的17个问题
Jun 04 Python
matplotlib绘制符合论文要求的图片实例(必看篇)
Jun 02 Python
python画出三角形外接圆和内切圆的方法
Jan 25 Python
Python中 传递值 和 传递引用 的区别解析
Feb 22 Python
详解python项目实战:模拟登陆CSDN
Apr 04 Python
python 画出使用分类器得到的决策边界
Aug 21 Python
基于python实现从尾到头打印链表
Nov 02 Python
windows环境中利用celery实现简单任务队列过程解析
Nov 29 Python
scrapy利用selenium爬取豆瓣阅读的全步骤
Sep 20 Python
去除python中的字符串空格的简单方法
Dec 22 Python
发工资啦!教你用Python实现邮箱自动群发工资条
May 10 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 5.0对象模型深度探索之绑定
2006/09/05 PHP
php实现refresh刷新页面批量导入数据的方法
2014/12/23 PHP
PHP session 会话处理函数
2016/06/06 PHP
JavaScript入门教程 Cookies
2009/01/31 Javascript
extjs 的权限问题 要求控制的对象是 菜单,按钮,URL
2010/03/09 Javascript
IE8 chrome中table隔行换色解决办法
2010/07/09 Javascript
js中的异常处理try...catch使用介绍
2013/09/21 Javascript
解决Jquery鼠标经过不停滑动的问题
2014/03/03 Javascript
JS实现仿Windows7风格的网页右键菜单效果代码
2015/09/11 Javascript
JavaScript仿聊天室聊天记录
2016/12/27 Javascript
Jquery uploadify 多余的Get请求(404错误)的解决方法
2017/01/26 Javascript
js实现PC端根据IP定位当前城市地理位置
2017/02/22 Javascript
JS求Number类型数组中最大元素方法
2018/04/08 Javascript
webpack4打包vue前端多页面项目
2018/09/17 Javascript
详解vue中多个有顺序要求的异步操作处理
2019/10/29 Javascript
[04:54]DOTA2-DPC中国联赛1月31日Recap集锦
2021/03/11 DOTA
Python实现在Linux系统下更改当前进程运行用户
2015/02/04 Python
Python中的os.path路径模块中的操作方法总结
2016/07/07 Python
Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
2018/02/23 Python
Python实现求两个数组交集的方法示例
2019/02/23 Python
python 在某.py文件中调用其他.py内的函数的方法
2019/06/25 Python
使用 tf.nn.dynamic_rnn 展开时间维度方式
2020/01/21 Python
基于Modernizr 让网站进行优雅降级的分析
2013/04/21 HTML / CSS
美国在线家装零售商:Build.com
2016/09/02 全球购物
锐步美国官方网站:Reebok美国
2018/01/10 全球购物
瑞士图书网站:Weltbild.ch
2019/09/17 全球购物
普通员工辞职信
2014/01/17 职场文书
自我鉴定总结
2014/03/24 职场文书
2014年五四青年节活动方案
2014/03/29 职场文书
文明倡议书范文
2014/04/15 职场文书
三分钟演讲稿范文
2014/04/24 职场文书
诚信贷款承诺书
2014/05/30 职场文书
房地产营销活动策划方案
2014/09/15 职场文书
免职证明样本
2014/10/23 职场文书
读《教育心理学》心得体会
2016/01/22 职场文书
创业计划书之烤红薯
2019/09/26 职场文书