Commit ef269320 authored by 章红平's avatar 章红平

提交

parent a96c0c79
This diff is collapsed.
...@@ -29,6 +29,15 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -29,6 +29,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
completeNum = 0; completeNum = 0;
@property(cc.Node) @property(cc.Node)
overN:cc.Node overN:cc.Node
resultQuesitons=[];
// resultData = {
// quesitons:[{
// duration: 107,// 用时多久
// rightPairNumber: 5, // 正确的对数
// wrongPairNumber: 3, // 错误的对数
// totalPairNumber: 6,// 总对数
// }]
// }
...@@ -66,6 +75,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -66,6 +75,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
initData() { initData() {
this.log('initData:'); this.log('initData:');
// 所有全局变量 默认都是null // 所有全局变量 默认都是null
//
// this.scheduleOnce(()=>{
this.playAudioByUrl(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.tittleLabel.string = this.data.title;
this.tipLabel.string = this.data.questionText; this.tipLabel.string = this.data.questionText;
...@@ -189,13 +202,10 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -189,13 +202,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"){
if (numTime <= 1) {
if (numTime == 1) this.playLocalAudio("time1")
} else {
this.playLocalAudio("time2")
}
// }else{ // }else{
if (this.gameState == "watching") { if (this.gameState == "watching") {
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();
...@@ -208,6 +218,12 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -208,6 +218,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
}) })
.start() .start()
} }
}else{
if (numTime <= 1) {
if (numTime == 1) this.playLocalAudio("time1")
} else {
this.playLocalAudio("time2")
}
} }
// } // }
...@@ -257,8 +273,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -257,8 +273,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.gameTime--; this.gameTime--;
console.log("gametime=====", this.gameTime) console.log("gametime=====", this.gameTime)
if (this.gameTime <= 0) { if (this.gameTime <= 0) {
this.gameOver(false);
this.clearntervals(); this.clearntervals();
this.resultQuesitons.push({
duration: this.data.questions[this.questionIndex].gameTime-this.gameTime,// 用时多久
rightPairNumber: 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)){
this.nextQuestion();
}else{
this.gameOver(true)
}
} }
this.updateTime(); this.updateTime();
...@@ -271,16 +297,18 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -271,16 +297,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.clickNode1 = node; this.clickNode1 = node;
this.clickNodeData1 = data; this.clickNodeData1 = data;
this.clickNode1.getComponent("card").asyncDoFlip() this.clickNode1.getComponent("card").asyncDoFlip()
this.playAudioByUrl(this.clickNodeData1.audio); this.asyncPlayAudioByUrl(this.clickNodeData1.audio);
// this.asyncPlayAudioByUrl( this.data.questionTextAudio);
} else { } else {
if (this.clickNode1 == node) { if (this.clickNode1 == node) {
return; return;
// this.playAudioByUrl( this.clickNodeData1.audio); // this.asyncPlayAudioByUrl( this.clickNodeData1.audio);
} else { } else {
this.canTouch = false this.canTouch = false
if (this.clickNodeData1.pairIdx == data.pairIdx) { if (this.clickNodeData1.pairIdx == data.pairIdx) {
Promise Promise
.all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl(data.audio)]) .all([node.getComponent("card").asyncDoFlip(), this.asyncPlayAudioByUrl(data.audio)])
.then(() => { .then(() => {
Promise.all([node.getComponent("card").playDragon(), this.clickNode1.getComponent("card").playDragon(), this.playLocalAudio("true")]) Promise.all([node.getComponent("card").playDragon(), this.clickNode1.getComponent("card").playDragon(), this.playLocalAudio("true")])
.then(() => { .then(() => {
...@@ -293,18 +321,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -293,18 +321,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.completeNum == this.data.questions[this.questionIndex].options.length / 2) { if (this.completeNum == this.data.questions[this.questionIndex].options.length / 2) {
console.log("allTrue===") console.log("allTrue===")
this.clearntervals(); this.clearntervals();
this.resultQuesitons.push({
duration: this.data.questions[this.questionIndex].gameTime-this.gameTime,// 用时多久
rightPairNumber: 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.questionIndex++ this.nextQuestion();
this.overN.active=false;
this.initGameData();
this.initCards();
this.tipN.active = false;
let children = this.cardParentN.children;
for (let i = 0; i < children.length; i++) {
children[i].getComponent("card").asyncDoFlip(() => {
if (i == children.length - 1) this.startWatch();
})
}
}else{ }else{
this.gameOver(true) this.gameOver(true)
} }
...@@ -316,7 +340,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -316,7 +340,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
) )
} else { } else {
Promise Promise
.all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl(data.audio)]) .all([node.getComponent("card").asyncDoFlip(), this.asyncPlayAudioByUrl(data.audio)])
.then(() => { .then(() => {
Promise.all([this.playLocalAudio("false")]) Promise.all([this.playLocalAudio("false")])
.then(() => { .then(() => {
...@@ -338,6 +362,19 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -338,6 +362,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
nextQuestion(){
this.questionIndex++
this.overN.active=false;
this.initGameData();
this.initCards();
this.tipN.active = false;
let children = this.cardParentN.children;
for (let i = 0; i < children.length; i++) {
children[i].getComponent("card").asyncDoFlip(() => {
if (i == children.length - 1) this.startWatch();
})
}
};
clearntervals() { clearntervals() {
// cc.find("Canvas/uiP/top/timeN").active=false; // cc.find("Canvas/uiP/top/timeN").active=false;
if (this.watchInterval) { if (this.watchInterval) {
...@@ -348,21 +385,19 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -348,21 +385,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
gameOver(isSuc){ gameOver(isSuc){
this.questionIndex=0;
this.overN.active=true;
let sucN=this.overN.getChildByName("suc")
let failN=this.overN.getChildByName("fail")
if(isSuc){ if(isSuc){
this.questionIndex=0;
this.overN.active=true;
let sucN=this.overN.getChildByName("suc")
let failN=this.overN.getChildByName("fail")
sucN.active=true; sucN.active=true;
failN.active=false; failN.active=false;
this.playAudioByUrl("suc") // this.asyncPlayAudioByUrl("suc")
onHomeworkFinish(); onHomeworkFinish({
}else{ quesitons:this.resultQuesitons
sucN.active=false; });
failN.active=true;
} }
} }
playLocalAudio(audioName) { playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource); const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
...@@ -374,6 +409,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -374,6 +409,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
}) })
} }
onClickRestart(){ onClickRestart(){
this.resultQuesitons=[]
this.overN.active=false; this.overN.active=false;
this.initGameData(); this.initGameData();
this.initCards(); this.initCards();
...@@ -443,7 +479,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -443,7 +479,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// iconNode.y = iconNode.parent.height / 2 - 10; // iconNode.y = iconNode.parent.height / 2 - 10;
// iconNode.on(cc.Node.EventType.TOUCH_START, () => { // iconNode.on(cc.Node.EventType.TOUCH_START, () => {
// this.playAudioByUrl(this.data.audio_url); // this.asyncPlayAudioByUrl(this.data.audio_url);
// }) // })
// } // }
......
...@@ -167,8 +167,9 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -167,8 +167,9 @@ export class MyCocosSceneComponent extends cc.Component {
}) })
} }
playAudioByUrl(audio_url, cb = null) { asyncPlayAudioByUrl(audio_url, cb = null) {
if (audio_url) { if (audio_url) {
console.log("audio_url===",audio_url)
return new Promise((resole, reject) => { return new Promise((resole, reject) => {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => { cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
cc.audioEngine.stopAll(); cc.audioEngine.stopAll();
...@@ -185,4 +186,15 @@ export class MyCocosSceneComponent extends cc.Component { ...@@ -185,4 +186,15 @@ export class MyCocosSceneComponent extends cc.Component {
cb && cb(); cb && cb();
} }
} }
playAudioByUrl(audio_url,) {
if (audio_url) {
console.log("audio_url===",audio_url)
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
cc.audioEngine.stopAll();
console.log("audioClip=====",audioClip)
cc.audioEngine.playEffect(audioClip, false);
console.log("audioClip2=====",audioClip)
})
}
}
} }
\ No newline at end of file
...@@ -410,15 +410,12 @@ export function showTrebleFirework(baseNode, rabbonList) { ...@@ -410,15 +410,12 @@ export function showTrebleFirework(baseNode, rabbonList) {
showFireworks(left); showFireworks(left);
showFireworks(right); showFireworks(right);
} }
export function onHomeworkFinish(data) {
export function onHomeworkFinish() {
const middleLayer = cc.find('middleLayer'); const middleLayer = cc.find('middleLayer');
if (middleLayer) { if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer'); const middleLayerComponent = middleLayer.getComponent('middleLayer');
if (middleLayerComponent.role == 'student') { middleLayerComponent.onHomeworkFinish(() => { }, data);
middleLayerComponent.onHomeworkFinish(() => { });
}
} else { } else {
console.log('onHomeworkFinish'); console.log('onHomeworkFinish:' + JSON.stringify(data));
} }
} }
\ No newline at end of file
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