|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: mojunshou 1637302775@qq.com
|
|
|
* @Date: 2025-03-11 18:05:45
|
|
|
* @LastEditors: mojunshou 1637302775@qq.com
|
|
|
- * @LastEditTime: 2025-03-17 16:01:55
|
|
|
+ * @LastEditTime: 2025-03-18 10:13:28
|
|
|
* @Description:
|
|
|
*/
|
|
|
import { _decorator, Color, EventTouch, instantiate, JsonAsset, Node, Prefab, Sprite, UITransform, Vec3, Widget, tween } from "cc";
|
|
|
@@ -15,6 +15,7 @@ import { UIID } from "../../common/config/GameUIConfig";
|
|
|
import { randomRangeInt } from "cc";
|
|
|
import { Vec2 } from "cc";
|
|
|
import { log } from "console";
|
|
|
+import { Label } from "cc";
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
|
@@ -127,6 +128,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
isAutoMode: boolean = false;
|
|
|
autoModeInterval: number = 1 // 自动模式的间隔时间(秒)
|
|
|
autoModeTimer: number = 0 // 自动模式计时器
|
|
|
+ autoLb: Label | null = null;
|
|
|
|
|
|
//网格列表
|
|
|
gridsNode: Node | null = null; //中间网格区域
|
|
|
@@ -181,6 +183,10 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.moveNode = this.node.getChildByPath("Scene/MoveNode");
|
|
|
this.rotateNode = this.node.getChildByPath("Scene/rotateNode");
|
|
|
this.hammerNode = this.node.getChildByPath("Scene/hammerNode")
|
|
|
+ const autoLbNode = this.node.getChildByPath("Scene/bottom/btn_list/btn_auto/autoLb")
|
|
|
+ if (autoLbNode) {
|
|
|
+ this.autoLb = autoLbNode.getComponent(Label);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -200,78 +206,12 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.rotateFlag = false;
|
|
|
this.rotateBrickData = null;
|
|
|
this.setGameStatus(GameStatus.Start);
|
|
|
+ if (this.autoLb) {
|
|
|
+ this.autoLb.string = "自动:关"
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- // private loadBrickConfig() {
|
|
|
- // let json_name: string = "gui/eliminate/config/GridConfig";
|
|
|
- // oops.res.load(json_name, JsonAsset, (err: Error | null, res: any) => {
|
|
|
- // if (res) {
|
|
|
- // this.gameConfig = res.json;
|
|
|
- // console.log("???????????????????", this.gameConfig);
|
|
|
- // } else {
|
|
|
- // console.log("JON数据加载失,请检查文件")
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
-
|
|
|
- // //加载预制体资源
|
|
|
- // private loadPrefabsAsset() {
|
|
|
- // let loadList = [];
|
|
|
- // const loadMap = {
|
|
|
- // gridPrefab: "gui/eliminate/prefabs/Grid",
|
|
|
- // rotatePrefab: "gui/eliminate/prefabs/Rotation"
|
|
|
- // }
|
|
|
- // Object.keys(loadMap).forEach(key => {
|
|
|
- // let path = loadMap[key as keyof typeof loadMap];
|
|
|
- // const keyTyped = key as 'gridPrefab' | 'rotatePrefab';
|
|
|
- // loadList.push(
|
|
|
- // new Promise((resolve, reject) => {
|
|
|
- // oops.res.load(path, Prefab, (err: Error | null, res: any) => {
|
|
|
- // if (err) {
|
|
|
- // reject(err)
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // if (res) {
|
|
|
- // this[keyTyped] = res;
|
|
|
- // resolve(0)
|
|
|
- // }
|
|
|
- // })
|
|
|
- // })
|
|
|
- // )
|
|
|
- // })
|
|
|
-
|
|
|
- // //加载类型预制体
|
|
|
-
|
|
|
- // console.log("this.gameConfig", this.gameConfig)
|
|
|
- // const prefabUrls: string[] = []
|
|
|
- // const typeList = this.gameConfig['GridType'];
|
|
|
- // Object.keys(typeList).forEach(key => {
|
|
|
- // let path = typeList[key]['prefabUrl'];
|
|
|
- // prefabUrls.push(path);
|
|
|
-
|
|
|
- // })
|
|
|
-
|
|
|
- // prefabUrls.forEach(path => {
|
|
|
- // loadList.push(
|
|
|
- // new Promise((resolve, reject) => {
|
|
|
- // oops.res.load(path, Prefab, (err: Error | null, res: any) => {
|
|
|
- // if (err) {
|
|
|
- // reject(err)
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // if (res) {
|
|
|
- // this.prefabUrlMap[path] = res
|
|
|
- // resolve(0)
|
|
|
- // }
|
|
|
- // })
|
|
|
- // })
|
|
|
- // )
|
|
|
- // })
|
|
|
-
|
|
|
- // console.log(">>>>>>>>>>>>>>>>loadList", loadList)
|
|
|
- // }
|
|
|
-
|
|
|
//初始化网格
|
|
|
private async loadBrickConfig() {
|
|
|
let json_name: string = "gui/eliminate/config/GridConfig";
|
|
|
@@ -334,7 +274,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
});
|
|
|
})
|
|
|
});
|
|
|
- // console.log("this.prefabUrlMap", this.prefabUrlMap)
|
|
|
}
|
|
|
|
|
|
private initGrids() {
|
|
|
@@ -736,8 +675,10 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.gridColorList.push(gridData)
|
|
|
})
|
|
|
})
|
|
|
- // 触摸松开后
|
|
|
+ // 触摸松开后,这里有问题,到位置,提示格子是绿色,能放置,但是不动了,正常应该能过去并且放置到格子的
|
|
|
brickNode.on(Node.EventType.TOUCH_END, (event: EventTouch) => {
|
|
|
+ console.log("移动结束数据查看", this.editingData.gridList.length);
|
|
|
+ console.log("brickData数据查看", this.editingData.brickData);
|
|
|
// 当连击很快时,会出现1次start,2次end情况,为了避免所以通过标志位表示是一个连贯操作
|
|
|
if (!this.touchStartFlag) return
|
|
|
this.touchStartFlag = false
|
|
|
@@ -777,7 +718,7 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.editingData.brickData.brickNode.destroy();
|
|
|
}
|
|
|
// 新增方块
|
|
|
- this.addBrick(this.editingData.brickData.index)
|
|
|
+ this.addBrick(this.editingData.brickData.index);
|
|
|
this.scheduleOnce(() => {
|
|
|
// 格子消除
|
|
|
this.gridEliminate().then(() => {
|
|
|
@@ -838,10 +779,8 @@ export class EliminateViewComp extends CCComp {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 提示
|
|
|
prompt(tipFlag = true) {
|
|
|
- console.log("点击了提示按钮")
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const gridPromptList: GridData[] = []
|
|
|
let moveFlag = false
|
|
|
@@ -1216,18 +1155,15 @@ export class EliminateViewComp extends CCComp {
|
|
|
// 先禁用所有操作
|
|
|
this.isAutoMode = false
|
|
|
this.editingFlag = true // 防止操作
|
|
|
-
|
|
|
// 执行格子变灰动画
|
|
|
await this.playGameOverGridAnimation()
|
|
|
-
|
|
|
// 播放游戏结束音效
|
|
|
// this.audioManager.playGameOver()
|
|
|
-
|
|
|
// 设置游戏状态
|
|
|
this.setGameStatus(GameStatus.Over)
|
|
|
-
|
|
|
// 恢复操作标志
|
|
|
this.editingFlag = false
|
|
|
+ oops.gui.open(UIID.GameOver);
|
|
|
}
|
|
|
|
|
|
private async playGameOverGridAnimation(): Promise<void> {
|
|
|
@@ -1359,13 +1295,10 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.gameOver();
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
// 获取选中的方块
|
|
|
const brickData = this.bricksList[selectedBrickIndex];
|
|
|
-
|
|
|
// 从列表中移除方块
|
|
|
this.bricksList.splice(selectedBrickIndex, 1);
|
|
|
-
|
|
|
// 保存方块的初始位置(从待选区开始)
|
|
|
const startPos = brickData.brickInitPos.clone();
|
|
|
|
|
|
@@ -1438,18 +1371,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
})
|
|
|
.start();
|
|
|
}
|
|
|
-
|
|
|
- // 引导节点跟着移动
|
|
|
- // if (this.guildNode) {
|
|
|
- // tween(this.guideNode)
|
|
|
- // .to(0.3, {
|
|
|
- // worldPosition: targetWorldPos
|
|
|
- // })
|
|
|
- // .call(() => {
|
|
|
- // this.guideNode.active = false;
|
|
|
- // })
|
|
|
- // .start();
|
|
|
- // }
|
|
|
});
|
|
|
|
|
|
// 检查并执行消除
|
|
|
@@ -1463,7 +1384,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if (!hasValidMove) {
|
|
|
console.log('没有方块可以放置,游戏结束');
|
|
|
this.isAutoMode = false;
|
|
|
@@ -1585,35 +1505,9 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //=================自动模式逻辑=================
|
|
|
|
|
|
-
|
|
|
- // ... 添加自动模式的开关方法
|
|
|
- onAutoButtonClick() {
|
|
|
- if (
|
|
|
- this.game_status !== GameStatus.Start ||
|
|
|
- this.editingFlag
|
|
|
- ) return
|
|
|
-
|
|
|
- // 切换自动模式状态
|
|
|
- this.isAutoMode = !this.isAutoMode
|
|
|
-
|
|
|
-
|
|
|
- if (this.isAutoMode) {
|
|
|
-
|
|
|
- this._isAutoFunc = () => {
|
|
|
- this.autoPlaceBrick()
|
|
|
- }
|
|
|
- this.schedule(this._isAutoFunc, this.autoModeInterval)
|
|
|
- console.log('开启自动模式')
|
|
|
- } else {
|
|
|
- if (this._isAutoFunc) {
|
|
|
- this.unschedule(this._isAutoFunc)
|
|
|
- this._isAutoFunc = null
|
|
|
- }
|
|
|
- console.log('关闭自动模式')
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ //自动模式
|
|
|
private btn_auto() {
|
|
|
// if (
|
|
|
// this.game_status !== GameStatus.Start ||
|
|
|
@@ -1630,13 +1524,17 @@ export class EliminateViewComp extends CCComp {
|
|
|
this.autoPlaceBrick()
|
|
|
}
|
|
|
this.schedule(this._isAutoFunc, this.autoModeInterval)
|
|
|
- console.log('开启自动模式')
|
|
|
+ if (this.autoLb) {
|
|
|
+ this.autoLb.string = "自动:开"
|
|
|
+ }
|
|
|
} else {
|
|
|
if (this._isAutoFunc) {
|
|
|
this.unschedule(this._isAutoFunc)
|
|
|
this._isAutoFunc = null
|
|
|
}
|
|
|
- console.log('关闭自动模式')
|
|
|
+ if (this.autoLb) {
|
|
|
+ this.autoLb.string = "自动:关"
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -1707,14 +1605,14 @@ export class EliminateViewComp extends CCComp {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //======================拓展功能==锤子玩法==
|
|
|
+ //======================拓展功能==锤子玩法==========
|
|
|
private btn_hammer(): void {
|
|
|
if (
|
|
|
this.game_status !== GameStatus.Start ||
|
|
|
this.editingFlag ||
|
|
|
this.isAutoMode
|
|
|
- ) return
|
|
|
+ )
|
|
|
+ return
|
|
|
|
|
|
// 随机选择一片区域的方块进行清除
|
|
|
this.performRandomHammerSmash();
|
|
|
@@ -1726,7 +1624,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
console.warn('锤子节点未找到');
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
// 默认隐藏锤子节点
|
|
|
this.hammerNode.active = false;
|
|
|
}
|
|
|
@@ -1735,7 +1632,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
private performRandomHammerSmash(): void {
|
|
|
// 收集所有已放置的方块
|
|
|
const placedBlocks: GridData[] = [];
|
|
|
-
|
|
|
for (let row = 0; row < this.max_row; row++) {
|
|
|
for (let col = 0; col < this.max_col; col++) {
|
|
|
const gridData = this.gridList[row][col];
|
|
|
@@ -1759,10 +1655,8 @@ export class EliminateViewComp extends CCComp {
|
|
|
|
|
|
// 获取中心方块的位置
|
|
|
const centerPosition = centerBlock.gridNode.getWorldPosition();
|
|
|
-
|
|
|
// 要清除的方块列表
|
|
|
const blocksToSmash: GridData[] = [];
|
|
|
-
|
|
|
// 首先添加中心块
|
|
|
blocksToSmash.push(centerBlock);
|
|
|
|
|
|
@@ -1782,10 +1676,8 @@ export class EliminateViewComp extends CCComp {
|
|
|
for (let col = Math.max(0, centerBlock.column - MAX_DISTANCE);
|
|
|
col <= Math.min(this.max_col - 1, centerBlock.column + MAX_DISTANCE);
|
|
|
col++) {
|
|
|
-
|
|
|
// 跳过中心块自身
|
|
|
if (row === centerBlock.row && col === centerBlock.column) continue;
|
|
|
-
|
|
|
const currentBlock = this.gridList[row][col];
|
|
|
|
|
|
// 只考虑已放置的方块
|
|
|
@@ -1807,18 +1699,16 @@ export class EliminateViewComp extends CCComp {
|
|
|
// 随机选择周围的方块,但保持锤子范围内的聚集效果
|
|
|
for (let i = 0; i < extraBlocksToSelect; i++) {
|
|
|
if (nearbyBlocks.length === 0) break;
|
|
|
-
|
|
|
// 随机选择一个附近的方块
|
|
|
const selectedIndex = randomRangeInt(0, nearbyBlocks.length);
|
|
|
blocksToSmash.push(nearbyBlocks[selectedIndex]);
|
|
|
-
|
|
|
// 从列表中移除已选方块,避免重复选择
|
|
|
nearbyBlocks.splice(selectedIndex, 1);
|
|
|
}
|
|
|
|
|
|
// 如果没有足够的方块可清除,直接返回
|
|
|
if (blocksToSmash.length < 2) {
|
|
|
- console.log('附近没有足够的方块可清除');
|
|
|
+ oops.gui.toast('附近没有足够的方块可清除')
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -1828,7 +1718,6 @@ export class EliminateViewComp extends CCComp {
|
|
|
const hammerPosition = centerPosition.clone();
|
|
|
hammerPosition.y += 50; // 设置在方块上方一定距离
|
|
|
this.hammerNode.setWorldPosition(hammerPosition);
|
|
|
-
|
|
|
// 播放锤子敲击动画,并清除选择的方块
|
|
|
this.playHammerSmashAnimation(blocksToSmash);
|
|
|
}
|
|
|
@@ -1882,4 +1771,8 @@ export class EliminateViewComp extends CCComp {
|
|
|
.start();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //点击进入提现页面
|
|
|
+
|
|
|
+
|
|
|
}
|