根據(jù)不同狀態(tài)進(jìn)行事件處理
init() {
this.stateHandler = {
[State.Standby]: this.sH_standby,
[State.Moving]: this.sH_moving,
[State.CheckAttacking]: this.sH_checkAttack,
[State.Callback]: this.sH_callback,
};
}
調(diào)用時(shí)根據(jù)狀態(tài)值取到對(duì)應(yīng)方法
let handler = this.stateHandler[curState];
遍歷全部成員
function forEach(handler: { (ship: GShip, ...args) }, ...args) {
handler(this.flagship, ...args);
const ships = this.ships;
for (let guid in ships) {
handler(ships[guid].ship, ...args);
}
}
this.forEach(function (ship: GShip, team: Team, interShips?: GShip[]) {
\\\............
}, this, interShips);
this.forEach(ship => {ship.vo.inBattle = false; })