【发布时间】:2015-02-16 15:04:13
【问题描述】:
我正在尝试制作基于文本的游戏,并且为了制作我的战斗机制,我必须重复 if 语句,直到你或怪物死去。
这里是 --Ph 代表玩家健康,str 是玩家力量,mdam 是怪物伤害,mstr 是怪物力量,monsterh 是怪物健康,@987654327 @是你获得的攻击奖励(加上这个,有没有办法将数字四舍五入到一位或没有小数位?)谢谢! :D
if fight == "A" and ph > 0:
damage = (str) + (random.random())
monsterh = 6
mstr = 0.9
monsterh = (monsterh) - (damage)
print(damage)
print(damage - str)
print('You attack the monster. You deal %s damage.' % damage )
time.sleep(3)
if monsterh > 0:
mstr = 0.9
mdam = (mstr) + (random.random())
print('The monster attacks you!')
ph = ph - mstr
print("You get hit %s" % mdam )
else:
xpgain = damage + 5
print("You won! You've gained %s XP!" % xpgain)
【问题讨论】:
-
你想要一个
while循环。查看docs.python.org/2/tutorial/…。 -
你可以把整个事情循环起来:
while i_am_not_dead and monster_is_not_dead: ...
标签: python