python实现的简单文本类游戏实现方法

   本文实例讲述了python实现的简单文本类游戏实现方法。分享给大家供大家参考。具体实现方法如下:

  ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

############################################################
# - 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('nn[--system--] one file is bad the other is good ..guess the right one.n')
print('nnconnecting....')
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:> ')

  ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

############################################################
# - 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('nnnnn[--system--] enter code in 15 trys to avoid lockoutn')
print('nconnecting....')
time.sleep(1)
print('....')
time.sleep(1)
print('....')
time.sleep(1)
print('....')
time.sleep(1)
print('connection establishedn')
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 OVERn')
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程序设计有所帮助。

时间: 2024-08-02 20:16:16

python实现的简单文本类游戏实现方法的相关文章

python实现的简单猜数字游戏_python

本文实例讲述了python实现的简单猜数字游戏.分享给大家供大家参考.具体如下: 给定一个1-99之间的数,让用户猜数字,当用户猜错时会提示用户猜的数字是过大还是过小,知道用户猜对数字为止,猜对数字用的次数越少成绩越好. import random n = random.randint(1, 99) guess = int(raw_input("Enter an integer from 1 to 99: ")) while n != "guess": print

python自定义解析简单xml格式文件的方法

  这篇文章主要介绍了python自定义解析简单xml格式文件的方法,涉及Python解析XML文件的相关技巧,非常具有实用价值,需要的朋友可以参考下: 因为公司内部的接口返回的字串支持2种形式:php数组,xml;结果php数组python不能直接用,而xml字符串的格式不是标准的,所以也不能用标准模块解析.[不标准的地方是某些节点会的名称是以数字开头的],所以写个简单的脚步来解析一下文件,用来做接口测试. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

用Python编写一个简单的俄罗斯方块游戏的教程_python

俄罗斯方块游戏,使用Python实现,总共有350+行代码,实现了俄罗斯方块游戏的基本功能,同时会记录所花费时间,消去的总行数,所得的总分,还包括一个排行榜,可以查看最高记录. 排行榜中包含一系列的统计功能,如单位时间消去的行数,单位时间得分等.   附源码:     from Tkinter import * from tkMessageBox import * import random import time #俄罗斯方块界面的高度 HEIGHT = 18 #俄罗斯方块界面的宽度 WIDT

使用Python编写一个简单的tic-tac-toe游戏的教程_python

 这个教程,我们将展示如何用python创建一个井字游戏. 其中我们将使用函数.数组.if条件语句.while循环语句和错误捕获等. 首先我们需要创建两个函数,第一个函数用来显示游戏板:   def print_board(): for i in range(0,3): for j in range(0,3): print map[2-i][j], if j != 2: print "|", print "" 这我们使用两个for循环来遍历map,该map是一个包含

python实现的简单RPG游戏流程实例

  本文实例讲述了python实现的简单RPG游戏流程.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

Python实现的简单hangman游戏实例

  本文实例讲述了Python实现的简单hangman游戏.分享给大家供大家参考.具体如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

Python实现的简单算术游戏实例

  本文实例讲述了Python实现的简单算术游戏.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #!/usr/bin/env python from operator import add, sub from random import randint, choic

python使用线程封装的一个简单定时器类实例

  本文实例讲述了python使用线程封装的一个简单定时器类.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 from threading import Timer class MyTimer: def __init__(self): self._timer= None self._tm = None self._fn = N

python基于Tkinter库实现简单文本编辑器实例

  这篇文章主要介绍了python基于Tkinter库实现简单文本编辑器,实例分析了Python使用Tkinter库实现简单桌面应用程序的技巧,具有一定参考借鉴价值,需要的朋友可以参考下 本文实例讲述了python基于Tkinter库实现简单文本编辑器的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3