首页 > 解决方案 > 定义有关 Player_HP 和 Damage 的变量

问题描述

下面创建的变量定义了来自玩家和对手的伤害量。之后是生命的一部分,根据给定的伤害,每个人都会消耗 X% 的生命。然后,变量 $player_hp 和 $对手_hp 的剩余 LIFE 被插入到 DATABASE 中。(更新说“player_health =?”。

错误:每次我进行攻击时,它都会删除 LIFE($ player)并在 DATABASE 中将 MORE LIFE(它应该删除直到它为负数)添加到 OPPONENT($ 对手),但只是为对手增加更多生命。

 Exemp: $player_damage = 1200
        $opponent_damage = 500

        $player_hp = 100(hp) - $opponent_damage  
        $opponent_hp = 100(hp) - $player_damage

数据库显示基本上是这样的:

  Player_VIDA = -400
  Opponent_VIDA = 600

我在 UPDATE player_health = player_health -? 上尝试过用户,但它是一样的。

我使用的代码:

$player_damage = rand(5, $player_status['attack']);
$player_damage = $player_damage - ($opponent_status['defense'] * 0.3);

$opponent_damage = rand(5, $opponent_status['attack']);
$opponent_damage = $opponent_damage - ($player_status['defense'] * 0.3);

//add def to the health and subtract with damaged
$player_hp = round($opponent_damage - $player_status['health']);
$opponent_hp = round($player_damage - $opponent_status['health']);  

解决方案:我需要知道为什么 PLAYER 和 OPPONENT_HP 是正数,它们应该减去负数。

标签: phpmath

解决方案


推荐阅读