そう:
私は、クラスとインスタンス変数を使用していますが、私はインスタンス変数があること数に基づいて、乱数生成方法作成しようとしています、Javaでテキストベースのゲームを作るに取り組んでいmax_attack
ています。
public class badPlayer
{
String description;
int health;
int award;
int max_attack;
public badPlayer(String description, int health, int award, int attack){
this.description=description;
this.health = health;
this.award = award;
this.max_attack = attack;
}
Random rnd = new Random();
public int maxAttack(){
int rand_int1 = rnd.nextInt(max_attack);
return rand_int1;
}
}
public class troll extends badPlayer
{
troll(int attack){
super("troll", 100, 50, 100);
}
}
出力
troll1005089
私は1と100の間の乱数を作成するための方法をしたいと思います。
Jocke:
Random r = new Random();
int low = 1;
int high = 100;
int result = r.nextInt(high-low) + low;