Commit 638eaea4 authored by Tt's avatar Tt

完美循环

parent aa363c89
......@@ -352,6 +352,14 @@ export default class SceneComponent extends MyCocosSceneComponent {
return;
}
// 如果未回答题目数量小于5,停止滚动并重新刷新列表
if (unansweredQuestions.length < 5) {
this.needScroll = false; // 停止滚动
// 重新显示页面
this.showPage();
return;
}
// 将未回答的题目添加到待添加队列
this.pendingCandyData = unansweredQuestions;
}
......@@ -434,7 +442,37 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 更新待添加的糖果数据队列,获取最新的未回答题目
// 这样在无限滚动时会排除刚刚回答正确的题目
this.pendingCandyData = this.getUnansweredQuestions();
const unansweredQuestions = this.getUnansweredQuestions();
this.pendingCandyData = unansweredQuestions;
// // 如果未回答题目数量小于5,停止滚动并重新刷新列表
// if (unansweredQuestions.length < 5 && unansweredQuestions.length > 0) {
// this.needScroll = false; // 停止滚动
// // 延迟一段时间后重新显示页面
// this.scheduleOnce(() => {
// this.showPage();
// }, 0.1); // 延迟1秒,给用户时间看到当前页面的完成状态
// return;
// }
// 在滚动列表中查找并隐藏对应题目的节点
if (this.touchData && this.layout && this.layout.childrenCount > 0) {
const currentQuestionId = this.touchData.id;
// 遍历布局中的所有节点
for (let i = 0; i < this.layout.childrenCount; i++) {
const node = this.layout.children[i] as CandyNode;
// 检查节点是否有data属性且id匹配
if (node.data && node.data.id === currentQuestionId) {
// 从活跃节点列表中移除
const nodeIndex = this.activeNodes.indexOf(node);
if (nodeIndex !== -1) {
this.activeNodes.splice(nodeIndex, 1);
}
// 隐藏节点
node.active = false;
}
}
}
// 检查当前页面是否所有火苗都已处理完毕
if (this.activeNodes.length === 0) {
......@@ -484,15 +522,21 @@ export default class SceneComponent extends MyCocosSceneComponent {
Game.getIns().addPage();
// 获取最新的未回答题目
this.pendingCandyData = this.getUnansweredQuestions();
const unansweredQuestions = this.getUnansweredQuestions();
this.pendingCandyData = unansweredQuestions;
// 如果没有未回答的题目,游戏结束
if (this.pendingCandyData.length === 0) {
if (unansweredQuestions.length === 0) {
// 可以在这里添加游戏结束逻辑
this.gameOver();
return;
}
// 如果未回答题目数量小于5,设置不滚动
if (unansweredQuestions.length < 5) {
this.needScroll = false;
}
// 重新显示页面
this.showPage();
}
......@@ -822,24 +866,24 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.layout.x -= frameScrollDistance;
// 累计滚动距离
this.scrollDistance = Math.abs(this.layout.x) - this.addCount * 200;
if (!this.addCount) {
this.addCount = 1;
this.addNewCandyNode(); // 添加新节点
} else if (this.scrollDistance >= 200 && this.pendingCandyData.length > 0) {
this.addCount++;
this.addNewCandyNode(); // 添加新节点
} else if (this.pendingCandyData.length == 0) {
let unansweredQuestions = this.getUnansweredQuestions();
this.pendingCandyData = unansweredQuestions.concat();
this.addCount++;
this.addNewCandyNode(); // 添加新节点
this.scrollDistance = Math.abs(this.layout.x) - this.addCount * 100;
if (this.layout.childrenCount <= 6) {
if (!this.addCount && this.pendingCandyData.length > 0) {
this.addCount = 1;
this.addNewCandyNode(); // 添加新节点
} else {
if (this.pendingCandyData.length == 0) {
let unansweredQuestions = this.getUnansweredQuestions();
this.pendingCandyData = unansweredQuestions.concat();
}
this.addCount++;
this.addNewCandyNode(); // 添加新节点
}
}
// 检查第一个糖果节点是否已经移出视图
const firstCandy = this.layout.children[0];
if (firstCandy && firstCandy.x + this.layout.x + firstCandy.width / 2 < -this.layout.parent.width / 2) {
if (firstCandy && firstCandy.x + this.layout.x + firstCandy.width / 2 < 0) {
// 从活跃节点数组中移除第一个节点
if (this.activeNodes.includes(firstCandy)) {
const index = this.activeNodes.indexOf(firstCandy);
......@@ -852,7 +896,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
firstCandy.removeFromParent();
firstCandy.destroy();
console.log("当前节点数量"+ this.layout.childrenCount);
console.log("当前节点数量" + this.layout.childrenCount);
}
}
}
......
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