【发布时间】:2016-04-08 02:24:11
【问题描述】:
所以我正在尝试制作一个基于标签概念的基本游戏引擎,其中每个对象都有一堆标签,我可以使用这些标签对墙段等事物进行分组并同时对它们执行所有操作。由于我不想用循环包围每个函数以在每个对象上调用它,因此我正在尝试创建一个可以在每个对象上调用传递的方法的方法。
这里是一些示例 suto 代码:
//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
}
我已经查看了此类问题的许多其他答案,但我不明白其中发生了什么。如果有人能更简单地解释一下,我将不胜感激。
【问题讨论】:
-
你能显示你的对象列表的定义吗?应该有更好的方法来做到这一点