日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

《Python游戏编程快速上手》第五章--龙穴探险

發(fā)布時間:2024/9/30 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 《Python游戏编程快速上手》第五章--龙穴探险 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

接著昨天的工作,今天來看《Python游戲編程快速上手》的第五章----龍穴探險。
這一章我將不會給出書中的代碼,我會直接給我我修改后的代碼。我增加了一些游戲的規(guī)則,如下:

  • 管理員(編程人員)可以調(diào)節(jié)龍穴的數(shù)量,也可以調(diào)節(jié)安全龍穴的數(shù)量,當(dāng)然安全龍穴的數(shù)量必須不大于龍穴的數(shù)量,由于這個是由管理員設(shè)置的,所以無需加判斷

代碼還是非常簡單的,因為還沒有涉及UI,加上UI后會更有可玩性。
代碼如下;

import random import timenum = 3 safenum = 1def storyBegin():print("Now you are in a island full of dragons.")print("In front of you,there are ", num, " caves.")print("In ", safenum, " cave, the dragon is friendly and will share his treasure with you.")print("The others dragon is greedy and hungry,and will eat you on sight.")print()def chooseCave():print("Which one do you choose?(1 to ", num,")")cave = int(input())if cave > 0 and cave <= num:return caveelse:print("You can only choose in 1 to ", num)chooseCave()def checkCave(chooseC):print("You approach the cave...")time.sleep(2)print("It is dark and spooky...")time.sleep(2)print("A large dragon jumps out in front of you!He opens his jaws and ...")time.sleep(2)print()friendCave = random.sample(range(1, num), safenum)if chooseC in friendCave:print("Gives you his treasure!")else:print("Gobbles you down in one bite!")if __name__ == "__main__":while True:storyBegin()chooseC = chooseCave()checkCave(chooseC)print("Do you want to play again?(yes or no)")againP = input()if againP not in ["y", "yes"]:break

加油吧,少年!

總結(jié)

以上是生活随笔為你收集整理的《Python游戏编程快速上手》第五章--龙穴探险的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。