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实现2048小游戏
Jan 19 Python
Ubuntu下创建虚拟独立的Python环境全过程
Feb 10 Python
Anaconda2下实现Python2.7和Python3.5的共存方法
Jun 11 Python
破解安装Pycharm的方法
Oct 19 Python
python 将列表中的字符串连接成一个长路径的方法
Oct 23 Python
解决Pycharm运行时找不到文件的问题
Oct 29 Python
python 使用值来排序一个字典的方法
Nov 16 Python
python 使用opencv 把视频分割成图片示例
Dec 12 Python
Python sorted对list和dict排序
Jun 09 Python
python的pip有什么用
Jun 17 Python
Python Celery异步任务队列使用方法解析
Aug 10 Python
Python使用sql语句对mysql数据库多条件模糊查询的思路详解
Apr 12 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
中国广播史趣谈 — 几个历史第一次
2021/03/01 无线电
set_include_path在win和linux下的区别
2008/01/10 PHP
有关php运算符的知识大全
2011/11/03 PHP
一个漂亮的php验证码类(分享)
2013/08/06 PHP
php-msf源码详解
2017/12/25 PHP
PHP基于面向对象实现的留言本功能实例
2018/04/04 PHP
使用PHP+Redis实现延迟任务,实现自动取消订单功能
2019/11/21 PHP
基于jQuery的的一个隔行变色,鼠标移动变色的小插件
2010/07/06 Javascript
js中switch case循环实例代码
2013/12/30 Javascript
JavaScript实现简单的数字倒计时
2015/05/15 Javascript
JQuery datepicker 用法详解
2015/12/25 Javascript
JS多物体实现缓冲运动效果示例
2016/12/20 Javascript
javascript中replace使用方法总结
2017/03/01 Javascript
layer弹出层框架alert与msg详解
2017/03/14 Javascript
原生JS实现瀑布流插件
2018/02/06 Javascript
[51:07]VGJ.S vs Pain 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/20 DOTA
python中对list去重的多种方法
2014/09/18 Python
python写xml文件的操作实例
2014/10/05 Python
Python使用scrapy采集数据过程中放回下载过大页面的方法
2015/04/08 Python
浅析Python中将单词首字母大写的capitalize()方法
2015/05/18 Python
Python实现公历(阳历)转农历(阴历)的方法示例
2017/08/22 Python
Python发送邮件功能示例【使用QQ邮箱】
2018/12/04 Python
Python实现DDos攻击实例详解
2019/02/02 Python
对Python定时任务的启动和停止方法详解
2019/02/19 Python
python实现将一维列表转换为多维列表(numpy+reshape)
2019/11/29 Python
python 制作本地应用搜索工具
2021/02/27 Python
档案接收函范文
2014/01/10 职场文书
宝宝周岁宴答谢词
2014/01/26 职场文书
药学专业学生的自我评价分享
2014/02/06 职场文书
大学生素质拓展活动方案
2014/02/11 职场文书
降消项目实施方案
2014/03/30 职场文书
励志演讲稿200字
2014/08/21 职场文书
同乡会致辞
2015/07/30 职场文书
幼儿园亲子活动感想
2015/08/07 职场文书
幼儿园迎新生欢迎词
2015/09/30 职场文书
vue实现锚点定位功能
2021/06/29 Vue.js