Commit 85ea6811 authored by yu's avatar yu

题目随机

parent d7bbb9c5
...@@ -88,13 +88,21 @@ export default class Game { ...@@ -88,13 +88,21 @@ export default class Game {
this.page = 1; this.page = 1;
this.start = true; this.start = true;
this.lists = []; this.lists = [];
let arr = [];
for (let i = 0; i < this.data.length; i++) { for (let i = 0; i < this.data.length; i++) {
let data = this.data[i]; let data = this.data[i];
this.lists.push(new Item(data, i)); arr.push(new Item(data, i));
} }
this.lists.sort(function () {
return (0.5 - Math.random()); let page = arr[0].page;
}); do {
arr.sort(() => Math.random() - 0.5);
} while (arr[0].page == page);
arr.forEach((item, idx) => {
item.page = idx + 1;
this.lists.push(item);
})
} }
checkSuccess(arr: Option[]) { checkSuccess(arr: Option[]) {
let data = this.getCurrentPage(); let data = this.getCurrentPage();
......
This diff is collapsed.
...@@ -259,9 +259,8 @@ export default class PuzzleJigsaw extends MyCocosSceneComponent { ...@@ -259,9 +259,8 @@ export default class PuzzleJigsaw extends MyCocosSceneComponent {
itemBg.errorCount++; itemBg.errorCount++;
if (itemBg.errorCount >= 3) { if (itemBg.errorCount >= 3) {
this.errorThere(target, itemBg); this.errorThere(target, itemBg);
this.playLocalAudio("right").then(() => { this.playLocalAudio("right");
this.roundOver(); this.roundOver();
});
} else { } else {
this.playLocalAudio("error"); this.playLocalAudio("error");
this.moveError(target, data); this.moveError(target, data);
...@@ -277,9 +276,8 @@ export default class PuzzleJigsaw extends MyCocosSceneComponent { ...@@ -277,9 +276,8 @@ export default class PuzzleJigsaw extends MyCocosSceneComponent {
let line = cc.find("line", item); let line = cc.find("line", item);
word.active = true; word.active = true;
line.active = false; line.active = false;
this.playLocalAudio("right").then(() => { this.playLocalAudio("right");
this.roundOver(); this.roundOver();
});
} }
private moveError(target, data) { private moveError(target, data) {
this.op_layout.children.forEach((item) => { this.op_layout.children.forEach((item) => {
...@@ -313,29 +311,33 @@ export default class PuzzleJigsaw extends MyCocosSceneComponent { ...@@ -313,29 +311,33 @@ export default class PuzzleJigsaw extends MyCocosSceneComponent {
} }
private roundOver() { private roundOver() {
if (this.checkRoundOver()) { if (this.checkRoundOver()) {
this.word_layout.active = false; cc.tween(this.nor_label)
this.word_layout.removeAllChildren(); .delay(0.5).call(() => {
cc.tween(this.nor_label).to(0.1, { opacity: 255 }).start(); this.word_layout.active = false;
let data = Game.getIns().getCurrentPage(); this.word_layout.removeAllChildren();
pg.audio.playAudioByUrl(data.wordAudio).then(() => { })
let pro = this.progressBar.getComponent(cc.ProgressBar); .to(0.1, { opacity: 255 }).delay(0.5).call(() => {
let p = Game.getIns().page / Game.getIns().getTotalPageNum(); let data = Game.getIns().getCurrentPage();
cc.tween(pro).to(1, { progress: p }).delay(1).call(() => { pg.audio.playAudioByUrl(data.wordAudio).then(() => {
let add = Game.getIns().addPage(); let pro = this.progressBar.getComponent(cc.ProgressBar);
if (add) { let p = Game.getIns().page / Game.getIns().getTotalPageNum();
this.nextPage() cc.tween(pro).to(1, { progress: p }).delay(1).call(() => {
} else { let add = Game.getIns().addPage();
if (Game.getIns().roundCount == 1) { if (add) {
Game.getIns().roundCount = 2; this.nextPage()
Game.getIns().page = 1; } else {
this.startGame(); if (Game.getIns().roundCount == 1) {
} else { Game.getIns().roundCount = 2;
this.goodJob.active = true; Game.getIns().page = 1;
this.gameOver(); this.startGame();
} } else {
} this.goodJob.active = true;
this.gameOver();
}
}
}).start();
})
}).start(); }).start();
})
} }
} }
private checkRoundOver() { private checkRoundOver() {
......
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