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函数式编程
Jun 09 Python
python中使用urllib2伪造HTTP报头的2个方法
Jul 07 Python
Python字符串逐字符或逐词反转方法
May 21 Python
Python中特殊函数集锦
Jul 27 Python
Python脚本实现自动将数据库备份到 Dropbox
Feb 06 Python
微信跳一跳辅助python代码实现
Jan 05 Python
解决python删除文件的权限错误问题
Apr 24 Python
python3实现名片管理系统
Nov 29 Python
python实现PDF中表格转化为Excel的方法
Jun 16 Python
PyTorch 中的傅里叶卷积实现示例
Dec 11 Python
python自动生成证件号的方法示例
Jan 14 Python
解决Python字典查找报Keyerror的问题
May 26 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 foreach、while性能比较
2009/10/15 PHP
php记录日志的实现代码
2011/08/08 PHP
Yii实现多数据库主从读写分离的方法
2014/12/29 PHP
php json中文编码为null的解决办法
2016/12/14 PHP
总结PHP中初始化空数组的最佳方法
2019/02/13 PHP
关于锚点跳转及jQuery下相关操作与插件
2012/10/01 Javascript
javascript Event对象详解及使用示例
2013/11/22 Javascript
js使用数组判断提交数据是否存在相同数据
2013/11/27 Javascript
使用JQuery库提供的扩展功能实现自定义方法
2014/09/09 Javascript
js用Date对象的setDate()函数对日期进行加减操作
2014/09/18 Javascript
对比分析AngularJS中的$http.post与jQuery.post的区别
2015/02/27 Javascript
js正则表达式验证邮件地址
2015/11/12 Javascript
Jquery实现的简单轮播效果【附实例】
2016/04/19 Javascript
Web前端新人笔记之jquery入门心得(新手必看)
2016/05/17 Javascript
jQuery基础_入门必看知识点
2016/07/04 Javascript
AngularJS 过滤器(自带和自建)详解
2016/09/19 Javascript
前端开发之CSS原理详解
2017/03/11 Javascript
js如何获取网页所有图片
2017/05/12 Javascript
深入解析Vue 组件命名那些事
2017/07/18 Javascript
微信小程序实现文字从右向左无限滚动
2020/11/18 Javascript
js瀑布流布局的实现
2020/06/28 Javascript
如何构建 vue-ssr 项目的方法步骤
2020/08/04 Javascript
Python使用自带的ConfigParser模块读写ini配置文件
2016/06/26 Python
Python3中条件控制、循环与函数的简易教程
2017/11/21 Python
深入了解Python iter() 方法的用法
2019/07/11 Python
Python PyQt5 Pycharm 环境搭建及配置详解(图文教程)
2019/07/16 Python
python3中pip3安装出错,找不到SSL的解决方式
2019/12/12 Python
Python assert关键字原理及实例解析
2019/12/13 Python
在python中修改.properties文件的操作
2020/04/08 Python
python保留格式汇总各部门excel内容的实现思路
2020/06/01 Python
python 怎样进行内存管理
2020/11/10 Python
python3代码中实现加法重载的实例
2020/12/03 Python
设计4个线程,其中两个线程每次对j增加1,另外两个线程对j每次减少1。写出程序。
2014/12/30 面试题
餐厅筹备计划书
2014/04/25 职场文书
自我介绍演讲稿范文
2014/08/21 职场文书
创业计划书之农家乐
2019/10/09 职场文书