Commit f99454e0 authored by Tt's avatar Tt

封装当前题目获取方式,拓展出下一题和游戏结束判断

parent 8ce7dc3b
...@@ -33,8 +33,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -33,8 +33,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.initGame() this.initGame()
} }
initData() { initData() {
this.speed = 30 this.current = -1;
console.log(this.data)
} }
initView() { } initView() { }
initEvent() { initEvent() {
...@@ -43,6 +42,13 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -43,6 +42,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.touchOn(bottom_megaphone, this.create_bubbles, this) pg.view.touchOn(bottom_megaphone, this.create_bubbles, this)
} }
initGame() { initGame() {
this.current++;// 自动切换下一题
if (!this.currentQuestion) {
this.gameOver();
return;
}
this.speed = 30
console.log(this.data)
// 底部海螺 // 底部海螺
let bottom_megaphone = pg.view.find(this, 'layer_game/bg/bottom_megaphone') let bottom_megaphone = pg.view.find(this, 'layer_game/bg/bottom_megaphone')
// 开始海螺从底部升起 // 开始海螺从底部升起
...@@ -54,9 +60,16 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -54,9 +60,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
}) })
btn.start() btn.start()
} }
gameOver() {
console.log("游戏结束");
}
private current: number;
get currentQuestion() {
return this.data.questions[this.current];
}
// 制造气泡 // 制造气泡
create_bubbles() { create_bubbles() {
if(this.touchNumber > this.data.questions[0].options.length) { if (this.touchNumber > this.currentQuestion.options.length) {
console.log('此题结束') console.log('此题结束')
} else { } else {
let bottom_megaphone = pg.view.find(this, 'layer_game/bg/bottom_megaphone') let bottom_megaphone = pg.view.find(this, 'layer_game/bg/bottom_megaphone')
...@@ -70,14 +83,14 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -70,14 +83,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
let img = newPaoPao.getChildByName("img") let img = newPaoPao.getChildByName("img")
let text = newPaoPao.getChildByName("text") let text = newPaoPao.getChildByName("text")
// 判断是显示图片还是文字 // 判断是显示图片还是文字
if(this.data.questions[0].options[this.touchNumber - 1].type === 'img') { if (this.currentQuestion.options[this.touchNumber - 1].type === 'img') {
pg.view.visible(img, true) pg.view.visible(img, true)
pg.view.visible(text, false) pg.view.visible(text, false)
pg.view.setNetImg(img, this.data.questions[0].options[this.touchNumber - 1].image, { w:60, h:60 }) pg.view.setNetImg(img, this.currentQuestion.options[this.touchNumber - 1].image, { w: 60, h: 60 })
} else { } else {
pg.view.visible(img, false) pg.view.visible(img, false)
pg.view.visible(text, true) pg.view.visible(text, true)
pg.view.setString(text, this.data.questions[0].options[this.touchNumber - 1].text) pg.view.setString(text, this.currentQuestion.options[this.touchNumber - 1].text)
} }
let btn = cc.tween(bottom_megaphone) let btn = cc.tween(bottom_megaphone)
layer_paopao.addChild(newPaoPao) layer_paopao.addChild(newPaoPao)
...@@ -119,8 +132,8 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -119,8 +132,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 点击泡泡 // 点击泡泡
touchPaoPao(e: any) { touchPaoPao(e: any) {
// 如果泡泡没有到指定位置不允许点击 // 如果泡泡没有到指定位置不允许点击
if(this.targetPosition > e.target.y) return if (this.targetPosition > e.target.y) return
if(this.isCorrect) { if (this.isCorrect) {
// 成功 泡泡破碎 里面的内容消失 // 成功 泡泡破碎 里面的内容消失
let paopao = e.target.getChildByName("bubble") let paopao = e.target.getChildByName("bubble")
let broken = e.target.getChildByName("bubble_broken") let broken = e.target.getChildByName("bubble_broken")
......
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