gpt4 book ai didi

java - OOP Java如何增加生命值并减少MP?

转载 作者:行者123 更新时间:2023-12-01 19:27:24 25 4
gpt4 key购买 nike

如何在 useSkill 方法中引用 hit_point?我现在所拥有的根本没有增加hit_point

public int hit_point() {
int total_power = this.power + this.weapon.getPower();
return total_power;
}
//------------------------------------------------------why isn't this increasing the hit point at all?

public int useSkill() {
this.mp=this.mp-1;
this.skill--;
return hit_point() +30;
}

public int getSkill() {
return skill;
}

最佳答案

返回值时,方法不会存储返回值,除非您告诉程序按如下方式存储该值:int TotalHitPoint = useSkill()。然后 useSkill() 不仅会添加到已经计算出的总生命值中,还会将其存储在您可以按需使用的变量中。

关于java - OOP Java如何增加生命值并减少MP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59297110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com