php - 定义有关 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 是正数,它们应该减去负数。
解决方案
推荐阅读
- appium - 如何在移动元素上写文本而不清除它
- python - 如何通过单击将焦点设置到小部件(不是条目)?
- android - 如何在我的应用中获取现在的在线用户数
- azure-active-directory - Microsoft Graph API 权限更改未使用 Azure Active Directory 传播
- wordpress - 根据您要离开的页面加载 Wordpress 模板
- python - 正则表达式的最小化
- javascript - 以 JavaScript 中最具介绍性的方式/级别打印或显示图像 url 作为条件语句的结果
- c# - 在 EntityFramework 中使用 Where() 会导致 System.ArgumentException
- java - 在 RecyclerView.Adapter 内滚动到位置
- c++ - 使用 Jenkins 将 c++ 库部署到 Artifactory