あなたの問題は、グラディエーターの配列を別のクラスに渡したいということに要約されると思います。それはかなり簡単なはずです。メインクラスにこれらの 2 つの定義がある場合 (必要なのは 1 つだけであることに注意してください。より用途が広く、配列は固定長であるため、リストをお勧めします)。
次のようなものが必要です。
public class Main {
// ....stuff
// This is the main class that keeps the list of gladiators
private List<Gladiator> gladiatorsList;
private Gladiator[] gladiatorsArray;
private MovementAI movementAI;
public Main() {
// You initialize gladiatorsList and gladiatorsArray as before
// gladiatorsList = ...
// gladiatorsArrray = ...
// Now you want to pass this list/array to another class (the AI), you
// can do this in the constructor of that class like so:
movementAI = new MovementAI(gladiatorsList);
}
// ...stuff as before
}
AI
public class MovementAI {
private List<Gladiator> gladiators;
// Giving the class the list-reference, this list will be the same as the
// list in main, when main-list changes so does this one, they point to the
// same list-object, so the reference is only needed once.
public MovementAI(List<Gladiator> gladiatorsList) {
this.gladiators = gladiatorsList;
}
// The class already has a reference to the list from its constructor so it
// doesn't need the list again as a parameter
public void moveAI() {
}
// If you don't want to keep a reference to the list in this class but only
// use it in a method (I would not recommend this)
public MovementAI() {
}
// You need to pass it gladiatorsList everytime you call this method.
public void moveAI(List<Gladiator> gladiators) {
}
}
前回のコメントで、AI が基準を満たした場合に再描画を決定することを決定したことを確認しましたが、これは推奨されません。クラスで責任を分離し、エラーが発生しにくく、開発を改善する必要があります。AI にグラディエーターのリストを変更させ (移動、キルなど)、rendererclass ですべてのグラディエーターを単純にペイントすることをお勧めします。
また、すべてのグラディエーターが別のグラディエーターをターゲットとして保持できるようにしたいようです。ターゲットをオブジェクトとして保持することをお勧めします。この方法では、リスト全体を検索して、どのグラディエーターがグラディエーター番号は参照しており、リスト内の順序について考える必要はありません。このようなもの:
public class Gladiator {
// ..other stuff
private Gladiator target;
public Gladiator getTarget() {
return target;
}
public void setTarget(Gladiator target) {
this.target = target;
}
}