1

重複の可能性:
非静的フィールドへの静的参照を作成できません

ここでこのコードを作成しました: http://mibpaste.com/naGV58 arraylists を使用して、目的の結果を成功させます。ご覧のとおり、各エージェントは、arrive(PVector) を使用して別のエージェントにアタッチされます。方法。

サブクラスなどを作成するために、継承とポリモーピズムを実装してプロセス全体を再構成しようとしました。ここにある新しいコード: http://mibpaste.com/WwZBWz 特定のメソッドを適用しようとすると問題が発生します。バグは次のとおりです。

非静的フィールド MW2.location への静的参照を作成できません

それを解決する方法はありますか?各サブクラスから新しいオブジェクトを作成する必要があると思いますが、方法がわかりません...

私が試したことはすでに失敗しています。構文についてもわかりません。

どんな助けでも大歓迎です!

agents = new ArrayList<Capsule>(); // creating the agents

for (int i = 0; i < 85; i++) {
if (i < 20) agents.add(new MW1(random(width),random(height),color(255,0,0),i));
else if (i < 45) agents.add(new FW1(random(width),random(height),color(0,255,0),i));
else if (i < 65) agents.add(new MW2(random(width),random(height),color(155,0,0),i));
else agents.add(new FnW2(random(width),random(height),color(0,155,0),i));
}
}


//--------------configuring the canvas & the counter-------------


void draw() {
background(255);
time(); //reference to the visual timer


if(millis() - time >= wait){
println(counter);//if it is, do something
temp=counter;
time = millis();//also update the stored time
counter++; // counter augmentation

if(counter >180){ // check whether time exceeds 180 sec. aka 24:00 hours
counter=0; 
}
}

//-------------------------------------------------------------

work.Default(); //main-basic functions of (W) facility
retail.Default(); //main-basic functions of (R) facility
school.Default(); //main-basic functions of (S) facility
leisure.Default(); //main-basic functions of (L) facility

PVector vectorOfwork = new PVector(work.location.x, work.location.y); 
PVector vectorOfretail = new PVector(retail.location.x, work.location.y); 
PVector vectorOfschool = new PVector(school.location.x, school.location.y); 
PVector vectorOfleisure = new PVector(leisure.location.x, leisure.location.y); 

for( Capsule agent : agents) { // instancing - creating objects
agent.Default(); // global separation that affects ALL the agents
agent.separate(agents); // global separation that affects ALL the agents

if (counter>0 && counter<=30) {

if (agent instanceof FnW2)
agent.arrive(MW2.location); 
}
}
}
4

0 に答える 0