python实现简单飞行棋
本人刚开始学习python,看了一段时间视频教程之后,决定做一个小游戏来巩固一下知识点,就做了一个文字版飞行棋,暂不具备图形界面。把代码贴出来,给自己留个标记。
chess_main.py
importchess_tools
#输入玩家信息
chess_tools.input_player()
whilechess_tools.end_flag:
forplayerinchess_tools.player_list:
chess_tools.ironman(player)
input(player["name"]+",请按enter掷骰子")
chess_tools.throw(player)
ifchess_tools.judge(player)==1:
break
chess_tools.hit(player)
chess_tools.speedup(player)
print("")
chess_tools.py
fromrandomimportrandint
player_list=[]
end_flag=1
definput_player():
num=input("数据玩家数量:")
i=0
whilei100:
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"]))
defjudge(player):
globalend_flag
ifplayer["score"]==100:
end_flag=0
print(player["name"]+"赢了")
return1
defhit(player):
"""
判断当前玩家是否会将领先的玩家撞回起飞位置
:paramplayer:当前玩家名字
"""
forother_playerinplayer_list:
ifplayer["score"]==other_player["score"]\
andother_player["name"]!=player["name"]:
other_player["score"]=0
defspeedup(player):
ifplayer["score"]==15or\
player["score"]==35or\
player["score"]==85:
player["score"]+=5
print("加速5格,当前在%d格"%player["score"])
defironman(player):
"""
主角光环,名字中含有指定字符的人可以获得50分加成
:paramplayer:当前玩家的名字
"""
master=player["name"].count("t")
ifmaster>0andplayer["score"]==0:
player["score"]=50
print("-IamIronMan!贾维斯,先给我加50分。")
print("-好的,%s。当前已走到第50格。"%player["name"])
print("") 
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
