/** 动物移动数据类 */ import Util from "../util/Util"; const { ccclass } = cc._decorator; @ccclass export default class PastureData { /** 所有点字典 */ private pointMap: Map = new Map(); /** 可移动key数组 */ private canMoveArr: Array = new Array(); /** 不可移动key数组 */ private noCanMoveArr: Array = new Array(); setPointMap(index, point: cc.Vec2) { this.pointMap.set(index, point); this.setCanMove(index); } getCanMoveIndex(oldIndex = -1) { let len = this.canMoveArr.length; let i = Util.rnd(0, len - 1); let index = this.canMoveArr[i]; this.setNoCanMove(index); if (oldIndex != -1) { this.setCanMove(oldIndex); } return index; } getCanMoveIndexPoint(index) { let point = this.pointMap.get(index); return point; } setCanMove(index) { let has = this.noCanMoveArr.indexOf(index) if (has != -1) { this.noCanMoveArr.splice(has, 1) } this.canMoveArr.push(index); } setNoCanMove(index) { let has = this.canMoveArr.indexOf(index) if (has != -1) { this.canMoveArr.splice(has, 1) } this.noCanMoveArr.push(index); } }