Commit aa1bf5e0 authored by yu's avatar yu

1

parent 7159b3e8
......@@ -37,8 +37,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
canTouch = false
completeNum = 0;
@property(cc.Node)
overN:cc.Node
resultQuesitons=[];
overN: cc.Node
resultQuesitons = [];
// resultData = {
// quesitons:[{
// duration: 107,// 用时多久
......@@ -74,7 +74,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
start(): void {
this.cardParentN.removeAllChildren();
cc.find("Canvas/uiP/bg_tip").active=false;
cc.find("Canvas/uiP/bg_tip").active = false;
super.start();
this.log('initBg:');
this.initBg();
......@@ -90,7 +90,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// this.scheduleOnce(()=>{
this.asyncPlayAudioByUrl(this.data.questionTextAudio)
// },1)
cc.find("Canvas/uiP/bg_tip").active=true;
cc.find("Canvas/uiP/bg_tip").active = true;
this.tittleLabel.string = this.data.title;
this.tipLabel.string = this.data.questionText;
this.initCards()
......@@ -122,7 +122,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
private stopBgAudio() {
cc.audioEngine.pauseMusic();
}
initGameData(){
initGameData() {
this.clickNode1 = null;
this.clickNodeData1 = null
this.canTouch = false
......@@ -141,7 +141,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.cardParentN.removeAllChildren();
let col = Math.ceil(num / 2);
let width = 1250;
console.log("getRandomCardData==========col", col,num)
console.log("getRandomCardData==========col", col, num)
if (num <= 8) width = 1050
if (col > 2) {
for (let i = 0; i < num; i++) {
......@@ -213,14 +213,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.gameTime = this.data.questions[this.questionIndex].gameTime;
let numTime = this.watchTime;
if (this.gameState == "game") numTime = this.gameTime;
console.log("numTime=======",numTime)
console.log("numTime=======", numTime)
timeN.getComponentInChildren(cc.Label).string = numTime;
timeN1.getComponentInChildren(cc.Label).string = numTime;
timeN.active = false;
timeN1.active = false;
if(numTime>5){
if (numTime > 5) {
timeN.active = true;
}else{
} else {
timeN.active = false;
}
}
......@@ -240,7 +240,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// }else{
if (this.gameState == "watching") {
if(numTime == 3)this.playLocalAudio("suc")
if (numTime == 3) this.playLocalAudio("suc")
if (numTime == 1 || numTime == 2 || numTime == 3) {
this.countDown.active = true;
this.countDown.stopAllActions();
......@@ -253,11 +253,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
})
.start()
}
}else{
} else {
if (numTime <= 1) {
if (numTime == 1) this.playLocalAudio("time1",false)
if (numTime == 1) this.playLocalAudio("time1", false)
} else {
this.playLocalAudio("time2",false)
this.playLocalAudio("time2", false)
}
}
// }
......@@ -268,6 +268,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
onStartClick() {
this.tipN.active = false;
cc.audioEngine.stopAll();
this.playLocalAudio("btn");
this.playBgAudioByUrl(this.data.bgAudio);
let children = this.cardParentN.children;
......@@ -311,14 +312,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.gameTime <= 0) {
this.clearntervals();
this.resultQuesitons.push({
duration: this.data.questions[this.questionIndex].gameTime-this.gameTime,// 用时多久
duration: this.data.questions[this.questionIndex].gameTime - this.gameTime,// 用时多久
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,// 总对数
})
if(this.questionIndex<(this.data.questions.length-1)){
if (this.questionIndex < (this.data.questions.length - 1)) {
this.nextQuestion();
}else{
} else {
this.gameOver(true)
}
}
......@@ -360,14 +361,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
console.log("allTrue===")
this.clearntervals();
this.resultQuesitons.push({
duration: this.data.questions[this.questionIndex].gameTime-this.gameTime,// 用时多久
duration: this.data.questions[this.questionIndex].gameTime - this.gameTime,// 用时多久
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,// 总对数
})
if(this.questionIndex<(this.data.questions.length-1)){
if (this.questionIndex < (this.data.questions.length - 1)) {
this.nextQuestion();
}else{
} else {
this.gameOver(true)
}
}
......@@ -401,9 +402,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
nextQuestion(){
nextQuestion() {
this.questionIndex++
this.overN.active=false;
this.overN.active = false;
this.initGameData();
this.initCards();
this.tipN.active = false;
......@@ -423,9 +424,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
clearInterval(this.gameInterval);
}
}
gameOver(isSuc){
if(isSuc){
this.questionIndex=0;
gameOver(isSuc) {
if (isSuc) {
this.questionIndex = 0;
// this.overN.active=true;
// let sucN=this.overN.getChildByName("suc")
......@@ -434,11 +435,11 @@ export default class SceneComponent extends MyCocosSceneComponent {
// failN.active=false;
// this.asyncPlayAudioByUrl("suc")
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);
return new Promise((resolve, reject) => {
// if(stopAll) cc.audioEngine.stopAll();
......@@ -449,14 +450,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
})
}
onClickRestart(){
this.resultQuesitons=[]
this.overN.active=false;
onClickRestart() {
this.resultQuesitons = []
this.overN.active = false;
this.initGameData();
this.initCards();
this.onStartClick();
}
onDestroy(){
onDestroy() {
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