PastureData.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /** 动物数据类 */
  2. import Util from "../util/Util";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class PastureData {
  6. /** 所有点字典 */
  7. public pointMap: Map<number, cc.Vec2> = new Map<number, cc.Vec2>();
  8. /** 可移动key数组 */
  9. public canMoveArr: Array<number> = new Array<number>();
  10. /** 不可移动key数组 */
  11. public noCanMoveArr: Array<number> = new Array<number>();
  12. setPointMap(index, point: cc.Vec2) {
  13. this.pointMap.set(index, point);
  14. this.setCanMove(index);
  15. }
  16. getCanMovePoint() {
  17. let len = this.canMoveArr.length;
  18. let i = Util.rnd(0, len - 1);
  19. let index = this.canMoveArr[i];
  20. this.setCanMove(index);
  21. let point = this.pointMap.get(index);
  22. return point;
  23. }
  24. setCanMove(index) {
  25. let has = this.noCanMoveArr.indexOf(index)
  26. if (has != -1) {
  27. this.noCanMoveArr.splice(has, 1)
  28. }
  29. this.canMoveArr.push(index);
  30. }
  31. setNoCanMove(index) {
  32. let has = this.canMoveArr.indexOf(index)
  33. if (has != -1) {
  34. this.canMoveArr.splice(has, 1)
  35. }
  36. this.noCanMoveArr.push(index);
  37. }
  38. }