这篇文章主要介绍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怎样实现简单飞行棋”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联成都网站设计公司行业资讯频道!
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。