0

さまざまな属性を持つクラスのリストを作成したいのですが、問題に直面しています:新しいものを追加すると、他のすべてが変更されます.(コードは非常に大きいので、小さなサンプルを投稿しています)

public abstract class A{
public static Point Position;
public static int LifePoints;
public static int range;
public static int atackValue;
public static double movementSpeed;

public double getMovementSpeed() {
return movementSpeed;
}
public static void setMovementSpeed(double movement) {//this n funciona
movementSpeed = movement;
}
(...)to make the topic shorter i only show the movement part but class A contains all getters and setters for all movement,position,range,life points and attack value
}

public class B extends A{

public static Point Position;
public static int LifePoints=10000;
public static int range=50;
public static int atackValue=100;
public static double movementSpeed=2;

public A(Point startPoint){
setMovementSpeed(movementSpeed);
setAtackValue(atackValue);
setRange(range);
setLifePoints(LifePoints);
setPosition(startPoint);
}

public class createB(){

(...)

public void create(){

private List<B> list = new ArrayList<B>();

B b = new B(startpoint);

list.add(b);

}

(...)

for(int x=0;x!=list.length();x++){

move(list.get(x));

system.out.println(list.get(x).getMovementSpeed());

}

println は、作成されたすべての b に対して正しい値 (2.0) を返しますが、新しい b を作成するたびに、他のすべての b の移動が停止し、新しい b は前のものよりも速く移動します。ムーブ機能は先生が作ったもので動作確認済みです。位置が正しく機能していないと思われ、写真を2ピクセル移動する代わりに、X回だけ移動します。

4

2 に答える 2