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实现将文件归档到zip文件及从zip文件中读取数据的方法
May 22 Python
Python3控制路由器——使用requests重启极路由.py
May 11 Python
Python selenium 三种等待方式解读
Sep 15 Python
python获取当前用户的主目录路径方法(推荐)
Jan 12 Python
Python3爬虫之自动查询天气并实现语音播报
Feb 21 Python
Python参数类型以及常见的坑详解
Jul 08 Python
opencv转换颜色空间更改图片背景
Aug 20 Python
Pytorch中index_select() 函数的实现理解
Nov 19 Python
利用Python的sympy包求解一元三次方程示例
Nov 22 Python
Flask项目中实现短信验证码和邮箱验证码功能
Dec 05 Python
如何通过python实现全排列
Feb 11 Python
如何以Winsows Service方式运行JupyterLab
Aug 30 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
一个用于mysql的数据库抽象层函数库
2006/10/09 PHP
PHPStorm 2020.1 调试 Nodejs的多种方法详解
2020/09/17 NodeJs
javascript 触发事件列表 比较不错
2009/09/03 Javascript
jQuery下扩展插件和拓展函数的写法(匿名函数使用的典型例子)
2010/10/20 Javascript
jQuery获取节点和子节点文本的方法
2014/07/22 Javascript
详谈JavaScript内存泄漏
2014/11/14 Javascript
JavaScript中的继承方式详解
2015/02/11 Javascript
jQuery实现根据类型自动显示和隐藏表单
2015/03/18 Javascript
JavaScript对象参数的引用传递
2016/01/14 Javascript
深入理解requestAnimationFrame的动画循环
2016/09/20 Javascript
html5+CSS 实现禁止IOS长按复制粘贴功能
2016/12/28 Javascript
Reactjs实现通用分页组件的实例代码
2017/01/19 Javascript
Vue多系统切换实现方案
2018/06/05 Javascript
小程序视频列表中视频的播放与停止的示例代码
2018/07/20 Javascript
JavaScript中.min.js和.js文件的区别讲解
2019/02/13 Javascript
简单谈谈javascript高级特性
2019/09/04 Javascript
微信小程序实现点击按钮后修改颜色
2019/12/05 Javascript
nodejs实现的http、https 请求封装操作示例
2020/02/06 NodeJs
Vue实现开关按钮拖拽效果
2020/09/22 Javascript
python使用os模块的os.walk遍历文件夹示例
2014/01/27 Python
python创建进程fork用法
2015/06/04 Python
python3.5实现socket通讯示例(TCP)
2017/02/07 Python
Python编程修改MP3文件名称的方法
2017/04/19 Python
Python数据结构之单链表详解
2017/09/12 Python
Python 实现训练集、测试集随机划分
2020/01/08 Python
Python使用进程Process模块管理资源
2020/03/05 Python
法国综合购物网站:RueDuCommerce
2016/09/12 全球购物
NUK奶瓶美国官网:NUK美国
2016/09/26 全球购物
标记环网Toke Ring IEEE802.5
2014/05/26 面试题
配件采购员岗位职责
2013/12/03 职场文书
大学生职业生涯规划范文
2014/01/22 职场文书
食堂个人先进事迹
2014/01/22 职场文书
供货协议书
2014/04/22 职场文书
PostgreSQL并行计算算法及参数强制并行度设置方法
2022/04/06 PostgreSQL
不负正版帝国之名 《重返帝国》引领SLG手游制作新的标杆
2022/04/07 其他游戏
MySQL如何修改字段类型和字段长度
2022/06/10 MySQL