Commit 85ea6811 authored by yu's avatar yu

题目随机

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