LayerEmptyAction.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { _decorator, Component, Node } from 'cc';
  2. import { PinAction } from './PinAction';
  3. import { EmptyHoleAction } from './EmptyHoleAction';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('LayerEmptyAction')
  6. export class LayerEmptyAction extends Component {
  7. start() {
  8. }
  9. update(deltaTime: number) {
  10. }
  11. public get_pin_by_color(color_id: number, pin_arr: PinAction[]) {
  12. this.node.children.forEach(empty_hole => {
  13. empty_hole.getComponent(EmptyHoleAction)?.get_pin_arr_by_color_id(color_id, pin_arr);
  14. });
  15. }
  16. public get_pin_arr(arr: PinAction[] = null): PinAction[] {
  17. // let arr:PinAction[] = [];
  18. if (!arr) {
  19. arr = [];
  20. }
  21. for (let i = this.node.children.length - 1; i >= 0; i--) {
  22. let empty_hole = this.node.children[i];
  23. let empty_hole_action = empty_hole.getComponent(EmptyHoleAction);
  24. if (empty_hole_action) {
  25. empty_hole_action.get_pin_arr(arr);
  26. }
  27. }
  28. return arr;
  29. }
  30. public put_pin(pin: PinAction) {
  31. for (let i = this.node.children.length - 1; i >= 0; i--) {
  32. let empty_hole_action = this.node.children[i].getComponent(EmptyHoleAction);
  33. if (empty_hole_action?.can_able_put()) {
  34. if (empty_hole_action?.put_pin(pin)) {
  35. //放入成功,结束
  36. break;
  37. }
  38. }
  39. }
  40. }
  41. //true = 满了
  42. public is_pin_full(): boolean {
  43. let ret = true;
  44. for (let i = 0; i < this.node.children.length; i++) {
  45. let empty_hole = this.node.children[i];
  46. let empty_hole_action = empty_hole.getComponent(EmptyHoleAction);
  47. if (!empty_hole_action) {
  48. continue;
  49. }
  50. if (empty_hole_action?.can_able_put()) {
  51. //还可以放入,结束了
  52. ret = false;
  53. break;
  54. }
  55. }
  56. return ret;
  57. }
  58. //check 获取上锁的个数
  59. get_unlock_num(): number {
  60. let num = 0;
  61. for (let i = this.node.children.length - 1; i >= 0; i--) {
  62. // console.log("unlock_empty_hole i:",i);
  63. let empty_hole = this.node.children[i];
  64. let empty_hole_action = empty_hole.getComponent(EmptyHoleAction);
  65. if (empty_hole_action?.isLocked) {
  66. num++
  67. }
  68. }
  69. return num;
  70. }
  71. // public get_pin_arr(arr:PinAction[] = null): PinAction[] {
  72. unlock_empty_hole() {
  73. for (let i = this.node.children.length - 1; i >= 0; i--) {
  74. // console.log("unlock_empty_hole i:",i);
  75. let empty_hole = this.node.children[i];
  76. let empty_hole_action = empty_hole.getComponent(EmptyHoleAction);
  77. if (empty_hole_action?.isLocked) {
  78. empty_hole_action.unlock_hole(null);
  79. break;
  80. }
  81. }
  82. }
  83. /**
  84. *
  85. */
  86. public init_empty() {
  87. this.node.children.forEach(empty_hole => {
  88. empty_hole.getComponent(EmptyHoleAction)?.init_empty_hole();
  89. });
  90. }
  91. }