游戏设计:计算战斗后获得的经验值

时间:2010-11-23 00:33:59

标签: php math

我正在开发一个简单的文字对战游戏,并且在计算战斗后应该获得多少XP时遇到一些问题,这是我想要考虑的几个因素:

1)如果玩家击败同级别的玩家,玩家当然应该获得良好的XP

2)如果玩家击败了更高级别的玩家,玩家应该获得优秀的XP

3)如果玩家击败较低级别的玩家,玩家应该获得较差的XP。

4)上面应该很好地扩展,即如果玩家A是10级并且与9级或11级玩家B战斗,差异不应该是巨大的(他们当然会获得更多XP以击败11级角色但是我们不会指望这是巨大的),但如果他要在5级或15级战斗,这种差异应该是巨大的。

在计算在所有场景中运行良好的东西时遇到问题,目前我的XP表如下所示:

Current Level   XP Needed   Increase from Last Level
1   30  0
2   65  35
3   106 41
4   154 48
5   210 56
...
10  672 123

在PHP中,我的代码如下所示,以计算所需的XP:

$offset = 30;
$multiplier = 1.17;
$base = $prevXp * $multiplier;

$xp = $base + $offset;

我尝试了一些不同的东西,但我对它们中的任何一个都没有留下深刻印象,我想计算两个玩家之间XP的差异,然后使用某种倍增器,但我没有'迄今为止对结果印象深刻。

任何帮助/意见都将不胜感激。

2 个答案:

答案 0 :(得分:1)

这是我用于FB游戏的战斗方法。您可能会发现它很有用。

public function fight(Player $attacker, Player $defender){
      $return = 'Attacking '.$defender->getName().'
'; // if the defener has greater def than attackers attack, repel the attack // if the attacker has greater attack then the denfenders defense, penetrate if($attacker->getAttack() > $defender->getDefense()){ $attacker->takeTemper(1); // penetration -- that's what she said!!! // figure out how much to damage each player $dmgDefender = rand(5, 25); $defender->takeHP($dmgDefender); $dmgAttacker = rand(0, 10); // figure out the reward // give between 1 and 5 XP and 10% of the defenders money $gainedXP = rand(1, 5); $attacker->addXP($gainedXP); $gainedMoney = floor($defender->getMoney() * .1); $attacker->addMoney($gainedMoney); $defender->takeMoney($gainedMoney); $return .= 'You won the fight and gained '.$gainedXP.' XP and $'.$gainedMoney.'
'; if($dmgAttacker > 0){ $return .= 'Unfortuantely you took '.$dmgAttacker.' damage in the fight. The good news is you did '.$dmgDefender.' damage to '.$defender->getName().'
'; $attacker->takeHP($dmgAttacker); } // check if the player leveled $nextLevelXP = $this->_level->levelXP( $attacker->getLevel() + 1 ); if( ( $attacker->getXP() >= $nextLevelXP ) ){ $gainedFounderPoints = $this->gainLevel($attacker); $return .= 'You gained a level'; if($gainedFounderPoints > 0) $return .= ' and '.$gainedFounderPoints.IMG_FOUNDER_POINT; $return .= '
'; } } else { // attack deflected $return .= 'The attack was deflected by '.$defender->getName().'
'; // reward defender -- how about 10% of the attackers money? $reward = ceil($attacker->getMoney() * .1); if($reward > 0){ // demerit attacker $attacker->takeMoney($reward); $defender->giveMoney($reward); $return .= 'You lost $'.$reward.'
'; } else { // the attacker is broke ... take his XP!!! -- 1 percent $reward = ceil($attacker->getXP() * .01); $attacker->takeXP($reward); $defender->addXP($reward); $return .= 'You lost '.$reward.' XP
'; } } // save data $attacker->save(); $defender->save(); // output return $return; }

答案 1 :(得分:1)

这很简单,但符合您的标准

xpGain = getbasexp(); //whatever you were doing before
xpGain *= opponentxp * 1.0 / playerxp;