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 07 Python
Python中json格式数据的编码与解码方法详解
Jul 01 Python
Python基于分水岭算法解决走迷宫游戏示例
Sep 26 Python
Python+selenium实现自动循环扔QQ邮箱漂流瓶
May 29 Python
使用pandas批量处理矢量化字符串的实例讲解
Jul 10 Python
Python爬虫小技巧之伪造随机的User-Agent
Sep 13 Python
Python空间数据处理之GDAL读写遥感图像
Aug 01 Python
Python Sympy计算梯度、散度和旋度的实例
Dec 06 Python
Python3实现监控新型冠状病毒肺炎疫情的示例代码
Feb 13 Python
win10下opencv-python特定版本手动安装与pip自动安装教程
Mar 05 Python
pyCharm 设置调试输出窗口中文显示方式(字符码转换)
Jun 09 Python
python基础之停用词过滤详解
Apr 21 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禁止页面缓存的代码
2011/10/23 PHP
php UBB 解析实现代码
2011/11/27 PHP
PHP的error_reporting错误级别变量对照表
2014/07/08 PHP
实例讲解yii2.0在php命令行中运行的步骤
2015/12/01 PHP
Laravel利用gulp如何构建前端资源详解
2018/06/03 PHP
利用毫秒减值计算时长的js代码
2013/09/22 Javascript
JS实现遮罩层效果的简单实例
2013/11/12 Javascript
Iframe 自动适应页面的高度示例代码
2014/02/26 Javascript
json属性名为什么要双引号(个人猜测)
2014/07/31 Javascript
Javascript 拖拽雏形中的一些问题(逐行分析代码,让你轻松了拖拽的原理)
2015/01/23 Javascript
jQuery使用元素属性attr赋值详解
2015/02/27 Javascript
JavaScript中getUTCMinutes()方法的使用详解
2015/06/10 Javascript
jQuery获取cookie值及删除cookie用法实例
2016/04/15 Javascript
JavaScript核心语法总结(推荐)
2016/06/02 Javascript
JavaScript比较当前时间是否在指定时间段内的方法
2016/08/02 Javascript
微信 java 实现js-sdk 图片上传下载完整流程
2016/10/21 Javascript
JS实现重新加载当前页面
2016/11/29 Javascript
JS 验证密码 不能为空,必须含有数字、字母、特殊字符,长度在8-12位
2017/06/21 Javascript
VUE脚手架具体使用方法
2019/05/20 Javascript
小程序click-scroll组件设计
2019/06/18 Javascript
python逐行读取文件内容的三种方法
2014/01/20 Python
python中管道用法入门实例
2015/06/04 Python
numpy.linspace 生成等差数组的方法
2018/07/02 Python
pytorch中tensor的合并与截取方法
2018/07/26 Python
上课看小说检讨书
2014/02/22 职场文书
幼儿园庆六一活动方案
2014/03/06 职场文书
高三家长寄语
2014/04/03 职场文书
小学领导班子对照材料
2014/08/23 职场文书
户籍证明书标准模板
2014/09/10 职场文书
2015年领班工作总结
2015/04/29 职场文书
2015仓库保管员年终工作总结
2015/05/13 职场文书
运动会加油稿
2015/07/22 职场文书
送给教师们,到底该如何写好教学反思?
2019/07/02 职场文书
创业计划书详解
2019/07/19 职场文书
python实现批量提取指定文件夹下同类型文件
2021/04/05 Python
CSS3实现三角形不断放大效果
2021/04/13 HTML / CSS