Commit bf4e8a1c authored by Tt's avatar Tt

feat(游戏场景): 添加重新开始功能并优化游戏结束逻辑

parent 5c89c59b
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
// 导入工具函数 // 导入工具函数
import { asyncDelay, onHomeworkFinish, RandomInt } from "../script/util"; import { asyncDelay, onHomeworkFinish, showTrebleFirework } from "../script/util";
// 导入基础场景组件 // 导入基础场景组件
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
// 导入游戏管理类和相关枚举 // 导入游戏管理类和相关枚举
...@@ -111,6 +111,12 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -111,6 +111,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initEvent(); // 初始化事件 this.initEvent(); // 初始化事件
this.initGame(); this.initGame();
} }
restartGame() {
this.initData(); // 初始化数据
this.initView(); // 初始化视图
this.initEvent(); // 初始化事件
this.initGame();
}
/** /**
* 组件销毁时的回调 * 组件销毁时的回调
* 清理事件监听,防止内存泄漏 * 清理事件监听,防止内存泄漏
...@@ -190,6 +196,36 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -190,6 +196,36 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.activeNodes = []; this.activeNodes = [];
// 初始化触摸状态 // 初始化触摸状态
this.touching = false; this.touching = false;
// 初始化录音相关变量
this.recordStartTime = 0;
this.maxRecordDuration = 30;
// 初始化提示相关变量
this.inactiveTimer = 0;
this.hintThreshold = 3;
// 初始化音频ID
this.audioId = -1;
// 初始化语音动画定时器
this._voiceAniTimer = null;
// 初始化语音关闭状态
this.onTouchSpeakCloseClosing = false;
// 初始化重试状态
this.tryAgain = false;
this.recordTouching = false;
// 初始化重新开始布局
this.layout_restart = null;
// 重置游戏布局和页面节点到初始状态
if (this.layout_game) {
// 重置游戏布局位置到初始状态(x=0)
this.layout_game.x = 0;
}
} }
/** 音频播放ID */ /** 音频播放ID */
private audioId: any; private audioId: any;
...@@ -1230,6 +1266,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1230,6 +1266,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 设置游戏状态为结束 // 设置游戏状态为结束
Game.getIns().state = GAME_STATE.OVER; Game.getIns().state = GAME_STATE.OVER;
showTrebleFirework(cc.find('Canvas/ani'), cc.find('Canvas/RabbonBase').children);
// 准备提交的数据 // 准备提交的数据
let data: any = {}; let data: any = {};
data.total = Game.getIns().getTotal; // 总题目数 data.total = Game.getIns().getTotal; // 总题目数
...@@ -1242,6 +1280,22 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -1242,6 +1280,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 提交作业完成数据 // 提交作业完成数据
onHomeworkFinish(data) onHomeworkFinish(data)
// 显示重新开始
this.showRestart();
}
private layout_restart: cc.Node = null;
showRestart() {
if (!this.layout_restart) this.layout_restart = cc.find('Canvas/layout_restart');
this.layout_restart.active = true;
pg.view.touchOn(pg.view.find(this.layout_restart, 'btn_restart'), this.onTouchRestart, this);
}
hideRestart() {
if (!this.layout_restart) this.layout_restart = cc.find('Canvas/layout_restart');
this.layout_restart.active = false;
}
onTouchRestart() {
this.hideRestart();
this.restartGame();
} }
/** /**
......
...@@ -25,23 +25,26 @@ export const defaultData = { ...@@ -25,23 +25,26 @@ export const defaultData = {
"image": "http://staging-teach.cdn.ireadabc.com/fbe3d792ce2a72310e5298e1d75d0d71.png", "time": null, "image": "http://staging-teach.cdn.ireadabc.com/fbe3d792ce2a72310e5298e1d75d0d71.png", "time": null,
"duration": 30, "duration": 30,
"audioName": "shoot.MP3" "audioName": "shoot.MP3"
}, { },
"type": "img", // {
"audio": "http://staging-teach.cdn.ireadabc.com/a6fb6452f0e383808cd056939ed81917_l.mp3", "text": "circle", "image": "http://staging-teach.cdn.ireadabc.com/d0652838333e892b5e495fbdd8746fa0.png", // "type": "img",
"time": null, "duration": 30, // "audio": "http://staging-teach.cdn.ireadabc.com/a6fb6452f0e383808cd056939ed81917_l.mp3", "text": "circle", "image": "http://staging-teach.cdn.ireadabc.com/d0652838333e892b5e495fbdd8746fa0.png",
"audioName": "levelup.MP3" // "time": null, "duration": 30,
}, { // "audioName": "levelup.MP3"
"type": "txt", // }, {
"audio": "http://staging-teach.cdn.ireadabc.com/e8d058205a1bc894c55a9dc46d60717f_l.mp3", "text": "shoot", "image": "", // "type": "txt",
"time": null, "duration": 30, // "audio": "http://staging-teach.cdn.ireadabc.com/e8d058205a1bc894c55a9dc46d60717f_l.mp3", "text": "shoot", "image": "",
"audioName": "yasuo.mp3" // "time": null, "duration": 30,
}, { // "audioName": "yasuo.mp3"
"type": "txt", "audio": "", "text": "apple", "image": "", "time": null, "duration": 30, "audioName": "" // }, {
}, { // "type": "txt", "audio": "", "text": "apple", "image": "", "time": null, "duration": 30, "audioName": ""
"type": "txt", "audio": "", "text": "international", "image": "", "time": null, "duration": 30, "audioName": "" // }, {
}, { // "type": "txt", "audio": "", "text": "international", "image": "", "time": null, "duration": 30, "audioName": ""
"type": "txt", "audio": "", "text": "deep", "image": "", "time": null, "duration": 30, "audioName": "" // }, {
}, { // "type": "txt", "audio": "", "text": "deep", "image": "", "time": null, "duration": 30, "audioName": ""
"type": "txt", "audio": "", "text": "fun", "image": "", "time": null, "duration": 10, "audioName": "" // }, {
}] // "type": "txt", "audio": "", "text": "fun", "image": "", "time": null, "duration": 10, "audioName": ""
// }
]
} }
{
"ver": "1.1.2",
"uuid": "0114ba45-275e-4cfe-aedd-b1d276da1db2",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "2984828f-4c2b-4ba9-9656-0f3b7bc71db9",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 407,
"height": 179,
"platformSettings": {},
"subMetas": {
"btn_restart": {
"ver": "1.0.4",
"uuid": "d7580966-b781-4363-99e0-617bb3bfdd48",
"rawTextureUuid": "2984828f-4c2b-4ba9-9656-0f3b7bc71db9",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 407,
"height": 179,
"rawWidth": 407,
"rawHeight": 179,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "c6c3a776-728e-4eb2-8e07-a949381530bb",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 55,
"height": 76,
"platformSettings": {},
"subMetas": {
"cd": {
"ver": "1.0.4",
"uuid": "91a5c684-5c06-4886-9fd2-24f7acddfb75",
"rawTextureUuid": "c6c3a776-728e-4eb2-8e07-a949381530bb",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 55,
"height": 76,
"rawWidth": 55,
"rawHeight": 76,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment