作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想制作一个小型回合制游戏。我只编码了轮到我的回合,并且只轮到我的回合。然而,当我执行回合时,我不会对CPU造成任何损害,并且在选择该选项时我也不会治愈自己。
import random
print("Let's play a turn based game")
print("Your moves are:")
print("")
print("1) Fire Blast(18 to 25 HP) 2) Aura Sphere(10 to 35 HP) 3) Recover(Recover 10 to 30 HP)")
print("You can go first")
playerHP = 100
cpuHP = 100
fireBlast = random.randint(18,25)
auraSphere = random.randint(10,35)
recover = random.randint(10,30)
while playerHP >= 0 or cpuHP >= 0:
print("")
print("You have",playerHP,"HP")
print("I have",cpuHP,"HP")
playerMove = input("Which move do you choose? ")
print("Initiate player's move!")
if playerMove == "Fire Blast" or "fire blast":
cpuHP == cpuHP - fireBlast
print("You used Fire Blast! I now have",cpuHP,"HP")
elif playerMove == "Aura Sphere" or "aura sphere":
cpuHP == cpuHP - auraSphere
print("You used Aura Sphere! I now have",cpuHP,"HP")
elif playerMove == "Recover" or "recover":
playerHP == playerHP + recover
print("Healed! You now have",playerHP,"HP")
else:
print("You didn't choose a move...")
最佳答案
第一个问题在于 if 行:
if playerMove == "Fire Blast" or "fire blast":
#(...)
elif playerMove == "Aura Sphere" or "aura sphere":
#(...)
elif playerMove == "Recover" or "recover":
#(...)
小写值不起作用。执行此操作时,首先将评估“Fire Blast”或“fireblast”
部分,从而产生“Fire Blast”
值,如 bool 或两个非空字符串中的
是第一个字符串。相反,你应该使用:
if playerMove == "Fire Blast" or playerMove == "fire blast":
#(...)
elif playerMove == "Aura Sphere" or playerMove == "aura sphere":
#(...)
elif playerMove == "Recover" or playerMove == "recover":
#(...)
或者为了简化你可以使用 lower()
:
playerMove = playerMove.lower()
if playerMove == "fire blast":
#(...)
elif playerMove == "aura sphere":
#(...)
elif playerMove == "recover":
#(...)
第二个问题是马力减法线:
cpuHP == cpuHP - fireBlast
cpuHP == cpuHP - auraSphere
playerHP == playerHP + recover
==
运算符用于比较值。你想要的是赋值运算符=
:
cpuHP = cpuHP - fireBlast
cpuHP = cpuHP - auraSphere
playerHP = playerHP + recover
关于python - 回合制游戏坏了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33888990/
我正在 android 上构建一个简单的两人回合制游戏: 我一直在回顾谷歌为 Android 多人游戏提供的很棒的 API: https://developers.google.com/games
有没有一种方法可以创建回合制游戏而无需为其设置服务器?例如,假设你想制作一个国际象棋游戏。您希望用户在一天中只要有机会就可以进行轮流(而不是立即与对手进行比赛)。当用户移动时,对手现在需要移动。苹果是
所以基本上我想构建一个实时的回合制 iPhone 游戏,后端在 Rails 中实现。 游戏流程如下: Player A and Player B will queue for a match. The
我是一名优秀的程序员,十分优秀!