Commit 43fae5e6 authored by Tt's avatar Tt

完成

parent f47733d4
...@@ -9710,6 +9710,9 @@ ...@@ -9710,6 +9710,9 @@
"page_b": { "page_b": {
"__id__": 65 "__id__": 65
}, },
"btn_close": {
"__id__": 117
},
"_id": "db3L+4L+FH/5MIRcKcfiq+" "_id": "db3L+4L+FH/5MIRcKcfiq+"
} }
] ]
\ No newline at end of file
...@@ -139,6 +139,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -139,6 +139,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
@property({ displayName: "提示手指节点", type: cc.Node }) btn_finger: cc.Node = null; @property({ displayName: "提示手指节点", type: cc.Node }) btn_finger: cc.Node = null;
@property({ displayName: "页面a", type: cc.Node }) page_a: cc.Node = null; @property({ displayName: "页面a", type: cc.Node }) page_a: cc.Node = null;
@property({ displayName: "页面b", type: cc.Node }) page_b: cc.Node = null; @property({ displayName: "页面b", type: cc.Node }) page_b: cc.Node = null;
@property({ displayName: "关闭录音界面按钮", type: cc.Node }) btn_close: cc.Node = null;
// 游戏数据相关变量 // 游戏数据相关变量
/** 当前触摸的选项数据 */ /** 当前触摸的选项数据 */
...@@ -200,6 +201,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -200,6 +201,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 音频控制按钮事件 // 音频控制按钮事件
this.btn_audio_off.on(cc.Node.EventType.TOUCH_END, this.onAudioOff, this); this.btn_audio_off.on(cc.Node.EventType.TOUCH_END, this.onAudioOff, this);
this.btn_audio_on.on(cc.Node.EventType.TOUCH_END, this.onAudioOn, this); this.btn_audio_on.on(cc.Node.EventType.TOUCH_END, this.onAudioOn, this);
this.btn_close.on(cc.Node.EventType.TOUCH_END, this.onTouchSpeakClose, this);
// 添加消防车点击事件 // 添加消防车点击事件
if (this.node_firetruck) { if (this.node_firetruck) {
...@@ -369,7 +371,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -369,7 +371,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 根据火苗编号调整消防车位置 // 根据火苗编号调整消防车位置
// fire_0~fire_2 消防车位置 x=-400,fire_3~fire_5 消防车位置 x=-185 // fire_0~fire_2 消防车位置 x=-400,fire_3~fire_5 消防车位置 x=-185
// 并根据当前页码进行偏移 // 并根据当前页码进行偏移
const baseX = (fireIndex <= 2) ? -400 : -185; const baseXList = [-400, -420, -400, -175, -215, -175]
const baseX = baseXList[fireIndex];
const targetX = baseX + 1920 * currentPage; const targetX = baseX + 1920 * currentPage;
// 移动消防车到指定位置 // 移动消防车到指定位置
...@@ -413,10 +416,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -413,10 +416,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 1. 播放node_firetruck_flush动画(喷水) // 1. 播放node_firetruck_flush动画(喷水)
this.node_firetruck_flush.active = true; this.node_firetruck_flush.active = true;
pg.view.playDBAnimation(this.node_firetruck_flush, '喷水', 1); pg.view.playDBAnimation(this.node_firetruck_flush, '喷水', 1);
await pg.time.delay(2); await pg.time.delay(1.5);
pg.view.playDBAnimation(this.node_firetruck_flush, '持续喷水', 1); pg.view.playDBAnimation(this.node_firetruck_flush, '持续喷水', 1);
await pg.time.delay(1); await pg.time.delay(1);
this.showCard(false, 'init'); this.showCard(true, 'init');
} }
onFireSuccess() { onFireSuccess() {
...@@ -573,8 +576,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -573,8 +576,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 录音动画定时器 // 录音动画定时器
private _voiceAniTimer: any = null; private _voiceAniTimer: any = null;
showCard(hide: boolean = false, recordState: string = 'init') { showCard(show: boolean = true, recordState: string = 'init') {
if (!hide) { if (show) {
// 显示卡片 // 显示卡片
const currentData = this.currentFireNode.data; const currentData = this.currentFireNode.data;
console.log('showCard', currentData) console.log('showCard', currentData)
...@@ -684,7 +687,24 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -684,7 +687,24 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.stopVoiceAni(); this.stopVoiceAni();
} }
} }
onTouchSpeakClose() {
this.showCard(false);
// 获取最后一次录音数据
const lastVoice = Game.getIns().player.getLastVoice();
// 如果有录音数据,则使用其分数
if (lastVoice && lastVoice.result) {
const score = lastVoice.result.overall;
if (score >= 10) {
this.onFireSuccess();
} else {
this.onFireFail();
}
} else {
// 如果没有录音数据,默认失败
this.onFireFail();
}
}
/** /**
* 游戏帧更新函数 * 游戏帧更新函数
...@@ -707,7 +727,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -707,7 +727,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.stopBgAudio(); this.stopBgAudio();
// 获取UI元素 // 获取UI元素
// 使用更新后的showCard方法,传入'recording'状态 // 使用更新后的showCard方法,传入'recording'状态
this.showCard(false, 'recording'); this.showCard(true, 'recording');
// 显示倒计时并设置时间 // 显示倒计时并设置时间
this.countDown = this.startCount; this.countDown = this.startCount;
this.countDown = this.touchData.time || this.startCount; //使用问题指定的时间或默认时间 this.countDown = this.touchData.time || this.startCount; //使用问题指定的时间或默认时间
...@@ -721,7 +741,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -721,7 +741,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
*/ */
private onTouchRecordEnd() { private onTouchRecordEnd() {
// 使用更新后的showCard方法,传入'recorded'状态 // 使用更新后的showCard方法,传入'recorded'状态
this.showCard(false, 'recorded'); this.showCard(true, 'recorded');
// 隐藏倒计时并设置一个很大的值防止倒计时继续 // 隐藏倒计时并设置一个很大的值防止倒计时继续
this.countDown = 999999; this.countDown = 999999;
...@@ -823,6 +843,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -823,6 +843,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
*/ */
private async recrodEnd(data) { private async recrodEnd(data) {
this.log("recrodEnd!!!!!") this.log("recrodEnd!!!!!")
// 将当前题目ID添加到录音数据中
data.questionId = this.touchData.id;
// 保存录音数据 // 保存录音数据
Game.getIns().player.addVoice(data); Game.getIns().player.addVoice(data);
...@@ -861,14 +883,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -861,14 +883,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
// 延迟后隐藏卡片和提示,进入下一题 // 延迟后隐藏卡片和提示,进入下一题
await pg.time.delay(3); await pg.time.delay(2);
this.showCard(true);
this.updateTips(null); this.updateTips(null);
if (score >= 10) {
this.onFireSuccess();
} else {
this.onFireFail();
}
return; return;
} else { } else {
// 单词不正确 // 单词不正确
...@@ -886,7 +902,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -886,7 +902,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
await pg.time.delay(3); await pg.time.delay(3);
this.showCard(true); this.showCard(false);
this.updateTips(null); this.updateTips(null);
this.recordTouching = false; this.recordTouching = false;
this.onFireFail(); this.onFireFail();
...@@ -912,10 +928,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -912,10 +928,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 根据是否需要再次尝试决定显示卡片或进入下一题 // 根据是否需要再次尝试决定显示卡片或进入下一题
if (this.tryAgain) { if (this.tryAgain) {
// 需要再次尝试,显示卡片和录音界面,重置为初始状态 // 需要再次尝试,显示卡片和录音界面,重置为初始状态
this.showCard(false, 'init') this.showCard(true, 'init')
} else { } else {
// 不需要再次尝试,隐藏卡片和录音界面 // 不需要再次尝试,隐藏卡片和录音界面
this.showCard(true) this.showCard(false)
this.recordTouching = false; this.recordTouching = false;
} }
} }
......
...@@ -86,6 +86,13 @@ class Role { ...@@ -86,6 +86,13 @@ class Role {
* @param obj 语音对象 * @param obj 语音对象
*/ */
addVoice(obj: any) { addVoice(obj: any) {
// 检查是否已存在相同题目ID的记录
const existingIndex = this.voices.findIndex(voice => voice.questionId === obj.questionId);
if (existingIndex !== -1) {
// 如果存在,先移除旧记录
this.voices.splice(existingIndex, 1);
}
// 添加新记录
this.voices.push(obj); this.voices.push(obj);
} }
getLastVoice(){ getLastVoice(){
......
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