我仍然对编码应用程序还不熟悉,我正在尝试为自己玩的游戏制作战斗计算器。我已经完成了大部分的用户输入和数学运算,但是即使达到一定程度,即使将变量更改为Int64,我也遇到了溢出问题。
错误的行是:
damagedealt1 = dcfleet1hp / darmadahp * armadadmg
为便于说明,用户输入了船舶数量和船舶类型,然后软件从这些输入中计算出值。以下是与此代码相关的行:
'Fleet 1'
fleet1hp = fleet1hp + fleet1hpboost
fleet1dmg = fleet1dmg + fleet1dmgboost
cfleet1hp = fleet1hp * fleet1count
cfleet1dmg = fleet1dmg * fleet1count
'D Fleet 1'
dfleet1hp = dfleet1hp + dfleet1hpboost
dfleet1dmg = dfleet1dmg + dfleet1dmgboost
dcfleet1hp = dfleet1hp * dfleet1count
dcfleet1dmg = dfleet1dmg * dfleet1count
'Fleet 2'
fleet2hp = fleet2hp + fleet2hpboost
fleet2dmg = fleet2dmg + fleet2dmgboost
cfleet2hp = fleet2hp * fleet2count
cfleet2dmg = fleet2dmg * fleet2count
'D Fleet 2'
dfleet2hp = dfleet2hp + dfleet2hpboost
dfleet2dmg = dfleet2dmg + dfleet2dmgboost
dcfleet2hp = dfleet2hp * dfleet2count
dcfleet2dmg = dfleet2dmg * dfleet2count
'Text Fields Assignation'
tfleet1.Text = fleet1type
tfleet1count.Text = fleet1count
tfleet1hp.Text = cfleet1hp
tfleet1dmg.Text = cfleet1dmg
tfleet2.Text = fleet2type
tfleet2count.Text = fleet2count
tfleet2hpp.Text = cfleet2hp
tfleet2dmg.Text = cfleet2dmg
'Armada HP Calculations'
armadahp = cfleet1hp + cfleet2hp
armadadmg = cfleet1dmg + cfleet2dmg
darmadadmg = dcfleet1dmg + dcfleet2dmg
darmadahp = dcfleet1hp + dcfleet2hp
'Individual Fleet DMG Calculation'
'Broken Code Here'
damagedealt1 = dcfleet1hp / darmadahp * armadadmg
damagedealt2 = dcfleet2hp / darmadahp * armadadmg
damagetaken1 = cfleet1hp / armadahp * darmadadmg
damagetaken2 = cfleet2hp / armadahp * darmadadmg
这是变量的定义:
fleet1hp = A single ship in attacking fleet 1's HP
fleet1dmg = A single ship in attacking fleet 1's DMG
cfleet1hp = The HP combined of all ships in attacking Fleet 1
cfleet1dmg = The DMG combined of all ships in attacking Fleet 1
(then all the same with a 'd' before variable to denote defending fleets)
armadahp = The total HP of all Fleets of attacker
darmadahp = The total HP of all fleets of defender
damagedealt1 = Would be the total damage taken by a single fleet
这里的想法是所遭受的损害等于 舰队马力除以所有舰队马力乘以传入伤害
此行应执行的操作:
damagedealt1 = dcfleet1hp / darmadahp * armadadmg
但是此行会导致
System.OverflowException:“算术运算导致溢出。”
答案 0 :(得分:1)
在线评论。
{
“$schema”:.....
“extends”: [
“@schematics/angular”
],
“schematics”: {
“ng-add”: {
“description”:.., “factory”:..., “schema”:...
}
}
}