作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
VBA 非常新。尝试搜索无济于事。我有以下代码:
monsterRollingForHit: rollForMonsterHit = (Int(2 * Rnd))
MsgBox rollForMonsterHit, 0, "Monster Hit Roll"
If rollForMonsterHit = 1 Then
GoTo monsterRollingForDmg
Else
GoTo playerRollingForHit
End If
'if monster hits we then roll for his base damage
'using a working around for randBetween due to Analysis Toolpak being required for that function
monsterRollingForDmg: rollForMonsterDmg = ((Int((6 * Rnd) + 1)))
MsgBox rollForMonsterDmg, 0, "Monster Dmg Roll"
GoTo monsterRollingForCrit
'we then add crit if the monster critically hits
monsterRollingForCrit: rollForMonsterCrit = (rollForMonsterDmg + ((Int(2 * Rnd)) * 8))
MsgBox rollForMonsterCrit, 0, "Monster Crit Roll"
GoTo rollingForPlayerArmor
'finally we reduce the monster's dmg with potential crit by the player's armor
rollingForPlayerArmor: finalMonsterDmg = (rollForMonsterCrit * (((Int((26 * Rnd) + 75))) / 100))
MsgBox finalMonsterDmg, 0, "Monster Final Dmg"
GoTo reducePlayerHealth
reducePlayerHealth: currentPlayerHP = (currentPlayerHP - finalMonsterDmg)
MsgBox currentPlayerHP, 0, "Current Player HP"
If currentPlayerHP > 0 Then
GoTo playerRollingForHit
Else
MsgBox "Monster Wins"
Exit Sub
End If
最佳答案
使用 Option Explicit
帮助查找变量名中的拼写错误。
这将是您似乎正在尝试的伪代码。另请注意,没有 goto 或标签。
Set MonsterHP and HeroHP
while monsterHP>0 and HeroHP>0
if MonsterHit then
work out monsterdmg
decide if critical
deduct from heroHP, accounting for any armor/dodge/etc
endif
if HeroHit then
work out HeroDmg
decide if critical
deduct from MonsterHP, accounting for any armor/dodge/etc
endif
wend
if monsterdmg>0 then
print "Monster Wins"
elseif heroHP>0 then
print "Hero wins"
else
print "They killed each other with their final blow!"
endif
关于vba - If/Else GoTo VBA Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20957187/
我是一名优秀的程序员,十分优秀!