我正在为玩家 A 与 B 的战斗编写简单的掉落公式 - 等级差异决定了掉落率。我的问题是,0: > 10 ||| 1 vs. 1 = 10%
它没有给出0: > 10 ||| 1 vs. 1 = 0%
- 为什么?
PhpFiddle:http ://www.phpfiddle.org/main/code/n1q-dw7
<?php
# lets simulate high level player A attacks low level player B
for ($A = 1; $A <= 100; $A++) {
$B = 1;
calculateMoneyDrop($A,$B);
}
# lets simulate low level player A attacks high level player B
for ($B = 1; $B <= 100; $B++) {
$A = 1;
calculateMoneyDrop($A,$B);
}
function calculateMoneyDrop($A,$B) {
$X = $A - $B;
echo '<strong>', $X, '</strong>: ';
switch ($X) {
case $X > 10:
echo "> 10 ||| ";
$X = 10;
break;
case $X < -90:
echo "< -90 ||| ";
$X = -90;
break;
}
$dropRate = 10 - $X;
echo $A, ' vs. ', $B, ' = ', $dropRate, '%<br>';
}