import { _decorator, Color, Mask, v3, Vec2, Vec3 } from 'cc'; import { Container } from '../container/Container'; import { ContainerView } from '../container/ContainerView'; import { BoardState, CellState, ObstacleType, PatternType } from '../../util/Enum'; export interface evt { } // 格子数据结构 interface CellData { x: number; y: number; state: CellState; patternType?: PatternType; isStartPoint?: boolean; isEndPoint?: boolean; obstacleType?: ObstacleType; // 障碍物类型 isBreakable?: boolean; // 是否可破坏 isMovable?: boolean; // 是否可移动 } export class Board { state: BoardState selectedContainer: Container containerView: ContainerView isWaitingSwap: boolean = false;//是否可用 private _evt = chsdk.get_new_event(); get evt() { return this._evt; } private _boardSize: number = 49; private _boardRows: number = 7; private _boardCols: number = 7; private _boardData: CellData[][] = []; private _lines: { type: PatternType, points: Vec2[] }[] = []; private _selectedPoint: Vec2 = null; private _currentPatternType: PatternType = null; private _pathCells: Vec2[] = []; // 当前路径经过的格子 // 初始化棋盘数据 initBoard(rows: number, cols: number) { this._boardRows = rows; this._boardCols = cols; this._boardData = []; for (let y = 0; y < this._boardRows; y++) { this._boardData[y] = []; for (let x = 0; x < this._boardCols; x++) { this._boardData[y][x] = { x, y, state: CellState.EMPTY }; } } } // Getter 和 Setter 方法 get boardData(): CellData[][] { return this._boardData; } set boardData(value: CellData[][]) { this._boardData = value; } get lines() { return this._lines; } set lines(value) { this._lines = value; } get selectedPoint() { return this._selectedPoint; } set selectedPoint(value) { this._selectedPoint = value; } get currentPatternType() { return this._currentPatternType; } set currentPatternType(value) { this._currentPatternType = value; } get boardRows() { return this._boardRows; } set boardRows(value) { this._boardRows = value; } get boardCols() { return this._boardCols; } set boardCols(value) { this._boardCols = value; } get boardSize() { return this._boardSize; } set boardSize(value) { this._boardSize = value; } // 获取路径经过的格子 get pathCells() { return this._pathCells; } set pathCells(value) { this._pathCells = value; } // 清除当前路径 clearCurrentPath() { this._pathCells = []; this._selectedPoint = null; this._currentPatternType = null; } }