Commit 62503a19 authored by 李维's avatar 李维

feat: 修改规则

1.中文选择界面改成英文;
2.每个出现随机几个正确的个数,不是完全一样都是2个;
3.上一个题目音频播放完了再开始下一题,而不是孩子点对了直接就消失掉音频没读完就直接切换下一题了
parent 51ee4291
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
"e2e": "ng e2e" "e2e": "ng e2e"
}, },
"private": true, "private": true,
"browser": {
"querystring": "querystring-es3"
},
"dependencies": { "dependencies": {
"@angular/animations": "~9.0.2", "@angular/animations": "~9.0.2",
"@angular/common": "~9.0.2", "@angular/common": "~9.0.2",
...@@ -52,6 +55,7 @@ ...@@ -52,6 +55,7 @@
"karma-jasmine": "~2.0.1", "karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2", "karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3", "protractor": "~5.4.3",
"querystring-es3": "^0.2.1",
"ts-node": "~8.3.0", "ts-node": "~8.3.0",
"tslint": "~5.18.0", "tslint": "~5.18.0",
"typescript": "~3.7.5" "typescript": "~3.7.5"
......
...@@ -85,6 +85,9 @@ export class Stage { ...@@ -85,6 +85,9 @@ export class Stage {
/** 随机问题列表 */ /** 随机问题列表 */
questionRandomList: Question[]; questionRandomList: Question[];
/** 本关需要点击的正确鱼数量 */
correctFishCount: number;
/** /**
* 构造函数 * 构造函数
* @param correctQuestion 正确的问题 * @param correctQuestion 正确的问题
...@@ -99,47 +102,44 @@ export class Stage { ...@@ -99,47 +102,44 @@ export class Stage {
} }
/** /**
* 将问题列表打乱并放置到随机问题列表中 * 生成本关出鱼列表
* 1. 从数组中移除正确的答案 * 1. 筛出错误选项池(除当前正确卡以外的所有选中卡片)
* 2. 将打乱的数组的长度限制为不超过4 * 2. 正确鱼、错误鱼各随机 1-5 次
* 3. 将正确的答案添加两次到列表中 * 3. 洗牌决定从屏幕右侧进入的顺序
* 4. 使用深拷贝处理数据
*/ */
randomList(): void { randomList(): void {
// 使用深拷贝复制问题列表,避免直接修改原数组 const wrongOptions = this.questionList
const tempList = JSON.parse(JSON.stringify(this.questionList)); .filter(q =>
!(q.audio === this.correctQuestion.audio &&
q.image === this.correctQuestion.image)
)
.map(q => JSON.parse(JSON.stringify(q)));
if (wrongOptions.length === 0) {
this.correctFishCount = 1;
this.questionRandomList = [JSON.parse(JSON.stringify(this.correctQuestion))];
return;
}
// 从列表中移除正确答案 this.correctFishCount = Math.floor(Math.random() * 5) + 1;
const correctQuestionIndex = tempList.findIndex(q => const wrongFishCount = Math.floor(Math.random() * 5) + 1;
q.audio === this.correctQuestion.audio &&
q.image === this.correctQuestion.image);
if (correctQuestionIndex !== -1) { const spawnList: Question[] = [];
tempList.splice(correctQuestionIndex, 1);
}
// 使用Fisher-Yates洗牌算法打乱数组 for (let i = 0; i < this.correctFishCount; i++) {
for (let i = tempList.length - 1; i > 0; i--) { spawnList.push(JSON.parse(JSON.stringify(this.correctQuestion)));
const j = Math.floor(Math.random() * (i + 1));
[tempList[i], tempList[j]] = [tempList[j], tempList[i]];
} }
// 限制打乱后的数组长度不超过4(不包括正确答案) for (let i = 0; i < wrongFishCount; i++) {
const maxLength = 4; const randomWrong = wrongOptions[Math.floor(Math.random() * wrongOptions.length)];
const limitedList = tempList.slice(0, maxLength); spawnList.push(JSON.parse(JSON.stringify(randomWrong)));
}
// 将正确答案添加两次到列表中
const correctQuestionCopy = JSON.parse(JSON.stringify(this.correctQuestion));
limitedList.push(correctQuestionCopy);
limitedList.push(JSON.parse(JSON.stringify(this.correctQuestion)));
// 再次打乱数组,确保正确答案的位置随机 for (let i = spawnList.length - 1; i > 0; i--) {
for (let i = limitedList.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1)); const j = Math.floor(Math.random() * (i + 1));
[limitedList[i], limitedList[j]] = [limitedList[j], limitedList[i]]; [spawnList[i], spawnList[j]] = [spawnList[j], spawnList[i]];
} }
// 将最终打乱后的列表赋值给随机问题列表 this.questionRandomList = spawnList;
this.questionRandomList = limitedList;
} }
} }
...@@ -50,32 +50,46 @@ import { FormData, Position, PositionMap, Stage, Question } from './interfaces'; ...@@ -50,32 +50,46 @@ import { FormData, Position, PositionMap, Stage, Question } from './interfaces';
let defaultFormData: FormData = { let defaultFormData: FormData = {
"score": 0, "score": 0,
"title": "", "title": "",
"doubleModal": false, "questionText": "",
"questionText": "", "questionType": "read", "questionTextAudio": "", "questionType": "read",
"questionTextAudio": "",
"bgAudio": "", "bgAudio": "",
imgSize: 'big', "doubleModal": false,
"imgSize": "small",
"questions": [ "questions": [
{ {
"type": "txt", "audio": "https://staging-teach.cdn.ireadabc.com/a050401ba53e74ede17b5c49635a977a.mp3", "text": "", "image": "http://staging-teach.cdn.ireadabc.com/bde25b1b2a7fdf976f17ae80b6a20a25.png", "time": null, "duration": "", "audioName": "", "imgSize": "big" "type": "img",
}, { "audio": "https://teach.cdn.ireadabc.com/8a3a2b3d01a519d0f5d4a1ec7d7b1d34.mp3",
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/89060c9eddd5f0f67908cce77ee74f94.mp3", "image": "http://staging-teach.cdn.ireadabc.com/761e1b17e16fa4674db9ad5344676bb9.png", "time": null, "audioName": "" "image": "http://cdn.iteachabc.com/9ce889a401d86e760359710dd9105503.png",
}, { "time": null,
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/0d11dcd7138f61dbead3dfaa5eb84b47.mp3", "image": "http://staging-teach.cdn.ireadabc.com/f7a3455a80e34c8f0fe9a190381181f4.png", "time": null, "audioName": "" "audioName": "",
}, { "imgSize": "small"
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3", "image": "http://staging-teach.cdn.ireadabc.com/7b470ba3fcee2d4a97bf2ffdf5796109.png", "time": null, "audioName": "" },
}, { {
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/0d11dcd7138f61dbead3dfaa5eb84b47.mp3", "image": "http://staging-teach.cdn.ireadabc.com/1438d4609714ad1968f546db51067c9c.png", "time": null, "audioName": "" "type": "img",
}, { "audio": "http://cdn.iteachabc.com/0b46681cc8f65af07518981741894f7e.mp3",
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3", "image": "http://staging-teach.cdn.ireadabc.com/f372eace088da338fa10f65415890c70.png", "time": null, "audioName": "" "image": "http://cdn.iteachabc.com/3ead52aa08b8390112bac7eac2792bdc.png",
}, { "time": null,
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/78ba347c18b181fd4550d30bb14c90c5.mp3", "image": "http://staging-teach.cdn.ireadabc.com/63a00af0b7a1d4ad38bbfd7a6363348d.png", "time": null, "audioName": "" "audioName": "",
}, { "imgSize": "small"
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ffdb9f038d5549c9deba6d3f92371e61.mp3", "image": "http://staging-teach.cdn.ireadabc.com/ee85bdb5170fd9e54e174a7b003b9634.png", "time": null, "audioName": "" },
}, { {
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/ed1a2dc4bfa7d35041ca94d1badde8ed.mp3", "image": "http://staging-teach.cdn.ireadabc.com/2c94dad69f2f031bf910673c0a775651.png", "time": null, "audioName": "" "type": "img",
}, { "audio": "http://cdn.iteachabc.com/b26454dd32abd9d55a906047bd080043.mp3",
"type": "img", "imgSize": "big", "audio": "http://staging-teach.cdn.ireadabc.com/5af2246994a28e28e155e71bb8175b85.mp3", "image": "http://staging-teach.cdn.ireadabc.com/5ae211fddfdede20852c41c07f69b2a1.png", "time": null, "audioName": "" "image": "http://cdn.iteachabc.com/1d41baee911159d3e07c8eb13208cb8e.png",
}] "time": null,
"audioName": "",
"imgSize": "small"
},
{
"type": "img",
"audio": "http://cdn.iteachabc.com/ae260ec3a18031298a823e88e8d8a2c4.mp3",
"image": "http://cdn.iteachabc.com/9eb977e67c9a17039f9c7fca51b8e8d6.png",
"time": null,
"audioName": "",
"imgSize": "small"
}
]
} }
...@@ -150,7 +164,9 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -150,7 +164,9 @@ export class PlayComponent implements OnInit, OnDestroy {
m_gameOver = false; // 游戏结束标志 m_gameOver = false; // 游戏结束标志
selectList = []; // 选中的项目列表 selectList = []; // 选中的项目列表
checkBtnElement = null; // 检查按钮元素引用 checkBtnElement = null; // 检查按钮元素引用
checkBtnLabel = null; // 检查按钮文字引用
gameStages: Stage[] = []; // 游戏阶段数组,存储所有创建的Stage对象 gameStages: Stage[] = []; // 游戏阶段数组,存储所有创建的Stage对象
private isWaitingQuestionAudio = false; // 等待题目音频播放完成时暂停出鱼
// ------------------------------------ // ------------------------------------
...@@ -458,7 +474,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -458,7 +474,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 创建标题文字元素 // 创建标题文字元素
const titleTextElement = this.g_cartoon.createCartoonElement('page_title_text', 'Label'); const titleTextElement = this.g_cartoon.createCartoonElement('page_title_text', 'Label');
// 设置文字内容 // 设置文字内容
titleTextElement.ref.text = '请选择本次的练习目标'; titleTextElement.ref.text = 'Select the pictures';
// 设置字体大小 // 设置字体大小
titleTextElement.ref.fontSize = 32 * this.g_mapScale; titleTextElement.ref.fontSize = 32 * this.g_mapScale;
// 设置字体颜色为深色 // 设置字体颜色为深色
...@@ -655,15 +671,21 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -655,15 +671,21 @@ export class PlayComponent implements OnInit, OnDestroy {
initCheckBtn() { initCheckBtn() {
// 创建按钮元素 // 创建按钮元素
const checkBtnElement = this.g_cartoon.createCartoonElement('check_btn', 'MySprite'); const checkBtnElement = this.g_cartoon.createCartoonElement('check_btn', 'MySprite');
const checkBtnLabel = this.g_cartoon.createCartoonElement('check_btn_label', 'Label');
checkBtnLabel.ref.fontSize = 22 * this.g_mapScale;
checkBtnLabel.ref.fontColor = '#FFFFFF';
checkBtnLabel.ref.textAlign = 'center';
checkBtnLabel.ref.x = 0;
checkBtnLabel.ref.y = -2 * this.g_mapScale;
// 根据selectList长度决定显示的按钮图片和文字 // 根据selectList长度决定显示的按钮图片和文字
const updateButtonState = () => { const updateButtonState = () => {
if (this.selectList.length >= 2) { if (this.selectList.length >= 2) {
// 显示"开始游戏"按钮
checkBtnElement.ref.init(this.g_cartoon.images.get('kai_shi')); checkBtnElement.ref.init(this.g_cartoon.images.get('kai_shi'));
checkBtnLabel.ref.text = 'Start';
} else { } else {
// 显示"选择单词"按钮
checkBtnElement.ref.init(this.g_cartoon.images.get('xuan_ze')); checkBtnElement.ref.init(this.g_cartoon.images.get('xuan_ze'));
checkBtnLabel.ref.text = 'Please select';
} }
}; };
...@@ -673,6 +695,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -673,6 +695,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// 设置按钮缩放 // 设置按钮缩放
checkBtnElement.ref.scaleX = this.g_mapScale; checkBtnElement.ref.scaleX = this.g_mapScale;
checkBtnElement.ref.scaleY = this.g_mapScale; checkBtnElement.ref.scaleY = this.g_mapScale;
checkBtnElement.ref.addChild(checkBtnLabel.ref);
// 设置按钮位置 - 屏幕右下角 // 设置按钮位置 - 屏幕右下角
// kai_shi和xuan_ze的尺寸都是209x65 // kai_shi和xuan_ze的尺寸都是209x65
...@@ -696,14 +719,13 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -696,14 +719,13 @@ export class PlayComponent implements OnInit, OnDestroy {
this.listItem.ref.visible = false; this.listItem.ref.visible = false;
this.initBattle(); this.initBattle();
} else { } else {
// 提示需要选择更多单词 console.log('Please select at least 2 words');
console.log('请至少选择2个单词');
// 这里可以添加提示逻辑
} }
}) })
// 保存按钮引用,用于状态更新 // 保存按钮引用,用于状态更新
this.checkBtnElement = checkBtnElement; this.checkBtnElement = checkBtnElement;
this.checkBtnLabel = checkBtnLabel;
// 渲染按钮 // 渲染按钮
this.render(checkBtnElement.ref, zIndexMap.card + 2); this.render(checkBtnElement.ref, zIndexMap.card + 2);
...@@ -746,11 +768,15 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -746,11 +768,15 @@ export class PlayComponent implements OnInit, OnDestroy {
updateCheckBtn() { updateCheckBtn() {
if (this.checkBtnElement) { if (this.checkBtnElement) {
if (this.selectList.length >= 2) { if (this.selectList.length >= 2) {
// 显示"开始游戏"按钮
this.checkBtnElement.ref.init(this.g_cartoon.images.get('kai_shi')); this.checkBtnElement.ref.init(this.g_cartoon.images.get('kai_shi'));
if (this.checkBtnLabel) {
this.checkBtnLabel.ref.text = 'Start';
}
} else { } else {
// 显示"选择单词"按钮
this.checkBtnElement.ref.init(this.g_cartoon.images.get('xuan_ze')); this.checkBtnElement.ref.init(this.g_cartoon.images.get('xuan_ze'));
if (this.checkBtnLabel) {
this.checkBtnLabel.ref.text = 'Please select';
}
} }
} }
} }
...@@ -810,26 +836,59 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -810,26 +836,59 @@ export class PlayComponent implements OnInit, OnDestroy {
data.image === currentStage.correctQuestion.image data.image === currentStage.correctQuestion.image
).length; ).length;
console.log('Correct clicks:', correctClicks); console.log('Correct clicks:', correctClicks, 'Required:', currentStage.correctFishCount);
// 如果有两个数据为当前Stage的正确数据,则清空画面,等待1秒后进入下一轮游戏 if (correctClicks >= currentStage.correctFishCount) {
if (correctClicks >= 2) {
console.log('Stage completed! Moving to next stage...'); console.log('Stage completed! Moving to next stage...');
// 清空画面(清除所有鱼)
this.clearFishes(); this.clearFishes();
// 增加当前阶段索引
this.currentStageIndex++; this.currentStageIndex++;
// 等待1秒后进入下一轮游戏 const audioKey = currentStage.correctQuestion && currentStage.correctQuestion.audio;
setTimeout(() => { const proceedToNextQuestion = () => this.startNextQuestion();
this.startNextQuestion(); if (audioKey) {
}, 1000); if (this.isQuestionAudioPlaying(audioKey)) {
this.isWaitingQuestionAudio = true;
this.questionWaitList = [];
}
this.waitForQuestionAudioEnd(audioKey, proceedToNextQuestion);
} else {
proceedToNextQuestion();
}
} }
} }
} }
/**
* 等待题目音频播放完毕后再执行回调
*/
waitForQuestionAudioEnd(audioKey: string, callback: () => void) {
const finish = () => {
this.isWaitingQuestionAudio = false;
callback();
};
const audio = this.g_cartoon.audio.get(audioKey);
if (!audio || audio.ended || audio.paused || audio.currentTime === 0) {
finish();
return;
}
const onEnd = () => {
audio.removeEventListener('ended', onEnd);
finish();
};
audio.addEventListener('ended', onEnd);
}
/**
* 判断题目音频是否正在播放
*/
isQuestionAudioPlaying(audioKey: string): boolean {
const audio = this.g_cartoon.audio.get(audioKey);
return !!(audio && !audio.paused && !audio.ended && audio.currentTime > 0);
}
//--------------------------------------------------------------钓鱼-初始化--------------------------------------------------------- //--------------------------------------------------------------钓鱼-初始化---------------------------------------------------------
...@@ -949,9 +1008,10 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -949,9 +1008,10 @@ export class PlayComponent implements OnInit, OnDestroy {
* 初始化下一个游戏阶段 * 初始化下一个游戏阶段
* 1. 将当前Stage中的数组随机一次 * 1. 将当前Stage中的数组随机一次
* 2. 后续出鱼按照随机后的数组出现 * 2. 后续出鱼按照随机后的数组出现
* 3. 用户点击鱼后存储对应数据,如果数据中有两个数据为当前Stage的正确数据则清空画面,等待1秒后进行下一轮游戏 * 3. 用户点击鱼后存储对应数据,正确点击数达到本关随机目标后等待音频播完再进入下一轮
*/ */
startNextQuestion() { startNextQuestion() {
this.isWaitingQuestionAudio = false;
// 清空之前点击的鱼的数据 // 清空之前点击的鱼的数据
this.clickedFishData = []; this.clickedFishData = [];
...@@ -1061,9 +1121,12 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -1061,9 +1121,12 @@ export class PlayComponent implements OnInit, OnDestroy {
const currentStage = this.gameStages[this.currentStageIndex]; const currentStage = this.gameStages[this.currentStageIndex];
if (currentStage && currentStage.correctQuestion && currentStage.correctQuestion.audio) { if (currentStage && currentStage.correctQuestion && currentStage.correctQuestion.audio) {
// 播放当前正确问题的音频 const audioKey = currentStage.correctQuestion.audio;
// 题目音频播放中时不重复打断重播
if (!this.isQuestionAudioPlaying(audioKey)) {
this.g_cartoon.stopAllAudio(); this.g_cartoon.stopAllAudio();
this.g_cartoon.playAudio(currentStage.correctQuestion.audio, true); this.g_cartoon.playAudio(audioKey, true);
}
} }
// 注销该鱼的点击事件 // 注销该鱼的点击事件
this.unsubscribeFishEvent(fish.fishId); this.unsubscribeFishEvent(fish.fishId);
...@@ -2952,6 +3015,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -2952,6 +3015,7 @@ export class PlayComponent implements OnInit, OnDestroy {
return; return;
} }
if (!this.isGameStart) return; if (!this.isGameStart) return;
if (this.isWaitingQuestionAudio) return;
// 获取当前游戏阶段 // 获取当前游戏阶段
const currentStage = this.gameStages[this.currentStageIndex]; const currentStage = this.gameStages[this.currentStageIndex];
......
src/assets/game/page/kai_shi.png

7.22 KB | W: | H:

src/assets/game/page/kai_shi.png

1.29 KB | W: | H:

src/assets/game/page/kai_shi.png
src/assets/game/page/kai_shi.png
src/assets/game/page/kai_shi.png
src/assets/game/page/kai_shi.png
  • 2-up
  • Swipe
  • Onion skin
src/assets/game/page/xuan_ze.png

6.61 KB | W: | H:

src/assets/game/page/xuan_ze.png

1.35 KB | W: | H:

src/assets/game/page/xuan_ze.png
src/assets/game/page/xuan_ze.png
src/assets/game/page/xuan_ze.png
src/assets/game/page/xuan_ze.png
  • 2-up
  • Swipe
  • Onion skin
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