更新メソッドを持つエンティティがゲームにあります。最も近いゾンビをターゲットにする必要があります。現在、ゾンビのリストはアクセスするグローバルオブジェクトにすぎませんが、これは間違っているようです。リストを更新メソッドに渡すことができますが、これが最善のアプローチかどうかわかりませんか?
これが私の更新方法の簡略版です:
this.update = function () {
var targetedZombie = null;
//TODO: should not be using the zombies object - tight coupling should be removed
var alivezombies = [];
for (var zombie in zombies) {
if (zombies[zombie].Alive) {
alivezombies.push(zombies[zombie]);
}
}
targetedZombie = this.GetClosestEntity(alivezombies);
if (targetedZombie) {
Fire(this, targetedZombie);
}
});