本人刚开始学习python,看了一段时间视频教程之后,决定做一个小游戏来巩固一下知识点,就做了一个文字版飞行棋,暂不具备图形界面。把代码贴出来,给自己留个标记。
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("数据玩家数量:") 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): """ 玩家扔骰子,随机1-6点 :param player: 当前玩家 :return: """ points = randint(1,6) # 首先判定是否起飞 if player["score"] == 0 and points == 6: player["score"] = 1 print("%d 点,恭喜起飞!当前在第%d格" % (points, player["score"])) elif player["score"] == 0 and points < 6: print("%d 点,起飞失败!" % points) return # 分数大于100,要后退,多几分退几步 elif player["score"] + points > 100: player["score"] = player["score"] - (player["score"]+ points) % 100 + 1 print("%d 点,飞过头了!回到%d格" % (points,player["score"])) else: player["score"] += points print("%d 点!当前在第%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): """ 判断当前玩家是否会将领先的玩家撞回起飞位置 :param player: 当前玩家名字 """ 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格" % player["score"]) def ironman(player): """ 主角光环,名字中含有指定字符的人可以获得50分加成 :param player:当前玩家的名字 """ master = player["name"].count("t") if master > 0 and player["score"] == 0: player["score"] = 50 print("- I am Iron Man!贾维斯,先给我加50分。") print("- 好的,%s 。当前已走到第50格。" % player["name"]) print("")
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
python,飞行棋
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“python实现简单飞行棋”评论...
更新日志
2025年01月03日
2025年01月03日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]