Java中计算两个数字之间的损害 [英] Calculating Damage Between Two Numbers In Java
问题描述
这不仅仅是寻找一个随机数,
This is not just about finding a random number,
我正在寻找的答案是如何将表达式添加到随机数以根据表达式计算数字.
The answer I am looking for is how to add an expression to a random number to calculate a number based on the expression.
例如,来自一系列数字的基本随机数,+ 角色的当前等级,* 角色的伤害增益.
For example a base random number from a range of numbers, + the current lvl of a character, * the character's damage gain.
如果我在 java
中创建一个像这样在两个数字之间造成伤害的字符,
If I am creating a character that does damage between two numbers like this in java
,
Damage = 44 to 55 per hit
我想把它写成一个变量,我该怎么做?
Damage = 44 to 55 per hit
and I want to write this into a variable, how can I do this?
我正在尝试这个,
double BottomDamage = 44 + level * 1.9;
double TopDamage = 55 + level * 1.9;
如果伤害介于这两个数字之间,那么写这样的东西的正确方法是什么44 到 55 + level * 1.9
???
What is the proper way to write something like this if the damage would be between these two numbers 44 through 55 + level * 1.9
???
推荐答案
你应该编写一个带有方法 damage
的接口,并且每种类型的字符都会有一个实现这个接口的类.
You should write an interface with a method damage
and each type of character would have a class that implements this interface.
public interface CausesDamage ()
{
public double damage ();
}
public abstact class CharacterType implements CausesDamage ()
{
private int _level;
...
public abstract double damage ();
...
public int getLevel ()
{
return _level;
}
}
public class Warrior extends CharacteType ()
{
public static final int MIN_DAMAGE = ..;
public static final int MAX_DAMAGE = ..;
...
private Random rand = new Random();
...
public double damage ()
{
return rand.nextInt(MAX_DAMAGE-MIN_DAMAGE+1)+MIN_DAMAGE + getLevel()*1.9;
}
}
这篇关于Java中计算两个数字之间的损害的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!