python實(shí)現(xiàn)的簡(jiǎn)單文本類游戲?qū)崿F(xiàn)方法
來(lái)源:易賢網(wǎng) 閱讀:1216 次 日期:2015-04-30 14:21:33
溫馨提示:易賢網(wǎng)小編為您整理了“python實(shí)現(xiàn)的簡(jiǎn)單文本類游戲?qū)崿F(xiàn)方法”,方便廣大網(wǎng)友查閱!

本文實(shí)例講述了python實(shí)現(xiàn)的簡(jiǎn)單文本類游戲?qū)崿F(xiàn)方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

############################################################

# - 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)

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

更多信息請(qǐng)查看IT技術(shù)專欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)