| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /** 动物数据类 */
- import Util from "../util/Util";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class PastureData {
- /** 所有点字典 */
- public pointMap: Map<number, cc.Vec2> = new Map<number, cc.Vec2>();
- /** 可移动key数组 */
- public canMoveArr: Array<number> = new Array<number>();
- /** 不可移动key数组 */
- public noCanMoveArr: Array<number> = new Array<number>();
- setPointMap(index, point: cc.Vec2) {
- this.pointMap.set(index, point);
- this.setCanMove(index);
- }
- getCanMovePoint() {
- let len = this.canMoveArr.length;
- let i = Util.rnd(0, len - 1);
- let index = this.canMoveArr[i];
- this.setCanMove(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);
- }
- }
|