タグのアイデアに基づいて基本的なゲームエンジンを作ろうとしています。すべてのオブジェクトには壁のようなものをグループ化するためのタグがたくさんあります一度にすべての操作を実行します。私は、すべての関数を各オブジェクトで呼び出すためにループで囲む必要はないので、各オブジェクトで渡されたメソッドを呼び出すことができるメソッドを作成しようとしています。ここオブジェクトのリストにパラメータとして関数を渡す
は、いくつかの例の須藤コードです:
//have a list of objs. some door, some not.
//an example of stuff I could want to do
// - check returns on any functions called
// - call a function on a bunch of objects, possibly with parameters
if (runOnTag("door", isClosed())[aPositionInReturnList] == true){
runOnTag("door", open());
}
//the method
public couldBeAnyType[] runOnTag(String tag, function(anyPerams)){ //dont want the function to compile here
for (String currentObj : listOfObjsWith[tag]){
returns[index++] = currentObj.function(anyPerams); //so that it can be executed on this object
}
return returns; //want to be able to colect returns
}
私はすでにこの種の質問に他の回答の束を通して見ているが、私は彼らに何が起こっているか理解していません。誰かがそれをもっと簡単に説明できるなら、私はそれを高く評価します。
あなたのオブジェクトのリストの定義を表示できますか?これを行うより良い方法があるはずです – jack3694078