Commit aa1bf5e0 authored by yu's avatar yu

1

parent 7159b3e8
...@@ -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,// 用时多久
...@@ -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();
...@@ -90,7 +90,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -90,7 +90,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 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()
...@@ -122,7 +122,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -122,7 +122,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
private stopBgAudio() { private stopBgAudio() {
cc.audioEngine.pauseMusic(); cc.audioEngine.pauseMusic();
} }
initGameData(){ 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;
} }
} }
...@@ -240,7 +240,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -240,7 +240,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// }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)
} }
} }
...@@ -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)
} }
} }
...@@ -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,9 +424,9 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -423,9 +424,9 @@ 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")
...@@ -434,11 +435,11 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -434,11 +435,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 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