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实现的文本简单可逆加密算法示例
May 18 Python
python unittest实现api自动化测试
Apr 04 Python
详谈pandas中agg函数和apply函数的区别
Apr 20 Python
python使用for循环计算0-100的整数的和方法
Feb 01 Python
python开头的coding设置方法
Aug 08 Python
pytorch 自定义数据集加载方法
Aug 18 Python
Python Gluon参数和模块命名操作教程
Dec 18 Python
利用pytorch实现对CIFAR-10数据集的分类
Jan 14 Python
python实现井字棋小游戏
Mar 04 Python
Django choices下拉列表绑定实例
Mar 13 Python
python 实现非极大值抑制算法(Non-maximum suppression, NMS)
Oct 15 Python
Python中使用ipython的详细教程
Jun 22 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数组中删除元素的实现代码
2012/06/22 PHP
生成随机字符串和验证码的类的PHP实例
2013/12/24 PHP
Laravel 修改默认日志文件名称和位置的例子
2019/10/17 PHP
js判断文本框剩余可输入字数的方法
2015/02/04 Javascript
javascript制作游戏开发碰撞检测的封装代码
2015/03/31 Javascript
js实现同一个页面多个渐变效果的方法
2015/04/10 Javascript
jQuery判断指定id的对象是否存在的方法
2015/05/22 Javascript
js学习阶段总结(必看篇)
2016/06/16 Javascript
Javascript的比较汇总
2016/07/25 Javascript
AngularJS中directive指令使用之事件绑定与指令交互用法示例
2016/11/22 Javascript
react-redux中connect的装饰器用法@connect详解
2018/01/13 Javascript
vue项目持久化存储数据的实现代码
2018/10/01 Javascript
微信小程序实现单选选项卡切换效果
2020/06/19 Javascript
Bootstarp在pycharm中的安装及简单的使用方法
2019/04/19 Javascript
小程序中canvas的drawImage方法参数使用详解
2019/07/04 Javascript
cordova+vue+webapp使用html5获取地理位置的方法
2019/07/06 Javascript
JS中的算法与数据结构之常见排序(Sort)算法详解
2019/08/16 Javascript
JavaScript的垃圾回收机制与内存管理
2020/08/06 Javascript
用生成器来改写直接返回列表的函数方法
2017/05/25 Python
详解supervisor使用教程
2017/11/21 Python
解决Python2.7读写文件中的中文乱码问题
2018/04/12 Python
对python中UDP,socket的使用详解
2019/08/22 Python
Python实现二叉树的最小深度的两种方法
2019/09/30 Python
python3实现单目标粒子群算法
2019/11/14 Python
python 如何去除字符串头尾的多余符号
2019/11/19 Python
关于windows下Tensorflow和pytorch安装教程
2020/02/04 Python
Python 通过爬虫实现GitHub网页的模拟登录的示例代码
2020/08/17 Python
关于Python3的import问题(pycharm可以运行命令行import错误)
2020/11/18 Python
Django如何重置migration的几种情景
2021/02/24 Python
Sam’s Club山姆会员商店:沃尔玛旗下高端会员制商店
2017/01/16 全球购物
学生个人自我鉴定范文
2014/03/28 职场文书
学校教研活动总结
2014/07/02 职场文书
2014年餐厅服务员工作总结
2014/11/18 职场文书
2014年办公室人员工作总结
2014/12/09 职场文书
党支部创先争优公开承诺书
2015/04/30 职场文书
python中Matplotlib绘制直线的实例代码
2021/07/04 Python