Commit aa1bf5e0 authored by yu's avatar yu

1

parent 7159b3e8
...@@ -19,12 +19,12 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -19,12 +19,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
countDown: cc.Node = null; countDown: cc.Node = null;
@property(cc.Node) @property(cc.Node)
btn_audio_off: cc.Node = null; btn_audio_off: cc.Node = null;
@property(cc.Node) @property(cc.Node)
btn_audio_on: cc.Node = null; btn_audio_on: cc.Node = null;
private isPlayBgAudio: boolean; private isPlayBgAudio: boolean;
questionIndex = 0; questionIndex = 0;
gameState = "watching" gameState = "watching"
...@@ -37,8 +37,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -37,8 +37,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
canTouch = false canTouch = false
completeNum = 0; completeNum = 0;
@property(cc.Node) @property(cc.Node)
overN:cc.Node overN: cc.Node
resultQuesitons=[]; resultQuesitons = [];
// resultData = { // resultData = {
// quesitons:[{ // quesitons:[{
// duration: 107,// 用时多久 // duration: 107,// 用时多久
...@@ -60,8 +60,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -60,8 +60,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
addPreloadAudio() { addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源 // TODO 根据自己的配置预加载音频资源
// this._audioResList.push({ url: this.data.audio_url }); // this._audioResList.push({ url: this.data.audio_url });
this._audioResList.push({ url: this.data.bgAudio }); this._audioResList.push({ url: this.data.bgAudio });
this._audioResList.push({ url: this.data.questionTextAudio }); this._audioResList.push({ url: this.data.questionTextAudio });
} }
addPreloadAnima() { addPreloadAnima() {
...@@ -74,7 +74,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -74,7 +74,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
start(): void { start(): void {
this.cardParentN.removeAllChildren(); this.cardParentN.removeAllChildren();
cc.find("Canvas/uiP/bg_tip").active=false; cc.find("Canvas/uiP/bg_tip").active = false;
super.start(); super.start();
this.log('initBg:'); this.log('initBg:');
this.initBg(); this.initBg();
...@@ -88,41 +88,41 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -88,41 +88,41 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 所有全局变量 默认都是null // 所有全局变量 默认都是null
// //
// this.scheduleOnce(()=>{ // this.scheduleOnce(()=>{
this.asyncPlayAudioByUrl(this.data.questionTextAudio) this.asyncPlayAudioByUrl(this.data.questionTextAudio)
// },1) // },1)
cc.find("Canvas/uiP/bg_tip").active=true; cc.find("Canvas/uiP/bg_tip").active = true;
this.tittleLabel.string = this.data.title; this.tittleLabel.string = this.data.title;
this.tipLabel.string = this.data.questionText; this.tipLabel.string = this.data.questionText;
this.initCards() this.initCards()
this.initTime(); this.initTime();
if (this.data.bgAudio && this.data.bgAudio != "") { if (this.data.bgAudio && this.data.bgAudio != "") {
this.btn_audio_on.active = true; this.btn_audio_on.active = true;
} }
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);
}
private onAudioOn() {
this.btn_audio_off.active = true;
this.btn_audio_on.active = false;
this.isPlayBgAudio = false;
this.stopBgAudio();
}
private onAudioOff() {
this.btn_audio_on.active = true;
this.btn_audio_off.active = false;
this.isPlayBgAudio = true;
this.playBgAudio();
} }
private playBgAudio() {
private onAudioOn() { if (!this.isPlayBgAudio) return;
this.btn_audio_off.active = true; cc.audioEngine.resumeMusic();
this.btn_audio_on.active = false; }
this.isPlayBgAudio = false; private stopBgAudio() {
this.stopBgAudio(); cc.audioEngine.pauseMusic();
} }
private onAudioOff() { initGameData() {
this.btn_audio_on.active = true;
this.btn_audio_off.active = false;
this.isPlayBgAudio = true;
this.playBgAudio();
}
private playBgAudio() {
if (!this.isPlayBgAudio) return;
cc.audioEngine.resumeMusic();
}
private stopBgAudio() {
cc.audioEngine.pauseMusic();
}
initGameData(){
this.clickNode1 = null; this.clickNode1 = null;
this.clickNodeData1 = null this.clickNodeData1 = null
this.canTouch = false this.canTouch = false
...@@ -141,7 +141,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -141,7 +141,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.cardParentN.removeAllChildren(); this.cardParentN.removeAllChildren();
let col = Math.ceil(num / 2); let col = Math.ceil(num / 2);
let width = 1250; let width = 1250;
console.log("getRandomCardData==========col", col,num) console.log("getRandomCardData==========col", col, num)
if (num <= 8) width = 1050 if (num <= 8) width = 1050
if (col > 2) { if (col > 2) {
for (let i = 0; i < num; i++) { for (let i = 0; i < num; i++) {
...@@ -213,14 +213,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -213,14 +213,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.gameTime = this.data.questions[this.questionIndex].gameTime; this.gameTime = this.data.questions[this.questionIndex].gameTime;
let numTime = this.watchTime; let numTime = this.watchTime;
if (this.gameState == "game") numTime = this.gameTime; if (this.gameState == "game") numTime = this.gameTime;
console.log("numTime=======",numTime) console.log("numTime=======", numTime)
timeN.getComponentInChildren(cc.Label).string = numTime; timeN.getComponentInChildren(cc.Label).string = numTime;
timeN1.getComponentInChildren(cc.Label).string = numTime; timeN1.getComponentInChildren(cc.Label).string = numTime;
timeN.active = false; timeN.active = false;
timeN1.active = false; timeN1.active = false;
if(numTime>5){ if (numTime > 5) {
timeN.active = true; timeN.active = true;
}else{ } else {
timeN.active = false; timeN.active = false;
} }
} }
...@@ -237,10 +237,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -237,10 +237,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
timeN.active = false; timeN.active = false;
timeN1.active = true; timeN1.active = true;
// if(this.gameState=="game"){ // if(this.gameState=="game"){
// }else{ // }else{
if (this.gameState == "watching") { if (this.gameState == "watching") {
if(numTime == 3)this.playLocalAudio("suc") if (numTime == 3) this.playLocalAudio("suc")
if (numTime == 1 || numTime == 2 || numTime == 3) { if (numTime == 1 || numTime == 2 || numTime == 3) {
this.countDown.active = true; this.countDown.active = true;
this.countDown.stopAllActions(); this.countDown.stopAllActions();
...@@ -253,11 +253,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -253,11 +253,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
}) })
.start() .start()
} }
}else{ } else {
if (numTime <= 1) { if (numTime <= 1) {
if (numTime == 1) this.playLocalAudio("time1",false) if (numTime == 1) this.playLocalAudio("time1", false)
} else { } else {
this.playLocalAudio("time2",false) this.playLocalAudio("time2", false)
} }
} }
// } // }
...@@ -268,6 +268,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -268,6 +268,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
onStartClick() { onStartClick() {
this.tipN.active = false; this.tipN.active = false;
cc.audioEngine.stopAll();
this.playLocalAudio("btn"); this.playLocalAudio("btn");
this.playBgAudioByUrl(this.data.bgAudio); this.playBgAudioByUrl(this.data.bgAudio);
let children = this.cardParentN.children; let children = this.cardParentN.children;
...@@ -311,14 +312,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -311,14 +312,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.gameTime <= 0) { if (this.gameTime <= 0) {
this.clearntervals(); this.clearntervals();
this.resultQuesitons.push({ this.resultQuesitons.push({
duration: this.data.questions[this.questionIndex].gameTime-this.gameTime,// 用时多久 duration: this.data.questions[this.questionIndex].gameTime - this.gameTime,// 用时多久
rightPairNumber: this.completeNum, // 正确的对数 rightPairNumber: this.completeNum, // 正确的对数
wrongPairNumber: this.data.questions[this.questionIndex].options.length / 2-this.completeNum, // 错误的对数 wrongPairNumber: this.data.questions[this.questionIndex].options.length / 2 - this.completeNum, // 错误的对数
totalPairNumber: this.data.questions[this.questionIndex].options.length / 2,// 总对数 totalPairNumber: this.data.questions[this.questionIndex].options.length / 2,// 总对数
}) })
if(this.questionIndex<(this.data.questions.length-1)){ if (this.questionIndex < (this.data.questions.length - 1)) {
this.nextQuestion(); this.nextQuestion();
}else{ } else {
this.gameOver(true) this.gameOver(true)
} }
} }
...@@ -335,7 +336,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -335,7 +336,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.clickNode1.getComponent("card_duiduipeng").asyncDoFlip() this.clickNode1.getComponent("card_duiduipeng").asyncDoFlip()
this.asyncPlayAudioByUrl(this.clickNodeData1.audio); this.asyncPlayAudioByUrl(this.clickNodeData1.audio);
// this.asyncPlayAudioByUrl( this.data.questionTextAudio); // this.asyncPlayAudioByUrl( this.data.questionTextAudio);
} else { } else {
if (this.clickNode1 == node) { if (this.clickNode1 == node) {
return; return;
...@@ -360,14 +361,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -360,14 +361,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log("allTrue===") console.log("allTrue===")
this.clearntervals(); this.clearntervals();
this.resultQuesitons.push({ this.resultQuesitons.push({
duration: this.data.questions[this.questionIndex].gameTime-this.gameTime,// 用时多久 duration: this.data.questions[this.questionIndex].gameTime - this.gameTime,// 用时多久
rightPairNumber: this.completeNum, // 正确的对数 rightPairNumber: this.completeNum, // 正确的对数
wrongPairNumber: this.data.questions[this.questionIndex].options.length / 2-this.completeNum, // 错误的对数 wrongPairNumber: this.data.questions[this.questionIndex].options.length / 2 - this.completeNum, // 错误的对数
totalPairNumber: this.data.questions[this.questionIndex].options.length / 2,// 总对数 totalPairNumber: this.data.questions[this.questionIndex].options.length / 2,// 总对数
}) })
if(this.questionIndex<(this.data.questions.length-1)){ if (this.questionIndex < (this.data.questions.length - 1)) {
this.nextQuestion(); this.nextQuestion();
}else{ } else {
this.gameOver(true) this.gameOver(true)
} }
} }
...@@ -383,13 +384,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -383,13 +384,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.playLocalAudio("false") this.playLocalAudio("false")
// Promise.all([this.playLocalAudio("false")]) // Promise.all([this.playLocalAudio("false")])
// .then(() => { // .then(() => {
Promise.all([node.getComponent("card_duiduipeng").asyncDoFlip(), this.clickNode1.getComponent("card_duiduipeng").asyncDoFlip()]) Promise.all([node.getComponent("card_duiduipeng").asyncDoFlip(), this.clickNode1.getComponent("card_duiduipeng").asyncDoFlip()])
.then(() => { .then(() => {
this.canTouch = true; this.canTouch = true;
this.clickNode1 = null this.clickNode1 = null
this.clickNodeData1 = null; this.clickNodeData1 = null;
}) })
// }) // })
} }
) )
} }
...@@ -401,9 +402,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -401,9 +402,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
nextQuestion(){ nextQuestion() {
this.questionIndex++ this.questionIndex++
this.overN.active=false; this.overN.active = false;
this.initGameData(); this.initGameData();
this.initCards(); this.initCards();
this.tipN.active = false; this.tipN.active = false;
...@@ -423,22 +424,22 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -423,22 +424,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
clearInterval(this.gameInterval); clearInterval(this.gameInterval);
} }
} }
gameOver(isSuc){ gameOver(isSuc) {
if(isSuc){ if (isSuc) {
this.questionIndex=0; this.questionIndex = 0;
// this.overN.active=true; // this.overN.active=true;
// let sucN=this.overN.getChildByName("suc") // let sucN=this.overN.getChildByName("suc")
// let failN=this.overN.getChildByName("fail") // let failN=this.overN.getChildByName("fail")
// sucN.active=true; // sucN.active=true;
// failN.active=false; // failN.active=false;
// this.asyncPlayAudioByUrl("suc") // this.asyncPlayAudioByUrl("suc")
onHomeworkFinish({ onHomeworkFinish({
quesitons:this.resultQuesitons quesitons: this.resultQuesitons
}); });
} }
} }
playLocalAudio(audioName,stopAll=true) { playLocalAudio(audioName, stopAll = true) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource); const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// if(stopAll) cc.audioEngine.stopAll(); // if(stopAll) cc.audioEngine.stopAll();
...@@ -449,14 +450,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -449,14 +450,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
}) })
} }
onClickRestart(){ onClickRestart() {
this.resultQuesitons=[] this.resultQuesitons = []
this.overN.active=false; this.overN.active = false;
this.initGameData(); this.initGameData();
this.initCards(); this.initCards();
this.onStartClick(); this.onStartClick();
} }
onDestroy(){ onDestroy() {
this.clearntervals(); this.clearntervals();
} }
......
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