わかりました。コードを最初に配置して、わかりやすくします。
***編集:シーケンスが作成されたときにシーケンスのインスタンスをダイアログに渡すことで問題が解決され、ダイアログには呼び出す内部参照があります。
public abstract class RavelSequence {
protected Dialog dialog; //every subclass uses one of these objects
public abstract void hit();
}
public class BattleSequence extends RavelSequence {
public void init(){ //this is the edited fix
dialog.setSequence(this); //
} //
public void hit(){ //the effect of a 'hit' in battle
doSomething();
}
}
public class OutOfBattleSequence extends RavelSequence {
public void init(){ //this is the edited fix
dialog.setSequence(this); //
} //
public void hit(){ //the effect of a 'hit' outside battle
doSomethingElse();
}
}
public class Dialog extends Container implements Runnable {
private RavelSequence sequence; //this is the edited fix
public void run (){
if (somethingHappens)
sequence.hit();
}
public void setSequence (RavelSeqence sequence){ //this is the edited fix
this.sequence = sequence; //
} //
}
私がしたいのは、Dialogが、Dialogのインスタンスを所有するクラスに実装されているメソッドhit()を呼び出せるようにすることです。IntelliJ IDEAを使用していますが、「非静的メソッドヒットは静的コンテキストから参照できない」と表示されます。
すべては、ゲームのコンテキストに応じてシーケンスオブジェクトのインスタンスを作成するアプリケーション内で実行されるため、ヒットはシーケンス内の非静的オブジェクトを参照する必要があります。