Commit 0d999088 authored by Chen Jiping's avatar Chen Jiping

fix:修复显示问题

parent c85320c1
......@@ -128,6 +128,10 @@ export class Card {
this.bgWord.addChild(label);
this.h = this.bgWord.getBoundingBox().height;
}
if (callback) {
callback();
}
}
......
......@@ -91,7 +91,7 @@ export class PlayComponent implements OnInit, OnDestroy {
gameEndFlag = false;
showCardTimeIdArr = [];
showCardTimeId;
@HostListener('window:resize', ['$event'])
onResize(event) {
......@@ -559,21 +559,18 @@ export class PlayComponent implements OnInit, OnDestroy {
this.answerArr.push(...this.data.answerArr);
this.answerArr2.push(...this.answerArr);
this.answerArr2 = [];
this.holeExistArr = [];
this.cardExistArr = [];
console.log(this.showCardTimeIdArr);
if (this.showCardTimeIdArr) {
this.showCardTimeIdArr.forEach((showCardTimeId) => {
clearTimeout(showCardTimeId);
});
if (this.showCardTimeId) {
clearTimeout(this.showCardTimeId);
}
this.showCardTimeIdArr = [];
}
......@@ -772,6 +769,7 @@ export class PlayComponent implements OnInit, OnDestroy {
this.cardArr = [];
this.holePosArr = [];
this.answerArr2 = [];
const rightNum = Math.ceil(Math.random() * 3);
const idArr = randomSortByArr([1, 2, 3]);
......@@ -837,7 +835,7 @@ export class PlayComponent implements OnInit, OnDestroy {
for (let i = 0; i < this.cardArr.length; i++) {
clearTimeout(this.cardArr[i].timeId);
if (this.cardArr[i].tween) {
//this.cardArr[i].tween.stop();
this.cardArr[i].tween.stop();
}
}
......@@ -857,8 +855,6 @@ export class PlayComponent implements OnInit, OnDestroy {
this.gameEndFlag = false;
this.answerArr = randomSortByArr(this.answerArr2);
this.answerArr.forEach((val) => {
val.endFlag = false;
})
......@@ -871,19 +867,32 @@ export class PlayComponent implements OnInit, OnDestroy {
}
getAnswer(callback) {
if (this.answerArr.length <= 0) {
setTimeout(() => {
let answer = this.getRandomItemFromArr(this.answerArr);
if(!answer){
setTimeout(()=>{
this.getAnswer(callback);
}, 20);
return;
}, 10);
}
else{
let index = this.answerArr2.indexOf(answer);
let answer = this.answerArr.shift();
if(index == -1 && !answer.endFlag){
this.answerArr2.push(answer);
callback(answer);
}
else{
setTimeout(()=>{
this.getAnswer(callback);
}, 10);
}
}
}
getRandomItemFromArr(arr) {
......@@ -904,11 +913,12 @@ export class PlayComponent implements OnInit, OnDestroy {
return;
}
if (this.holeExistArr.length >= 2) {
if (this.holeExistArr.length >= 3) {
return;
}
this.getAnswer((answer) => {
const holeArr = [0, 1, 2, 3 , 4];
for (let i = 0; i < this.holeExistArr.length; i++) {
removeItemFromArr(holeArr, this.holeExistArr[i]);
......@@ -927,6 +937,7 @@ export class PlayComponent implements OnInit, OnDestroy {
const cardIndex = cardIndexArr[i];
if (cardIndex) {
const card = this.cardArr[cardIndex];
if (card.canHit) {
cardIndexArr.splice(i, 1);
i--;
......@@ -960,14 +971,13 @@ export class PlayComponent implements OnInit, OnDestroy {
this.holeExistArr.push(holeIndex);
this.cardExistArr.push(cardIndex);
let showCardTimeId = setTimeout(() => {
this.showCardTimeId = setTimeout(() => {
// console.log(' in timeout')
this.showCard();
removeItemFromArr(this.showCardTimeIdArr, showCardTimeId);
}, 500 + 1500 * Math.random());
this.showCardTimeIdArr.push(showCardTimeId);
});
}
......@@ -1000,13 +1010,16 @@ export class PlayComponent implements OnInit, OnDestroy {
card.canHit = false;
if (!card.curAnswer.endFlag) {
removeItemFromArr(this.cardExistArr, card.id);
} else {
this.checkGameEnd();
}
removeItemFromArr(this.cardExistArr, card.id);
removeItemFromArr(this.holeExistArr, card.holeId);
this.answerArr.push(card.curAnswer);
removeItemFromArr(this.answerArr2, card.curAnswer);
if (this.holeExistArr.length <= 1) {
this.showCard();
......@@ -1050,8 +1063,8 @@ export class PlayComponent implements OnInit, OnDestroy {
}
checkGameEnd() {
for (let i = 0; i < this.answerArr2.length; i++) {
if (this.answerArr2[i].isRight == '1' && !this.answerArr2[i].endFlag) {
for (let i = 0; i < this.answerArr.length; i++) {
if (this.answerArr[i].isRight == '1' && !this.answerArr[i].endFlag) {
return;
}
}
......@@ -1065,8 +1078,8 @@ export class PlayComponent implements OnInit, OnDestroy {
this.audioAni.pauseAudio();
for (let i = 0; i < this.cardArr.length; i++) {
this.cardArr[i].bg.childDepandAlpha = true;
hideItem(this.cardArr[i].bg, 0.3);
//hideItem(this.cardArr[i].bg, 0.3);
this.cardArr[i].bg.visible = false;
}
this.gameEndFlag = true;
......
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