グループ プロジェクトの一環として、自分で選ぶアドベンチャー「ゲーム」を作成しています。私の考えは、その StoryRoom の説明、それに接続している他の StoryRoom などの情報を格納するタイプの StoryRoom のオブジェクトを作成することです。また、StoryRoom の配列になる冒険を作成するためのクラスも必要です。 . アイデアは、プレイヤーが最終シナリオに到達するまで、メイン プログラムが StoryRooms を循環し、テキストを表示し、次の StoryRoom の参照となる決定が行われたときに値を返すというものです。
私が抱えている問題は、AdventureTeller クラスを介して AdventureBuilder クラスで作成された StoryRooms にアクセスできないことです。AdventureTeller は、ゲームのドライバー クラスです。Eclipse は、entryway を変数として解決できないというエラーをスローします。どうすればこれを修正できますか?
public class StoryRoom {
public String[] description = null;
public int[] exits;
public StoryRoom(String[] builddescriptions, int[] buildexits){
description = new String[builddescriptions.length];
exits = new int[buildexits.length];
for (int i = 0; i< builddescriptions.length; i++){
description[i] = builddescriptions[i];
}
for (int i = 0; i< buildexits.length; i++){
exits[i] = buildexits[i];
}
}
public String GetDescription(int reference){
return description[reference];
}
public int GetExit(int reference){
return exits[reference];
}
}
public class AdventureTeller {
public static void main(String[] args) {
AdventureBuilder.main();
for (int i = 0; i < entryway.description.length; i++)
{
System.out.println(entryway.GetDescription(i));
}
}
}
public class AdventureBuilder {
public static void main() {
// StoryRoom[] book = new StoryRoom[20];
String[] description = null;
description = new String[3];
int[] exits;
exits = new int[3];
description[0] = "This is a strange room with 2 doors, one on the left and one on the right.";
description[1] = "Take the left door? (enter 1)";
description[2] = "Take the right door? (enter 2)";
exits[0] = 1; // current room number
exits[1] = 2;
exits[2] = 3;
StoryRoom entryway = new StoryRoom(description, exits);
}
}