|
|
@@ -1,776 +0,0 @@
|
|
|
-/*
|
|
|
- * @Author: mojunshou 1637302775@qq.com
|
|
|
- * @Date: 2025-03-20 15:01:09
|
|
|
- * @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-04-19 18:08:35
|
|
|
- * @Description: 消除游戏主场景
|
|
|
- */
|
|
|
-import { _decorator, Button, EventTouch, JsonAsset, Label, Node, Prefab, Vec2, Vec3, tween } from "cc";
|
|
|
-import { oops } from "db://oops-framework/core/Oops";
|
|
|
-import { ecs } from "db://oops-framework/libs/ecs/ECS";
|
|
|
-import { LabelChange } from "db://oops-framework/libs/gui/label/LabelChange";
|
|
|
-import { CCComp } from "db://oops-framework/module/common/CCComp";
|
|
|
-import { GameEvent } from "../../common/config/GameEvent";
|
|
|
-import { UIID } from "../../common/config/GameUIConfig";
|
|
|
-import { smc } from "../../common/SingletonModuleComp";
|
|
|
-import { ServerHandler } from "../../common/manager/ServerHandler";
|
|
|
-import { EliminateGridManager } from "./EliminateGridManager";
|
|
|
-import { EliminateBrickManager } from "./EliminateBrickManager";
|
|
|
-import { EliminateAnimationManager } from "./EliminateAnimationManager";
|
|
|
-import { EliminateGuideManager } from "./EliminateGuideManager";
|
|
|
-import { EliminateAutoPlayManager } from "./EliminateAutoPlayManager";
|
|
|
-import { EliminateUIManager } from "./EliminateUIManager";
|
|
|
-import { BrickData, CellState, EditingData, GameState, GridData } from "./EliminateTypes";
|
|
|
-import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
|
|
|
-import { Format } from "../../utils/Format";
|
|
|
-
|
|
|
-const { ccclass, property } = _decorator;
|
|
|
-
|
|
|
-/** 视图层对象 */
|
|
|
-@ccclass('EliminateViewComp')
|
|
|
-@ecs.register('EliminateView', false)
|
|
|
-export class EliminateViewComp extends CCComp {
|
|
|
- @property({ type: LabelChange, displayName: "自动提现金额" })
|
|
|
- private lab_wxCoin: LabelChange = null!;
|
|
|
- @property({ type: LabelChange, displayName: "额外奖励" })
|
|
|
- private lab_hbCoin: LabelChange = null!;
|
|
|
- @property({ type: Node, displayName: "tween微信钱Node" })
|
|
|
- private tweenWechatNode: Node = null!;
|
|
|
- @property({ type: Node, displayName: "tween红包Node" })
|
|
|
- private tweenRedNode: Node = null!;
|
|
|
-
|
|
|
- @property({ type: Prefab, displayName: "金币预制体" })
|
|
|
- private coinPrefab: Prefab = null!
|
|
|
- @property({ type: Prefab, displayName: "红包预制体" })
|
|
|
- private redPacketPrefab: Prefab = null!;
|
|
|
- @property({ type: Label, displayName: "本局分数" })
|
|
|
- private lab_score: Label = null!;
|
|
|
- @property({ type: Label, displayName: "目标分数" })
|
|
|
- private lab_taget: Label = null!;
|
|
|
-
|
|
|
- @property({ type: Prefab, displayName: "item预制体列表" })
|
|
|
- private itemPrefabs: Prefab[] = [];
|
|
|
- @property({ type: Node, displayName: "网格Node" })
|
|
|
- private gridNode: Node = null!;
|
|
|
- @property({ type: Node, displayName: "移动Node" })
|
|
|
- private moveNode: Node = null!;
|
|
|
- @property({ type: Node, displayName: "旋转Node" })
|
|
|
- private rotateNode: Node = null!;
|
|
|
- @property({ type: Node, displayName: "方块Node" })
|
|
|
- private brickNode: Node = null!;
|
|
|
-
|
|
|
- @property({ type: Prefab, displayName: "旋转预制体" })
|
|
|
- private rotatePrefab: Node = null!;
|
|
|
- @property({ type: Label, displayName: "累计消除次数" })
|
|
|
- private lab_total: Label = null!;
|
|
|
- @property({ type: Label, displayName: "每次放置添加的分数" })
|
|
|
- private lab_addScore: Label = null!;
|
|
|
-
|
|
|
- @property({ type: Button, displayName: "自动按钮" })
|
|
|
- private autoBtn: Button = null!;
|
|
|
-
|
|
|
- @property({ type: Label, displayName: "第几块金砖" })
|
|
|
- private lab_goldNum: Label = null!;
|
|
|
-
|
|
|
- @property({ type: Label, displayName: "二倍速时间" })
|
|
|
- private lab_doubleTime: Label = null!;
|
|
|
-
|
|
|
- @property({ type: Node, displayName: "引导层" })
|
|
|
- private guideNode: Node = null!;
|
|
|
-
|
|
|
- @property({ type: Node, displayName: "ComboNode" })
|
|
|
- private comboNode: Node = null!;
|
|
|
-
|
|
|
- // 管理器
|
|
|
- private gridManager: EliminateGridManager = null!;
|
|
|
- private brickManager: EliminateBrickManager = null!;
|
|
|
- private animationManager: EliminateAnimationManager = null!;
|
|
|
- private guideManager: EliminateGuideManager = null!;
|
|
|
- private autoPlayManager: EliminateAutoPlayManager = null!;
|
|
|
- private uiManager: EliminateUIManager = null!;
|
|
|
-
|
|
|
- // 游戏配置
|
|
|
- private rows: number = 8; // 行数
|
|
|
- private cols: number = 8; // 列数
|
|
|
- private itemSize: number = 76.25; // 格子大小
|
|
|
- private brickNum: number = 3; // 砖块数量
|
|
|
- private yOffset = 100;
|
|
|
-
|
|
|
- // 游戏状态
|
|
|
- private gameState: GameState = GameState.READY;
|
|
|
- private operateFlag: boolean = false; // 是否可以操作
|
|
|
- private touchStartPos = new Vec2();
|
|
|
- private adShowingFlag: boolean = false; // 广告展示标记
|
|
|
-
|
|
|
- // 得分设置
|
|
|
- private eliminateBaseScore: number = 10; // 每行得多少分
|
|
|
- private extraGridScore: number = 1; // 每个格子占用几分
|
|
|
- private placementBaseScore: number = 1; // 每个格子占用几分
|
|
|
-
|
|
|
- // 连击设置
|
|
|
- private currentCombo: number = 0; // 当前连击次数
|
|
|
- private shouldResetEliminateCount: boolean = true; // 是否需要重置消除计数
|
|
|
-
|
|
|
- // 双倍速设置
|
|
|
- private isDoubleSpeed: boolean = false; // 是否开启二倍速
|
|
|
- private doubleSpeedTime: number = 0; // 双倍速剩余时间
|
|
|
- private callback: Function | null = null; // 计时回调函数
|
|
|
-
|
|
|
- // 编辑中的方块和格子
|
|
|
- private editingData: EditingData = {
|
|
|
- brickData: null,
|
|
|
- gridList: [],
|
|
|
- };
|
|
|
-
|
|
|
- // 消除区间数组
|
|
|
- private eliminateInterval: number[] = [];
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化
|
|
|
- */
|
|
|
- async start() {
|
|
|
- this.initManagers();
|
|
|
- this.setButton();
|
|
|
- this.uiManager.initButtonState(false);
|
|
|
- await this.brickManager.loadConfig();
|
|
|
- this.initData();
|
|
|
- this.uiManager.setData();
|
|
|
- this.addEventListeners();
|
|
|
-
|
|
|
- // 初始化网格
|
|
|
- if (this.guideManager.getGuideStep() === 0 && smc.account.AccountModel.curLevel == 1) {
|
|
|
- this.guideManager.startGuideMode();
|
|
|
- } else {
|
|
|
- this.initGame();
|
|
|
- }
|
|
|
-
|
|
|
- // 更新福利点
|
|
|
- this.uiManager.updateWelfarePoint();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化管理器
|
|
|
- */
|
|
|
- private initManagers(): void {
|
|
|
- // 创建网格管理器
|
|
|
- this.gridManager = new EliminateGridManager(
|
|
|
- this.gridNode,
|
|
|
- this.itemPrefabs,
|
|
|
- this.rows,
|
|
|
- this.cols,
|
|
|
- this.itemSize
|
|
|
- );
|
|
|
-
|
|
|
- // 创建方块管理器
|
|
|
- this.brickManager = new EliminateBrickManager(
|
|
|
- this.brickNode,
|
|
|
- this.rotateNode,
|
|
|
- this.moveNode,
|
|
|
- this.itemPrefabs,
|
|
|
- this.rotatePrefab,
|
|
|
- this.itemSize
|
|
|
- );
|
|
|
-
|
|
|
- // 创建动画管理器
|
|
|
- this.animationManager = new EliminateAnimationManager(
|
|
|
- this.node,
|
|
|
- this.coinPrefab,
|
|
|
- this.redPacketPrefab,
|
|
|
- this.lab_addScore,
|
|
|
- this.lab_wxCoin,
|
|
|
- this.lab_hbCoin,
|
|
|
- this.tweenWechatNode,
|
|
|
- this.tweenRedNode,
|
|
|
- this.comboNode
|
|
|
- );
|
|
|
-
|
|
|
- // 创建引导管理器
|
|
|
- this.guideManager = new EliminateGuideManager(
|
|
|
- this.guideNode,
|
|
|
- this.gridManager,
|
|
|
- this.brickManager
|
|
|
- );
|
|
|
-
|
|
|
- // 创建自动游戏管理器
|
|
|
- this.autoPlayManager = new EliminateAutoPlayManager(
|
|
|
- this.gridManager,
|
|
|
- this.brickManager,
|
|
|
- this.moveNode
|
|
|
- );
|
|
|
-
|
|
|
- // 创建UI管理器
|
|
|
- this.uiManager = new EliminateUIManager(
|
|
|
- this.lab_wxCoin,
|
|
|
- this.lab_hbCoin,
|
|
|
- this.lab_score,
|
|
|
- this.lab_taget,
|
|
|
- this.lab_total,
|
|
|
- this.lab_goldNum,
|
|
|
- this.lab_doubleTime,
|
|
|
- this.autoBtn
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化游戏
|
|
|
- */
|
|
|
- private initGame(): void {
|
|
|
- this.gridManager.initGrid();
|
|
|
- this.brickManager.initBricks(this.brickNum);
|
|
|
- this.setupBrickEvents();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置砖块事件
|
|
|
- */
|
|
|
- private setupBrickEvents(): void {
|
|
|
- const bricksList = this.brickManager.getBricksList();
|
|
|
- for (const brickData of bricksList) {
|
|
|
- this.brickManager.brickStartDrag(brickData, this.onBrickStartDrag.bind(this));
|
|
|
- this.brickManager.brickAddEvent(brickData, this.onBrickDrag.bind(this));
|
|
|
- this.brickManager.brickEndDrag(brickData, this.onBrickEndDrag.bind(this));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方块拖动开始事件处理
|
|
|
- */
|
|
|
- private onBrickStartDrag(brickData: BrickData, startPos: Vec3): void {
|
|
|
- // 如果正在编辑其他方块或不允许操作,则忽略
|
|
|
- if (!this.operateFlag) return;
|
|
|
-
|
|
|
- // 清空编辑中的数据
|
|
|
- this.editingData.brickData = null;
|
|
|
- this.editingData.gridList.length = 0;
|
|
|
-
|
|
|
- // 将方块移到移动层并设置位置
|
|
|
- if (brickData.brickNode) {
|
|
|
- const originalParent = brickData.brickNode.parent;
|
|
|
- brickData.brickNode.setParent(this.moveNode);
|
|
|
- brickData.brickNode.setWorldPosition(startPos);
|
|
|
- }
|
|
|
-
|
|
|
- // 从方块列表中移除该方块
|
|
|
- const index = this.brickManager.getBricksList().findIndex(item => item === brickData);
|
|
|
- if (index > -1) {
|
|
|
- const bricksList = this.brickManager.getBricksList();
|
|
|
- this.editingData.brickData = bricksList.splice(index, 1)[0];
|
|
|
- this.brickManager.setBricksList(bricksList);
|
|
|
- } else {
|
|
|
- console.error("未找到方块数据:", brickData);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方块拖动事件处理
|
|
|
- */
|
|
|
- private onBrickDrag(brickData: BrickData, position: Vec3, startPos: Vec2, delta: Vec2): void {
|
|
|
- // 如果操作标记为false,不处理拖动
|
|
|
- if (!this.operateFlag) return;
|
|
|
-
|
|
|
- // 清除旧的编辑数据
|
|
|
- this.editingData.brickData = brickData;
|
|
|
- this.editingData.gridList.length = 0;
|
|
|
-
|
|
|
- // 如果方块可旋转,隐藏旋转节点
|
|
|
- if (brickData.rotateFlag && brickData.rotateNode) {
|
|
|
- brickData.rotateNode.active = false;
|
|
|
- }
|
|
|
-
|
|
|
- // 恢复所有网格颜色
|
|
|
- this.gridManager.gridColorRecovery();
|
|
|
-
|
|
|
- // 移动方块到新位置
|
|
|
- if (brickData.brickNode) {
|
|
|
- brickData.brickNode.setWorldPosition(position);
|
|
|
- brickData.brickNode.scale.set(1, 1, 1);
|
|
|
- }
|
|
|
-
|
|
|
- // 检查方块每个子网格是否与游戏网格重叠
|
|
|
- const tempGridList: GridData[] = [];
|
|
|
- let allEmptyGrids: boolean = true; // 标记是否所有网格都为空
|
|
|
-
|
|
|
- if (brickData.brickNode) {
|
|
|
- brickData.brickNode.children.forEach((childNode) => {
|
|
|
- const childWorldPos = childNode.getWorldPosition();
|
|
|
-
|
|
|
- // 查找与子网格重叠的游戏网格
|
|
|
- let matchedGrid: GridData | null = null;
|
|
|
- const gridList = this.gridManager.getGridList();
|
|
|
-
|
|
|
- for (let row = 0; row < this.gridManager.getRows() && !matchedGrid; row++) {
|
|
|
- for (let col = 0; col < this.gridManager.getCols() && !matchedGrid; col++) {
|
|
|
- const grid = gridList[row][col];
|
|
|
- if (!grid || !grid.gridNode) continue;
|
|
|
-
|
|
|
- const gridPos = grid.gridNode.getWorldPosition();
|
|
|
- if (Vec3.distance(gridPos, childWorldPos) <= (this.gridManager.getItemSize() / 2)) {
|
|
|
- matchedGrid = grid;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (matchedGrid) {
|
|
|
- tempGridList.push(matchedGrid);
|
|
|
- // 检查是否有非空网格
|
|
|
- if (matchedGrid.status !== CellState.EMPTY) {
|
|
|
- allEmptyGrids = false;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // 检查是否所有子网格都有对应的游戏网格,且都是空的
|
|
|
- const canPlace = tempGridList.length === brickData.gridConfig.length && allEmptyGrids;
|
|
|
-
|
|
|
- // 更新编辑中的网格列表
|
|
|
- if (canPlace) {
|
|
|
- this.editingData.gridList = [...tempGridList];
|
|
|
- }
|
|
|
-
|
|
|
- // 更新网格颜色提示 - 显示可放置状态
|
|
|
- tempGridList.forEach(grid => {
|
|
|
- this.gridManager.updateGridHighlight(grid, canPlace);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方块拖动结束事件处理
|
|
|
- */
|
|
|
- private onBrickEndDrag(brickData: BrickData, canPlace: boolean): void {
|
|
|
- // 如果操作标记为false,不处理拖动结束
|
|
|
- if (!this.operateFlag || this.adShowingFlag) return;
|
|
|
-
|
|
|
- // 临时关闭操作标记,避免重复触发
|
|
|
- this.operateFlag = false;
|
|
|
-
|
|
|
- // 恢复所有网格颜色
|
|
|
- this.gridManager.gridColorRecovery();
|
|
|
-
|
|
|
- // 检查是否为旋转操作(点击)
|
|
|
- if (brickData.rotateFlag &&
|
|
|
- brickData.brickNode &&
|
|
|
- this.editingData.gridList.length === 0) {
|
|
|
-
|
|
|
- // 将方块添加回列表
|
|
|
- this.brickManager.setBricksList([...this.brickManager.getBricksList(), brickData]);
|
|
|
-
|
|
|
- // 恢复方块到初始位置
|
|
|
- if (brickData.brickNode) {
|
|
|
- this.brickNode.addChild(brickData.brickNode);
|
|
|
- brickData.brickNode.setWorldPosition(brickData.brickInitPos);
|
|
|
-
|
|
|
- // 显示旋转节点
|
|
|
- if (brickData.rotateNode) {
|
|
|
- brickData.rotateNode.active = true;
|
|
|
- }
|
|
|
-
|
|
|
- // 执行旋转
|
|
|
- this.brickManager.brickGridRotate(brickData).then(() => {
|
|
|
- this.operateFlag = true;
|
|
|
- });
|
|
|
-
|
|
|
- // 延迟隐藏旋转节点
|
|
|
- this.scheduleOnce(() => {
|
|
|
- if (brickData.rotateNode) {
|
|
|
- brickData.rotateNode.active = false;
|
|
|
- }
|
|
|
- }, 0.4);
|
|
|
- }
|
|
|
- }
|
|
|
- // 检查是否可以放置
|
|
|
- else if (this.editingData.gridList.length > 0) {
|
|
|
- // 处理引导模式特殊逻辑
|
|
|
- if (this.guideManager.getIsGuideMode() && this.guideManager.getGuideStep() > 0) {
|
|
|
- const targetGrids = this.editingData.gridList;
|
|
|
-
|
|
|
- // 如果格子数量不足,直接视为无效放置
|
|
|
- if (!targetGrids || targetGrids.length !== brickData.gridConfig.length) {
|
|
|
- this.handleInvalidPlacement(brickData);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 模拟砖块落下后的状态
|
|
|
- const tempGridList = this.gridManager.copyGridList();
|
|
|
- for (const grid of targetGrids) {
|
|
|
- tempGridList[grid.row][grid.col].status = CellState.FILLED;
|
|
|
- }
|
|
|
-
|
|
|
- const simulateResult = this.gridManager.gridEliminateCheck(tempGridList);
|
|
|
- const canEliminate = simulateResult.gridEliminateList.length > 0;
|
|
|
-
|
|
|
- // 在引导模式下,如果不能消除则视为无效放置
|
|
|
- if (!canEliminate) {
|
|
|
- this.handleInvalidPlacement(brickData);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 计算放置的格子数量
|
|
|
- const placedGridCount = this.editingData.gridList.length;
|
|
|
-
|
|
|
- // 获取中心位置用于显示分数
|
|
|
- let centerPos = new Vec3(0, 0, 0);
|
|
|
- if (this.editingData.gridList.length > 0 && this.editingData.gridList[0].gridNode) {
|
|
|
- centerPos = this.editingData.gridList[0].gridNode.getWorldPosition().clone();
|
|
|
-
|
|
|
- if (this.editingData.gridList.length > 1) {
|
|
|
- // 计算所有格子的平均位置作为中心点
|
|
|
- for (let i = 1; i < this.editingData.gridList.length; i++) {
|
|
|
- const gridNode = this.editingData.gridList[i].gridNode;
|
|
|
- if (gridNode) {
|
|
|
- centerPos.add(gridNode.getWorldPosition());
|
|
|
- }
|
|
|
- }
|
|
|
- const validGridCount = this.editingData.gridList.filter(grid => grid.gridNode).length;
|
|
|
- centerPos.x /= validGridCount;
|
|
|
- centerPos.y /= validGridCount;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 放置方块到网格
|
|
|
- this.editingData.gridList.forEach(grid => {
|
|
|
- grid.status = CellState.FILLED;
|
|
|
- grid.type = brickData.type;
|
|
|
- this.gridManager.generateGrid(grid);
|
|
|
- });
|
|
|
-
|
|
|
- // 显示放置得分动画
|
|
|
- this.animationManager.showScoreAnimation(
|
|
|
- centerPos,
|
|
|
- placedGridCount,
|
|
|
- this.placementBaseScore
|
|
|
- );
|
|
|
-
|
|
|
- // 标记需要重置消除计数器
|
|
|
- this.shouldResetEliminateCount = true;
|
|
|
-
|
|
|
- // 销毁方块节点
|
|
|
- if (brickData.brickNode) {
|
|
|
- brickData.brickNode.destroy();
|
|
|
- }
|
|
|
-
|
|
|
- // 添加新方块到待选区
|
|
|
- this.brickManager.addBrick(brickData.index);
|
|
|
-
|
|
|
- // 检查消除
|
|
|
- this.scheduleOnce(() => {
|
|
|
- this.gridEliminate().then((hasElimination) => {
|
|
|
- // 如果没有消除,确保下次消除会重置计数
|
|
|
- if (!hasElimination) {
|
|
|
- this.shouldResetEliminateCount = true;
|
|
|
- }
|
|
|
-
|
|
|
- this.operateFlag = true;
|
|
|
-
|
|
|
- // 处理新手引导
|
|
|
- if (this.guideManager.getIsGuideMode()) {
|
|
|
- this.scheduleOnce(() => {
|
|
|
- this.guideManager.checkNextStep();
|
|
|
- }, 0.3);
|
|
|
- } else {
|
|
|
- // 检查游戏是否结束
|
|
|
- this.prompt(false).then(canContinue => {
|
|
|
- if (!canContinue) {
|
|
|
- this.gameOver();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }, 0.1);
|
|
|
- } else {
|
|
|
- // 无法放置,将方块返回原位置
|
|
|
- this.handleInvalidPlacement(brickData);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理无效放置
|
|
|
- */
|
|
|
- private handleInvalidPlacement(brickData: BrickData): void {
|
|
|
- // 将方块添加回列表
|
|
|
- this.brickManager.setBricksList([...this.brickManager.getBricksList(), brickData]);
|
|
|
-
|
|
|
- if (brickData.brickNode) {
|
|
|
- // 添加回弹动画
|
|
|
- tween(brickData.brickNode)
|
|
|
- .to(0.2, {
|
|
|
- worldPosition: brickData.brickInitPos,
|
|
|
- scale: new Vec3(0.6, 0.6, 0.6)
|
|
|
- })
|
|
|
- .call(() => {
|
|
|
- this.operateFlag = true;
|
|
|
- if (brickData.brickNode) {
|
|
|
- this.brickNode.addChild(brickData.brickNode);
|
|
|
- brickData.brickNode.setWorldPosition(brickData.brickInitPos);
|
|
|
- }
|
|
|
- })
|
|
|
- .start();
|
|
|
- } else {
|
|
|
- this.operateFlag = true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加事件监听
|
|
|
- */
|
|
|
- private addEventListeners(): void {
|
|
|
- oops.message.on(GameEvent.RestartGame, this.restartGame, this);
|
|
|
- oops.message.on(GameEvent.DoubleSpeedOpenSuccess, this.doubleSpeedOpenSuccess, this);
|
|
|
- oops.message.on(GameEvent.openView, this.openView, this);
|
|
|
- oops.message.on(GameEvent.showCoinAnimation, this.showCoinAnimation, this);
|
|
|
- oops.message.on(GameEvent.Resurrection, this.onResurrection, this);
|
|
|
- oops.message.on(GameEvent.updateHbAndWxCoin, this.updateCoin, this);
|
|
|
- oops.message.on(GameEvent.StartAutoGame, this.startAutoGame, this);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化数据
|
|
|
- */
|
|
|
- private initData(): void {
|
|
|
- this.operateFlag = true;
|
|
|
- this.gameState = GameState.READY;
|
|
|
- this.shouldResetEliminateCount = true;
|
|
|
- this.currentCombo = 0;
|
|
|
- this.uiManager.initData();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新金币
|
|
|
- */
|
|
|
- private updateCoin(): void {
|
|
|
- this.uiManager.updateCoin();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重启游戏
|
|
|
- */
|
|
|
- private restartGame(): void {
|
|
|
- if (this.gameState === GameState.READY) return;
|
|
|
-
|
|
|
- this.initData();
|
|
|
- this.uiManager.setData();
|
|
|
- this.initGame();
|
|
|
- this.uiManager.initButtonState(this.autoPlayManager.getAutoState());
|
|
|
- this.uiManager.updateWelfarePoint();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 开始自动游戏
|
|
|
- */
|
|
|
- private startAutoGame(): void {
|
|
|
- this.btn_auto();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 显示金币动画
|
|
|
- */
|
|
|
- private showCoinAnimation(event: string, args: string): void {
|
|
|
- const lastPos = this.moveNode.getWorldPosition();
|
|
|
- const score = this.uiManager.getScore();
|
|
|
-
|
|
|
- // 显示金币动画
|
|
|
- this.animationManager.showCoinAnimation(lastPos, score, !!args);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 打开视图
|
|
|
- */
|
|
|
- private openView(event: string, args: string): void {
|
|
|
- this.uiManager.openView(args);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 复活处理
|
|
|
- */
|
|
|
- private onResurrection(): void {
|
|
|
- console.log("复活游戏,分数不清零");
|
|
|
- // 复活逻辑实现
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 二倍速开启成功
|
|
|
- */
|
|
|
- private doubleSpeedOpenSuccess(): void {
|
|
|
- if (this.gameState !== GameState.PLAYING) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (this.callback) {
|
|
|
- this.unschedule(this.callback);
|
|
|
- }
|
|
|
-
|
|
|
- this.isDoubleSpeed = true;
|
|
|
- this.animationManager.setDoubleSpeed(true, 2);
|
|
|
- this.autoPlayManager.setDoubleSpeed(true);
|
|
|
-
|
|
|
- // 设置倒计时
|
|
|
- this.doubleSpeedTime = smc.game.GameModel.doubleSpeedTime || 15;
|
|
|
-
|
|
|
- if (this.doubleSpeedTime <= 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 如果没有开启自动,则开启
|
|
|
- if (!this.autoPlayManager.getAutoState()) {
|
|
|
- this.btn_auto();
|
|
|
- }
|
|
|
-
|
|
|
- // 设置倒计时回调
|
|
|
- this.callback = () => {
|
|
|
- if (!this.adShowingFlag && this.gameState === GameState.PLAYING) {
|
|
|
- this.doubleSpeedTime--;
|
|
|
- this.uiManager.updateDoubleSpeedTime(this.doubleSpeedTime);
|
|
|
-
|
|
|
- // 时间到了
|
|
|
- if (this.doubleSpeedTime <= 0) {
|
|
|
- this.lab_doubleTime.string = "二倍速";
|
|
|
- this.isDoubleSpeed = false;
|
|
|
- this.animationManager.setDoubleSpeed(false);
|
|
|
- this.autoPlayManager.setDoubleSpeed(false);
|
|
|
-
|
|
|
- // 再打开继续二倍速页面
|
|
|
- oops.gui.open(UIID.KeepSpeed);
|
|
|
- this.unschedule(this.callback as Function);
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- this.schedule(this.callback, 1);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置游戏状态
|
|
|
- */
|
|
|
- private setGameState(state: GameState): void {
|
|
|
- this.gameState = state;
|
|
|
- switch (state) {
|
|
|
- case GameState.READY:
|
|
|
- break;
|
|
|
-
|
|
|
- case GameState.PLAYING:
|
|
|
- break;
|
|
|
-
|
|
|
- case GameState.PAUSED:
|
|
|
- break;
|
|
|
-
|
|
|
- case GameState.GAME_OVER:
|
|
|
- // 打开游戏结束界面
|
|
|
- this.autoPlayManager.setAutoState(false);
|
|
|
- this.uiManager.setAutoState(false);
|
|
|
- this.adShowingFlag = false;
|
|
|
- break;
|
|
|
-
|
|
|
- case GameState.GAME_PASS:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查是否可以继续游戏
|
|
|
- */
|
|
|
- private prompt(tipFlag = true): Promise<boolean> {
|
|
|
- // TODO: 实现提示逻辑
|
|
|
- return Promise.resolve(true);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 游戏结束处理
|
|
|
- */
|
|
|
- private gameOver(): void {
|
|
|
- this.setGameState(GameState.GAME_OVER);
|
|
|
- console.log("游戏结束");
|
|
|
- oops.gui.open(UIID.GameOver);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 消除格子
|
|
|
- */
|
|
|
- private gridEliminate(): Promise<boolean> {
|
|
|
- // TODO: 实现格子消除逻辑
|
|
|
- return Promise.resolve(false);
|
|
|
- }
|
|
|
-
|
|
|
- // =============== 按钮事件处理 ===============
|
|
|
-
|
|
|
- /**
|
|
|
- * 设置按钮点击
|
|
|
- */
|
|
|
- private btn_setting(): void {
|
|
|
- this.uiManager.onSettingBtnClick();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 提现按钮点击
|
|
|
- */
|
|
|
- private btn_withdraw(): void {
|
|
|
- this.uiManager.onWithdrawBtnClick();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 奖励按钮点击
|
|
|
- */
|
|
|
- private btn_award(): void {
|
|
|
- this.uiManager.onAwardBtnClick();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 双倍速按钮点击
|
|
|
- */
|
|
|
- private btn_double(): void {
|
|
|
- this.uiManager.onDoubleBtnClick();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 自动按钮点击
|
|
|
- */
|
|
|
- private btn_auto(): void {
|
|
|
- const newState = !this.autoPlayManager.getAutoState();
|
|
|
- this.autoPlayManager.setAutoState(newState);
|
|
|
- this.uiManager.setAutoState(newState);
|
|
|
-
|
|
|
- this.gameState = GameState.PLAYING;
|
|
|
-
|
|
|
- if (newState) {
|
|
|
- this.executeAutoPlace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 执行自动放置
|
|
|
- */
|
|
|
- private executeAutoPlace(): void {
|
|
|
- if (!this.autoPlayManager.getAutoState() || this.gameState !== GameState.PLAYING || this.adShowingFlag) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.autoPlayManager.executeAutoPlace((success) => {
|
|
|
- if (!success) {
|
|
|
- // 游戏结束
|
|
|
- this.autoPlayManager.setAutoState(false);
|
|
|
- this.uiManager.setAutoState(false);
|
|
|
- this.gameOver();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 消除检查
|
|
|
- this.gridEliminate().then(() => {
|
|
|
- this.prompt(false).then((canContinue) => {
|
|
|
- if (!canContinue) {
|
|
|
- this.gameOver();
|
|
|
- } else if (this.autoPlayManager.getAutoState()) {
|
|
|
- // 继续自动放置
|
|
|
- this.scheduleOnce(() => {
|
|
|
- this.executeAutoPlace();
|
|
|
- }, 0.4);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /** 视图对象通过 ecs.Entity.remove(eliminateViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
|
- reset() {
|
|
|
- this.node.destroy();
|
|
|
- }
|
|
|
-}
|