创建一个有功能问题的网络游戏

时间:2017-05-13 16:39:19

标签: php mysql

我目前正致力于为严格使用php,html,sql& s构建的浏览器开发游戏。 js atm。这只是一个有趣的项目我正在努力。然而,我来到一个功能不按预期工作的地方,也许一些帮助可以帮助我找到我错的地方。所以说,我有一个页面,你可以打击敌人。现在,一旦你按下攻击按钮,它就会计算出一个公式,然后根据敌人当前的健康状况更新敌人的生命值 - 所谓的公式。现在按预期工作。我继续前进,然后反过来(当一个敌人攻击我时),它没有按预期工作。无论如何,它始终将角色健康设置为0而不是运行正确的公式等。$enemy& $my_character是数组。

$enemy = Array ( [level] => 1 [cur_health] => 104 [max_health] => 108 [cur_mana] => 36 [max_mana] => 36 [defense] => 30 [attack_power] => 16 [spell_power] => 3 [image] => images/enemies/demon_1.png [name] => Demon [battleback] => images/battlebacks/cave1.png )

$my_character = Array ( [name] => rackemup [level] => 1 [next_level] => 2 [avatar] => 05.png [class] => Knight [race] => Human [max_health] => 135 [current_health] => 135 [max_mana] => 9 [current_mana] => 9 [next_level_xp] => 100 [current_xp] => 30 [sp] => 0 [gold] => 115 [tokens] => 0 [ac] => 0 [defense] => 18 [attack_power] => 20 [spell_power] => 1 )  

控制器:

if ($action == "attack") {

  charAttack($enemy,$my_character);

  enemyAttack($enemy,$my_character);

  header("Location: ?route=$route&msg=2#attack");
  exit;

}

型号:

function enemyAttack($enemy,$my_character) {
  $dmg = $enemy['attack_power'] - $my_character['defense'];
  if ($dmg <= 0) {
    $dmg = 1;
  }else{
    $dmg = ceil($dmg);
  }
  $cur_hp = $my_character['cur_health'] - $dmg;
  updateCharacter($_SESSION['char'],"health",$cur_hp);
  updateLog("Enemy Attack","The Enemy Hit You For ".number_format($dmg)." Damage!");
}

function charAttack($enemy,$my_character) {
  $dmg = $my_character['attack_power'] - $enemy['defense'];
  if ($dmg <= 0) {
    $dmg = 1;
  }else{
    $dmg = ceil($dmg);
  }
  $cur_hp = $enemy['cur_health'] - $dmg;
  updateEnemy($_SESSION['char'],"health",$cur_hp);
  updateLog("User Attack","Your Attack Hit The Enemy For ".number_format($dmg)." Damage!");
}

1 个答案:

答案 0 :(得分:2)

$my_character['current_health']中尝试$my_character['cur_health']而不是enemyAttack? ; - )