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

提交

parent a96c0c79
This diff is collapsed.
......@@ -29,6 +29,15 @@ export default class SceneComponent extends MyCocosSceneComponent {
completeNum = 0;
@property(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 {
initData() {
this.log('initData:');
// 所有全局变量 默认都是null
//
// this.scheduleOnce(()=>{
this.playAudioByUrl(this.data.questionTextAudio)
// },1)
cc.find("Canvas/uiP/bg_tip").active=true;
this.tittleLabel.string = this.data.title;
this.tipLabel.string = this.data.questionText;
......@@ -189,13 +202,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
timeN.active = false;
timeN1.active = true;
// if(this.gameState=="game"){
if (numTime <= 1) {
if (numTime == 1) this.playLocalAudio("time1")
} else {
this.playLocalAudio("time2")
}
// }else{
if (this.gameState == "watching") {
if(numTime == 3)this.playLocalAudio("suc")
if (numTime == 1 || numTime == 2 || numTime == 3) {
this.countDown.active = true;
this.countDown.stopAllActions();
......@@ -208,6 +218,12 @@ export default class SceneComponent extends MyCocosSceneComponent {
})
.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 {
this.gameTime--;
console.log("gametime=====", this.gameTime)
if (this.gameTime <= 0) {
this.gameOver(false);
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();
......@@ -271,16 +297,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.clickNode1 = node;
this.clickNodeData1 = data;
this.clickNode1.getComponent("card").asyncDoFlip()
this.playAudioByUrl(this.clickNodeData1.audio);
this.asyncPlayAudioByUrl(this.clickNodeData1.audio);
// this.asyncPlayAudioByUrl( this.data.questionTextAudio);
} else {
if (this.clickNode1 == node) {
return;
// this.playAudioByUrl( this.clickNodeData1.audio);
// this.asyncPlayAudioByUrl( this.clickNodeData1.audio);
} else {
this.canTouch = false
if (this.clickNodeData1.pairIdx == data.pairIdx) {
Promise
.all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl(data.audio)])
.all([node.getComponent("card").asyncDoFlip(), this.asyncPlayAudioByUrl(data.audio)])
.then(() => {
Promise.all([node.getComponent("card").playDragon(), this.clickNode1.getComponent("card").playDragon(), this.playLocalAudio("true")])
.then(() => {
......@@ -293,18 +321,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.completeNum == this.data.questions[this.questionIndex].options.length / 2) {
console.log("allTrue===")
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.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();
})
}
this.nextQuestion();
}else{
this.gameOver(true)
}
......@@ -316,7 +340,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
)
} else {
Promise
.all([node.getComponent("card").asyncDoFlip(), this.playAudioByUrl(data.audio)])
.all([node.getComponent("card").asyncDoFlip(), this.asyncPlayAudioByUrl(data.audio)])
.then(() => {
Promise.all([this.playLocalAudio("false")])
.then(() => {
......@@ -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() {
// cc.find("Canvas/uiP/top/timeN").active=false;
if (this.watchInterval) {
......@@ -348,21 +385,19 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
gameOver(isSuc){
this.questionIndex=0;
this.overN.active=true;
let sucN=this.overN.getChildByName("suc")
let failN=this.overN.getChildByName("fail")
if(isSuc){
this.questionIndex=0;
this.overN.active=true;
let sucN=this.overN.getChildByName("suc")
let failN=this.overN.getChildByName("fail")
sucN.active=true;
failN.active=false;
this.playAudioByUrl("suc")
onHomeworkFinish();
}else{
sucN.active=false;
failN.active=true;
// this.asyncPlayAudioByUrl("suc")
onHomeworkFinish({
quesitons:this.resultQuesitons
});
}
}
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
......@@ -374,6 +409,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
})
}
onClickRestart(){
this.resultQuesitons=[]
this.overN.active=false;
this.initGameData();
this.initCards();
......@@ -443,7 +479,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// iconNode.y = iconNode.parent.height / 2 - 10;
// 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 {
})
}
playAudioByUrl(audio_url, cb = null) {
asyncPlayAudioByUrl(audio_url, cb = null) {
if (audio_url) {
console.log("audio_url===",audio_url)
return new Promise((resole, reject) => {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
cc.audioEngine.stopAll();
......@@ -185,4 +186,15 @@ export class MyCocosSceneComponent extends cc.Component {
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) {
showFireworks(left);
showFireworks(right);
}
export function onHomeworkFinish() {
export function onHomeworkFinish(data) {
const middleLayer = cc.find('middleLayer');
if (middleLayer) {
const middleLayerComponent = middleLayer.getComponent('middleLayer');
if (middleLayerComponent.role == 'student') {
middleLayerComponent.onHomeworkFinish(() => { });
}
middleLayerComponent.onHomeworkFinish(() => { }, data);
} 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