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关键字and和or用法实例
May 28 Python
python多进程中的内存复制(实例讲解)
Jan 05 Python
Django中的forms组件实例详解
Nov 08 Python
python石头剪刀布小游戏(三局两胜制)
Jan 20 Python
python读写csv文件实例代码
Jul 05 Python
使用OpenCV实现仿射变换—平移功能
Aug 29 Python
Python中用pyinstaller打包时的图标问题及解决方法
Feb 17 Python
Tensorflow安装问题: Could not find a version that satisfies the requirement tensorflow
Apr 20 Python
Python实现UDP程序通信过程图解
May 15 Python
5 分钟读懂Python 中的 Hook 钩子函数
Dec 09 Python
python可视化分析的实现(matplotlib、seaborn、ggplot2)
Feb 03 Python
对PyTorch中inplace字段的全面理解
May 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 格式化数字的时候注意数字的范围
2010/04/13 PHP
PHP 数组遍历方法大全(foreach,list,each)
2010/06/30 PHP
CI框架(CodeIgniter)操作redis的方法详解
2018/01/25 PHP
jquery 插件 人性化的消息显示
2008/01/21 Javascript
js confirm()方法的使用方法实例
2013/07/13 Javascript
在JavaScript中实现类的方式探讨
2013/08/28 Javascript
Jquery中find与each方法用法实例
2015/02/04 Javascript
JavaScript如何禁止Backspace键
2015/12/02 Javascript
深入理解Angularjs中$http.post与$.post
2017/05/19 Javascript
vue-cli基础配置及webpack配置修改的完整步骤
2019/10/20 Javascript
如何在vue项目中嵌入jsp页面的方法(2种)
2020/02/06 Javascript
js实现全选和全不选功能
2020/07/28 Javascript
详解JavaScript 事件流
2020/09/02 Javascript
Python进程通信之匿名管道实例讲解
2015/04/11 Python
Django应用程序中如何发送电子邮件详解
2017/02/04 Python
机器学习的框架偏向于Python的13个原因
2017/12/07 Python
Python实现合并同一个文件夹下所有PDF文件的方法示例
2018/04/28 Python
Python3操作MongoDB增册改查等方法详解
2020/02/10 Python
Python的pygame安装教程详解
2020/02/10 Python
python GUI库图形界面开发之PyQt5 MDI(多文档窗口)QMidArea详细使用方法与实例
2020/03/05 Python
python json.dumps中文乱码问题解决
2020/04/01 Python
接口自动化多层嵌套json数据处理代码实例
2020/11/20 Python
HTML5学习笔记之History API
2015/02/26 HTML / CSS
美容院考勤制度
2014/01/30 职场文书
小溪流的歌教学反思
2014/02/13 职场文书
留学生求职信
2014/06/03 职场文书
大学生志愿者活动总结
2014/06/27 职场文书
2015年度班主任自我评价
2015/03/11 职场文书
生日祝酒词大全
2015/08/10 职场文书
廉洁自律心得体会2016
2016/01/13 职场文书
python glom模块的使用简介
2021/04/13 Python
简单谈谈Python面向对象的相关知识
2021/06/28 Python
golang 语言中错误处理机制
2021/08/30 Golang
C3 线性化算法与 MRO之Python中的多继承
2021/10/05 Python
MySQL示例讲解数据库约束以及表的设计
2022/06/16 MySQL
JavaScript设计模式之原型模式详情
2022/06/21 Javascript