python實(shí)現(xiàn)簡單飛行棋
本人剛開始學(xué)習(xí)python,看了一段時(shí)間視頻教程之后,決定做一個(gè)小游戲來鞏固一下知識點(diǎn),就做了一個(gè)文字版飛行棋,暫不具備圖形界面。把代碼貼出來,給自己留個(gè)標(biāo)記。
chess_main.py
import chess_tools # 輸入玩家信息 chess_tools.input_player() while chess_tools.end_flag: for player in chess_tools.player_list: chess_tools.ironman(player) input(player["name"]+",請按enter擲骰子") chess_tools.throw(player) if chess_tools.judge(player) == 1: break chess_tools.hit(player) chess_tools.speedup(player) print("")
chess_tools.py
from random import randint player_list = [] end_flag = 1 def input_player(): num = input("數(shù)據(jù)玩家數(shù)量:") i = 0 while i < int(num): player_name = input("輸入第" + str(i + 1) + "位玩家名字:") play_info = {"name": player_name, "score": 0} player_list.append(play_info) i = i + 1 def throw(player): """ 玩家扔骰子,隨機(jī)1-6點(diǎn) :param player: 當(dāng)前玩家 :return: """ points = randint(1,6) # 首先判定是否起飛 if player["score"] == 0 and points == 6: player["score"] = 1 print("%d 點(diǎn),恭喜起飛!當(dāng)前在第%d格" % (points, player["score"])) elif player["score"] == 0 and points < 6: print("%d 點(diǎn),起飛失??!" % points) return # 分?jǐn)?shù)大于100,要后退,多幾分退幾步 elif player["score"] + points > 100: player["score"] = player["score"] - (player["score"]+ points) % 100 + 1 print("%d 點(diǎn),飛過頭了!回到%d格" % (points,player["score"])) else: player["score"] += points print("%d 點(diǎn)!當(dāng)前在第%d格" % (points, player["score"])) def judge(player): global end_flag if player["score"] == 100: end_flag = 0 print(player["name"]+"贏了") return 1 def hit(player): """ 判斷當(dāng)前玩家是否會將領(lǐng)先的玩家撞回起飛位置 :param player: 當(dāng)前玩家名字 """ for other_player in player_list: if player["score"] == other_player["score"] \ and other_player["name"] != player["name"]: other_player["score"] = 0 def speedup(player): if player["score"] == 15 or \ player["score"] == 35 or \ player["score"] == 85: player["score"] += 5 print("加速5格,當(dāng)前在%d格" % player["score"]) def ironman(player): """ 主角光環(huán),名字中含有指定字符的人可以獲得50分加成 :param player:當(dāng)前玩家的名字 """ master = player["name"].count("t") if master > 0 and player["score"] == 0: player["score"] = 50 print("- I am Iron Man!賈維斯,先給我加50分。") print("- 好的,%s 。當(dāng)前已走到第50格。" % player["name"]) print("")
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python使用urllib2模塊獲取gravatar頭像實(shí)例
python使用urllib2模塊獲取gravatar頭像的實(shí)例,大家參考使用吧2013-12-12python處理csv數(shù)據(jù)動態(tài)顯示曲線實(shí)例代碼
這篇文章主要介紹了python處理csv數(shù)據(jù)動態(tài)顯示曲線實(shí)例代碼,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01在Pycharm中項(xiàng)目解釋器與環(huán)境變量的設(shè)置方法
今天小編就為大家分享一篇在Pycharm中項(xiàng)目解釋器與環(huán)境變量的設(shè)置方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10Python?Socket實(shí)現(xiàn)遠(yuǎn)程木馬彈窗詳解
這篇文章主要介紹了Python?Socket實(shí)現(xiàn)遠(yuǎn)程木馬彈窗詳解,Socket用來描述IP地址和端口,是通信鏈的句柄,應(yīng)用程序可以通過Socket向網(wǎng)絡(luò)發(fā)送請求或者應(yīng)答網(wǎng)絡(luò)請求2022-07-07python讀取mat文件生成h5文件的實(shí)現(xiàn)
這篇文章主要介紹了python讀取mat文件生成h5文件的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07解決Tensorflow使用pip安裝后沒有model目錄的問題
今天小編就為大家分享一篇解決Tensorflow使用pip安裝后沒有model目錄的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06