功能完成,等待UI
This commit is contained in:
parent
1abe14c632
commit
dc41fefb31
File diff suppressed because it is too large
Load Diff
|
@ -29,17 +29,24 @@ export default class Ball extends cc.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
init(type,id){
|
init(type,id){
|
||||||
this.GameManager = this.node.parent.getComponent("GameManager");
|
this.set_Touch(type)
|
||||||
|
if(this.node.parent.name != "GameArea"){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.GameManager = this.node.parent.parent.getComponent("GameManager");
|
||||||
this.tube_Array = this.GameManager.tube_Array;
|
this.tube_Array = this.GameManager.tube_Array;
|
||||||
this._posX = this.node.x;
|
this._posX = this.node.x;
|
||||||
this._posY = this.node.y;
|
this._posY = this.node.y;
|
||||||
this.size = cc.winSize;
|
this.size = cc.winSize;
|
||||||
this._touch = type;
|
|
||||||
this._id = id;
|
this._id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
start () {
|
set_Touch(type){
|
||||||
|
this._touch = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
start () {
|
||||||
}
|
}
|
||||||
//开始点击,提高层级
|
//开始点击,提高层级
|
||||||
touchStart (event) {
|
touchStart (event) {
|
||||||
|
@ -49,11 +56,10 @@ export default class Ball extends cc.Component {
|
||||||
else{
|
else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//移动小球,跟随手指移动
|
//移动小球,跟随手指移动
|
||||||
touchMove (event) {
|
touchMove (event) {
|
||||||
|
this.node.zIndex = 2;
|
||||||
if(this._touch){
|
if(this._touch){
|
||||||
var touchTemp = cc.v2(event.touch._point.x-this.size.width/2,event.touch._point.y-this.size.height/2);
|
var touchTemp = cc.v2(event.touch._point.x-this.size.width/2,event.touch._point.y-this.size.height/2);
|
||||||
this.node.x = touchTemp.x;
|
this.node.x = touchTemp.x;
|
||||||
|
@ -63,28 +69,39 @@ export default class Ball extends cc.Component {
|
||||||
//松手,还原层级,判断是否落到玻璃管内
|
//松手,还原层级,判断是否落到玻璃管内
|
||||||
touchEnd (event) {
|
touchEnd (event) {
|
||||||
//先判断是否是回收
|
//先判断是否是回收
|
||||||
|
this.node.zIndex = 0;
|
||||||
if(this._touch){
|
if(this._touch){
|
||||||
var jg = this.getPos(cc.v2(this.node.x,this.node.y));
|
var jg = this.getPos(cc.v2(this.node.x,this.node.y));
|
||||||
if(jg == 0){
|
if(jg == 0){
|
||||||
this.node.x = this._posX;
|
this.node.x = this._posX;
|
||||||
this.node.y = this._posY;
|
this.node.y = this._posY;
|
||||||
}
|
}
|
||||||
|
else if(jg == 1 && this._posX == -210){
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
|
else if(jg == 2 && this._posX == 0){
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
|
else if(jg == 3 && this._posX == 210){
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
this.runEnter(jg);
|
this.runEnter(jg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this._posX = this.node.x;
|
this._posX = this.node.x;
|
||||||
this._posY = this.node.y;
|
this._posY = this.node.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this.node.zIndex = 1;
|
|
||||||
}
|
}
|
||||||
//执行进管子动画
|
//执行进管子动画
|
||||||
runEnter(jg){
|
runEnter(jg){
|
||||||
if(jg == 1 && this.tube_Array[0].length < 3){
|
if(jg == 1 && this.tube_Array[0].length < 3){
|
||||||
var height = 50+this.tube_Array[0].length*100;
|
var height = -100+this.tube_Array[0].length*100;
|
||||||
cc.fx.Notifications.emit("moveTube",{id:this._id,tube:0,pos:cc.v2(this._posX,this._posY)});
|
cc.fx.Notifications.emit("moveTube",{id:this._id,tube:0,
|
||||||
|
start_Pos:cc.v2(this._posX,this._posY),
|
||||||
|
end_Pos:cc.v2(-210,height)});
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2,{x:-210})
|
.to(0.2,{x:-210})
|
||||||
.to(0.25,{y:height})
|
.to(0.25,{y:height})
|
||||||
|
@ -94,9 +111,11 @@ export default class Ball extends cc.Component {
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
else if(jg == 3 && this.tube_Array[1].length < 2){
|
else if(jg == 2 && this.tube_Array[1].length < 2){
|
||||||
var height = 50+this.tube_Array[1].length*100;
|
var height = -100+this.tube_Array[1].length*100;
|
||||||
cc.fx.Notifications.emit("moveTube",{id:this._id,tube:1,pos:cc.v2(this._posX,this._posY)});
|
cc.fx.Notifications.emit("moveTube",{id:this._id,tube:1,
|
||||||
|
start_Pos:cc.v2(this._posX,this._posY),
|
||||||
|
end_Pos:cc.v2(0,height)});
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2,{x:0})
|
.to(0.2,{x:0})
|
||||||
.to(0.25,{y:height})
|
.to(0.25,{y:height})
|
||||||
|
@ -106,9 +125,11 @@ export default class Ball extends cc.Component {
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
else if(jg == 5 && this.tube_Array[2].length < 1){
|
else if(jg == 3 && this.tube_Array[2].length < 1){
|
||||||
var height = 50+this.tube_Array[2].length*100;
|
var height = -100+this.tube_Array[2].length*100;
|
||||||
cc.fx.Notifications.emit("moveTube",{id:this._id,tube:2,pos:cc.v2(this._posX,this._posY)});
|
cc.fx.Notifications.emit("moveTube",{id:this._id,tube:2,
|
||||||
|
start_Pos:cc.v2(this._posX,this._posY),
|
||||||
|
end_Pos:cc.v2(210,height)});
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2,{x:210})
|
.to(0.2,{x:210})
|
||||||
.to(0.25,{y:height})
|
.to(0.25,{y:height})
|
||||||
|
@ -117,31 +138,25 @@ export default class Ball extends cc.Component {
|
||||||
this._posY = this.node.y;
|
this._posY = this.node.y;
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPos(point){
|
getPos(point){
|
||||||
var jg = 0;
|
var jg = 0;
|
||||||
var rect = this.GameManager.tube1.getBoundingBox();
|
var tube1 = this.GameManager.tube1;var tube2 = this.GameManager.tube2;var tube3 = this.GameManager.tube3
|
||||||
if (rect.contains(point)) {
|
var rect1 = cc.rect(tube1.x, tube1.y, tube1.width, tube1.height);
|
||||||
jg = 1;
|
var rect2 = cc.rect(tube2.x, tube2.y, tube2.width, tube2.height);
|
||||||
return jg;
|
var rect3 = cc.rect(tube3.x, tube3.y, tube3.width, tube3.height);
|
||||||
}
|
var nodeRect = cc.rect(point.x, point.y, this.node.width, this.node.height);
|
||||||
rect = this.GameManager.tube3.getBoundingBox();
|
if (nodeRect.intersects(rect1)) jg = 1;
|
||||||
if (rect.contains(point)) {
|
else if (nodeRect.intersects(rect2)) jg = 2;
|
||||||
jg = 3;
|
else if (nodeRect.intersects(rect3)) jg = 3;
|
||||||
return jg;
|
|
||||||
}
|
|
||||||
rect = this.GameManager.tube5.getBoundingBox();
|
|
||||||
if (rect.contains(point)) {
|
|
||||||
jg = 5;
|
|
||||||
return jg;
|
|
||||||
}
|
|
||||||
return jg;
|
return jg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// update (dt) {}
|
// update (dt) {
|
||||||
|
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,61 +2,225 @@
|
||||||
const {ccclass, property} = cc._decorator;
|
const {ccclass, property} = cc._decorator;
|
||||||
@ccclass
|
@ccclass
|
||||||
export default class GameManager extends cc.Component {
|
export default class GameManager extends cc.Component {
|
||||||
|
@property(cc.Prefab)
|
||||||
|
goal_Prefab: cc.Prefab = null;
|
||||||
|
@property(cc.Prefab)
|
||||||
|
middle_Prefab: cc.Prefab = null;
|
||||||
|
|
||||||
countTime: number; //游戏总daojishi
|
countTime: number; //游戏总daojishi
|
||||||
|
steps: number; //地图最大步数限制
|
||||||
tube1: cc.Node; //管子1
|
tube1: cc.Node; //管子1
|
||||||
tube3: cc.Node; //管子2
|
tube2: cc.Node; //管子2
|
||||||
tube5: cc.Node; //管子3
|
tube3: cc.Node; //管子3
|
||||||
ball1: cc.Node; //球1
|
ball1: cc.Node; //球1
|
||||||
ball2: cc.Node; //球2
|
ball2: cc.Node; //球2
|
||||||
ball3: cc.Node; //球3
|
ball3: cc.Node; //球3
|
||||||
tube_Array: number[][];//管子数组
|
goal: cc.Node; //管子1
|
||||||
|
middle: cc.Node; //管子2
|
||||||
|
tube_Array: any;//管子数组
|
||||||
|
goal_Array: any;//管子数组
|
||||||
|
middle_Array: any;//管子数组
|
||||||
|
|
||||||
onLoad () {}
|
onLoad () {}
|
||||||
start () {
|
start () {
|
||||||
this.fit();
|
this.fit();
|
||||||
this.init();
|
this.init();
|
||||||
|
setTimeout(() => {
|
||||||
|
cc.fx.Notifications.on("moveTube", this.moveTube, this);
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//初始化数据
|
//初始化数据
|
||||||
init(){
|
init(){
|
||||||
this.tube1 = this.node.getChildByName("tube1");
|
this.tube1 = this.node.getChildByName("GameArea").getChildByName("tube1");
|
||||||
this.tube3 = this.node.getChildByName("tube3");
|
this.tube2 = this.node.getChildByName("GameArea").getChildByName("tube2");
|
||||||
this.tube5 = this.node.getChildByName("tube5");
|
this.tube3 = this.node.getChildByName("GameArea").getChildByName("tube3");
|
||||||
this.ball1 = this.node.getChildByName("ball1");
|
this.ball1 = this.node.getChildByName("GameArea").getChildByName("ball1");
|
||||||
this.ball2 = this.node.getChildByName("ball2");
|
this.ball2 = this.node.getChildByName("GameArea").getChildByName("ball2");
|
||||||
this.ball3 = this.node.getChildByName("ball3");
|
this.ball3 = this.node.getChildByName("GameArea").getChildByName("ball3");
|
||||||
this.tube_Array = [[1,3],[2],[]];
|
this.goal = this.node.getChildByName("Goal");
|
||||||
|
this.middle = this.node.getChildByName("Middle");
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube1").zIndex = 1;
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube2").zIndex = 1;
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube3").zIndex = 1;
|
||||||
|
this.initMap()
|
||||||
this.initBall();
|
this.initBall();
|
||||||
}
|
}
|
||||||
|
//初始化 管子和球的关卡数据
|
||||||
|
initMap(){
|
||||||
|
this.tube_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].start,"start");
|
||||||
|
this.middle_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].middle,"middle");
|
||||||
|
this.goal_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].goal,"goal");
|
||||||
|
this.steps = cc.fx.GameConfig.LEVEL_INFO[0].steps;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 转变地图参数到程序可用
|
||||||
|
* @param tagArr tagArr为目标数组,可能为二维数组
|
||||||
|
* @param name 关卡,球和管子的类型,有start,middle,goal,其中middle是二维数组,最多为3个
|
||||||
|
*/
|
||||||
|
changeMap(tagArr, name){
|
||||||
|
//中间态可能有多组目标 故单独处理
|
||||||
|
if(name == "middle"){
|
||||||
|
for(let k=0; k<tagArr.length;k++){
|
||||||
|
let tempArr = tagArr[k];
|
||||||
|
for(let i=0; i<tempArr.length;i++){
|
||||||
|
if(tempArr[i].length > 0){
|
||||||
|
for(let j=0; j<tagArr[i].length; j++){
|
||||||
|
if(this.conversion_Char(tempArr[i][j]))
|
||||||
|
tempArr[i][j] = this.conversion_Char(tempArr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for(let i=0; i<tagArr.length;i++){
|
||||||
|
if(tagArr[i].length > 0){
|
||||||
|
for(let j=0; j<tagArr[i].length; j++){
|
||||||
|
if(this.conversion_Char(tagArr[i][j]))
|
||||||
|
tagArr[i][j] = this.conversion_Char(tagArr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tagArr;
|
||||||
|
}
|
||||||
|
//转换符号,"rgb"配置改为123
|
||||||
|
conversion_Char(str: string){
|
||||||
|
if(str == "r") return 1;
|
||||||
|
else if(str == "g") return 2;
|
||||||
|
else if(str == "b") return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
//初始化球球 管子状态所有关都一样-
|
||||||
initBall(){
|
initBall(){
|
||||||
|
//初始状态,球的初始化
|
||||||
for(let i=0; i<this.tube_Array.length; i++){
|
for(let i=0; i<this.tube_Array.length; i++){
|
||||||
if(this.tube_Array[i].length > 0 ){
|
if(this.tube_Array[i].length > 0 ){
|
||||||
for(let j =0; j<this.tube_Array[i].length; j++){
|
for(let j =0; j<this.tube_Array[i].length; j++){
|
||||||
let name = "ball" + this.tube_Array[i][j];
|
let name = "ball" + this.tube_Array[i][j];
|
||||||
this[name].active = true;
|
this[name].active = true;
|
||||||
this[name].setPosition((i-1)*210,50+j*100);
|
this[name].setPosition((i-1)*210,-100+j*100);
|
||||||
this[name].getComponent("Ball").init(j==(this.tube_Array[i].length-1)?true:false,this.tube_Array[i][j]);
|
this[name].getComponent("Ball").init(j==(this.tube_Array[i].length-1)?true:false,this.tube_Array[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//最终状态,球的初始化
|
||||||
|
for(let i=0; i<this.goal_Array.length; i++){
|
||||||
|
if(this.goal_Array[i].length > 0 ){
|
||||||
|
for(let j =0; j<this.goal_Array[i].length; j++){
|
||||||
|
let name = this.goal_Array[i][j] + 4;
|
||||||
|
this.goal.children[name].active = true;
|
||||||
|
this.goal.children[name].setPosition((i-1)*210,-100+j*100);
|
||||||
|
this.goal.children[name].getComponent("Ball").init(false,this.goal_Array[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//中间状态,球的初始化
|
||||||
|
for(let i=0; i<this.middle_Array.length;i++){
|
||||||
|
if(this.middle_Array.length > 0){
|
||||||
|
if(this.middle_Array.length == 1){
|
||||||
|
this.createMiddle(0);
|
||||||
|
}
|
||||||
|
else if(this.middle_Array.length == 3){
|
||||||
|
this.createMiddle(1);
|
||||||
|
this.createMiddle(2);
|
||||||
|
this.createMiddle(3);
|
||||||
|
// this.middle.getChildByName("part").active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
moveTube(data){
|
createMiddle(num){
|
||||||
this.tube_Array[data.tube].push(data.id);
|
let nodeName = "part";
|
||||||
var tube_Arr = this.tube_Array[1];
|
if(num != 0) nodeName = nodeName + num;
|
||||||
if(data.pos.x == -210){
|
|
||||||
tube_Arr = this.tube_Array[0];
|
|
||||||
}
|
|
||||||
else if(data.pos.x == 210){
|
|
||||||
tube_Arr = this.tube_Array[2];
|
|
||||||
}
|
|
||||||
tube_Arr.pop();
|
|
||||||
if(data.pos.y == 150){
|
|
||||||
|
|
||||||
|
let mid = this.middle.getChildByName(nodeName);
|
||||||
|
mid.active = true;
|
||||||
|
let mid_Arr = this.middle_Array[num-1];
|
||||||
|
for(let i=0; i<mid_Arr.length; i++){
|
||||||
|
if(mid_Arr[i].length > 0 ){
|
||||||
|
for(let j =0; j<mid_Arr[i].length; j++){
|
||||||
|
let name = mid_Arr[i][j] + 4;
|
||||||
|
mid.children[name].active = true;
|
||||||
|
mid.children[name].setPosition((i-1)*210,-100+j*100);
|
||||||
|
mid.children[name].getComponent("Ball").init(false,mid_Arr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当管子内球发生移动时,改变管子数组,并且重置所有球是否可移动状态
|
||||||
|
* @param data data格式为对象
|
||||||
|
* id:number 移动球的自己的id
|
||||||
|
* tube:number 移动到目标个管子,0,1,2
|
||||||
|
start_Pos:cc.v2(), 移动之前的位置
|
||||||
|
end_Pos:cc.v2() 移动之后的终点位置
|
||||||
|
*/
|
||||||
|
moveTube(data){
|
||||||
|
this.tube_Array[data.tube].push(data.id);
|
||||||
|
var tube_Arr = this.tube_Array[1];
|
||||||
|
if(data.start_Pos.x == -210){
|
||||||
|
tube_Arr = this.tube_Array[0];
|
||||||
|
}
|
||||||
|
else if(data.start_Pos.x == 210){
|
||||||
|
tube_Arr = this.tube_Array[2];
|
||||||
|
}
|
||||||
|
if(tube_Arr.length > 0) tube_Arr.pop();
|
||||||
|
if(data.start_Pos.y != 50 && tube_Arr.length > 0){
|
||||||
|
let name = "ball" + tube_Arr[tube_Arr.length-1];
|
||||||
|
this[name].getComponent("Ball").set_Touch(true);
|
||||||
|
}
|
||||||
|
if(data.end_Pos.y != 50){
|
||||||
|
tube_Arr = this.tube_Array[1];
|
||||||
|
if(data.end_Pos.x == -210){
|
||||||
|
tube_Arr = this.tube_Array[0];
|
||||||
|
}
|
||||||
|
else if(data.end_Pos.x == 210){
|
||||||
|
tube_Arr = this.tube_Array[2];
|
||||||
|
}
|
||||||
|
if(tube_Arr.length > 1){
|
||||||
|
let name = "ball" + tube_Arr[tube_Arr.length-2];
|
||||||
|
console.log(name);
|
||||||
|
this[name].getComponent("Ball").set_Touch(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.gameWin();
|
||||||
|
}
|
||||||
|
|
||||||
|
gameWin(){
|
||||||
|
var result = false;
|
||||||
|
//如果没有中间状态,或者中间状态都已达到,则达到最终目标则算胜利
|
||||||
|
if(this.middle_Array.length == 0){
|
||||||
|
result = this.isArrEqual(this.goal_Array);
|
||||||
|
if(result){
|
||||||
|
alert("成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for(let i=0; i<this.middle_Array.length; i++){
|
||||||
|
if(this.isArrEqual(this.middle_Array[i])){
|
||||||
|
alert("达到中间态");
|
||||||
|
this.middle_Array.splice(i,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//判断数组是否相同,如果join情况下都不相同就不用往下比较
|
||||||
|
isArrEqual(tagArr){
|
||||||
|
var result = false;
|
||||||
|
if(this.tube_Array.join() == tagArr.join()){
|
||||||
|
result = true;
|
||||||
|
for(let i=0; i<this.tube_Array.length; i++){
|
||||||
|
if(this.tube_Array[i].length != tagArr[i].length){
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//根据是否全面屏,做独立适配方面
|
//根据是否全面屏,做独立适配方面
|
||||||
fit(){
|
fit(){
|
||||||
|
@ -139,7 +303,7 @@ export default class GameManager extends cc.Component {
|
||||||
}
|
}
|
||||||
//上传排行榜数据
|
//上传排行榜数据
|
||||||
gameOver(time){
|
gameOver(time){
|
||||||
cc.fx.GameTool.setRank(time);
|
cc.fx.GameTool.setRank(time);
|
||||||
this.node.getChildByName("GameOver").active = true;
|
this.node.getChildByName("GameOver").active = true;
|
||||||
this.node.getChildByName("GameOver").opacity = 0;
|
this.node.getChildByName("GameOver").opacity = 0;
|
||||||
cc.tween(this.node.getChildByName("GameOver"))
|
cc.tween(this.node.getChildByName("GameOver"))
|
||||||
|
@ -153,9 +317,9 @@ export default class GameManager extends cc.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onEnable () {
|
onEnable () {
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
cc.fx.Notifications.on("moveTube", this.moveTube, this);
|
// cc.fx.Notifications.on("moveTube", this.moveTube, this);
|
||||||
}, 100);
|
// }, 100);
|
||||||
|
|
||||||
}
|
}
|
||||||
onDisable () {
|
onDisable () {
|
||||||
|
|
|
@ -48,6 +48,7 @@ export default class NewClass extends cc.Component {
|
||||||
//重新开始玩
|
//重新开始玩
|
||||||
again(){
|
again(){
|
||||||
cc.director.loadScene("GameScene");
|
cc.director.loadScene("GameScene");
|
||||||
|
|
||||||
}
|
}
|
||||||
//获取排行榜
|
//获取排行榜
|
||||||
getRank(){
|
getRank(){
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -6,40 +6,37 @@ const BASE_URL = "https://api.sparkus.cn";
|
||||||
//只负责网络接口 次类只负责和后端交互,不负责处理数据 数据处理在GameTool
|
//只负责网络接口 次类只负责和后端交互,不负责处理数据 数据处理在GameTool
|
||||||
@ccclass
|
@ccclass
|
||||||
export default class HttpUtil extends cc.Component {
|
export default class HttpUtil extends cc.Component {
|
||||||
static async getShareInfo(shareUrl: string): Promise<any> {
|
|
||||||
console.log("设置分享链接:",shareUrl);
|
|
||||||
const time = Math.floor((new Date().getTime()) / 1000)
|
|
||||||
const url = HttpUtil.apiSign(`/api/share/cfg?gameId=${config.gameId}&time=${time}&url=${shareUrl}`,{})
|
|
||||||
return this.post(url,null,null);
|
|
||||||
}
|
|
||||||
//排行榜
|
//排行榜
|
||||||
static async rankData(type,callback,data): Promise<any> {
|
static async rankData(type,callback,data): Promise<any> {
|
||||||
const time = Math.floor((new Date().getTime()) / 1000)
|
const time = Math.floor((new Date().getTime()) / 1000)
|
||||||
const url = HttpUtil.apiSign(`/api/get/rank/data?gameId=${config.gameId}&dataType=${type}&time=${time}`, data)
|
const url = HttpUtil.apiSign(`/api/get/rank/data?gameId=${config.gameId}&dataType=${type}&time=${time}`, data)
|
||||||
this.post(url,data,callback);
|
this.post(url,data,callback,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async uploadUserLogData(data,callback): Promise<any> {
|
static async uploadUserLogData(data,callback): Promise<any> {
|
||||||
const url = '/log/collect/data';
|
const url = '/log/collect/data';
|
||||||
this.post(url,data,callback);
|
this.post(url,data,callback,3);
|
||||||
}
|
}
|
||||||
//暂时用不到
|
//暂时用不到
|
||||||
static async getUserRecord(data,callback): Promise<any> {
|
static async getUserRecord(data,callback): Promise<any> {
|
||||||
const time = Math.floor((new Date().getTime()) / 1000)
|
const time = Math.floor((new Date().getTime()) / 1000)
|
||||||
const url = HttpUtil.apiSign(`/api/get/user/data?gameId=${config.gameId}&time=${time}`, data)
|
const url = HttpUtil.apiSign(`/api/get/user/data?gameId=${config.gameId}&time=${time}`, data)
|
||||||
this.post(url,data,callback);
|
this.post(url,data,callback,0);
|
||||||
}
|
}
|
||||||
static async post(url, data, callback) {
|
|
||||||
const response = await this.fetchData(url, data, 'POST');
|
static async get(url, callback,count) {
|
||||||
|
let repeat = count?count:0;
|
||||||
|
const response = await this.fetchData(url, null, 'GET',repeat);
|
||||||
callback && callback(response);
|
callback && callback(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async get(url, callback) {
|
static async post(url, data, callback,count) {
|
||||||
const response = await this.fetchData(url, null, 'GET');
|
let repeat = count?count:0;
|
||||||
|
const response = await this.fetchData(url, data, 'POST',repeat);
|
||||||
callback && callback(response);
|
callback && callback(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async fetchData(url, data, method) {
|
static async fetchData(url, data, method,repeat) {
|
||||||
const fullUrl = `${BASE_URL}${url}`;
|
const fullUrl = `${BASE_URL}${url}`;
|
||||||
const headers = { 'Content-Type': 'application/json' };
|
const headers = { 'Content-Type': 'application/json' };
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -49,17 +46,39 @@ export default class HttpUtil extends cc.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(fullUrl, options);
|
var response = await this.fetchWithTimeout(fullUrl,options);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP_______________error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
return await response.json();
|
return await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fetch error:', error);
|
console.error('Fetch_______________error:', error);
|
||||||
return null;
|
if(repeat > 0){
|
||||||
|
repeat -= 1;
|
||||||
|
const timeOut = (3-repeat)*5000;
|
||||||
|
setTimeout(async () => {
|
||||||
|
response = await this.fetchData(url, data, method,repeat);
|
||||||
|
}, timeOut);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async fetchWithTimeout(resource, options = {}) {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const id = setTimeout(() => controller.abort(), 5000);
|
||||||
|
const response = await fetch(resource, {
|
||||||
|
...options,
|
||||||
|
signal: controller.signal
|
||||||
|
});
|
||||||
|
clearTimeout(id);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param url {string} 接口地址
|
* @param url {string} 接口地址
|
||||||
|
|
|
@ -83,7 +83,7 @@ export class WeChat {
|
||||||
static async getShareInfo(shareUrl: string, callback:Function): Promise<any> {
|
static async getShareInfo(shareUrl: string, callback:Function): Promise<any> {
|
||||||
const time = Math.floor((new Date().getTime()) / 1000)
|
const time = Math.floor((new Date().getTime()) / 1000)
|
||||||
const url = cc.fx.HttpUtil.apiSign(`/api/share/cfg?gameId=${shareConfig.gameId}&time=${time}&url=${shareUrl}`,{})
|
const url = cc.fx.HttpUtil.apiSign(`/api/share/cfg?gameId=${shareConfig.gameId}&time=${time}&url=${shareUrl}`,{})
|
||||||
return cc.fx.HttpUtil.get(url,callback)
|
return cc.fx.HttpUtil.get(url,callback,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -115,7 +115,7 @@ var WeChat = /** @class */ (function () {
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
time = Math.floor((new Date().getTime()) / 1000);
|
||||||
url = cc.fx.HttpUtil.apiSign("/api/share/cfg?gameId=" + shareConfig.gameId + "&time=" + time + "&url=" + shareUrl, {});
|
url = cc.fx.HttpUtil.apiSign("/api/share/cfg?gameId=" + shareConfig.gameId + "&time=" + time + "&url=" + shareUrl, {});
|
||||||
return [2 /*return*/, cc.fx.HttpUtil.get(url, callback)];
|
return [2 /*return*/, cc.fx.HttpUtil.get(url, callback, 0)];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -16,6 +16,17 @@ var __extends = (this && this.__extends) || (function () {
|
||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
var __assign = (this && this.__assign) || function () {
|
||||||
|
__assign = Object.assign || function(t) {
|
||||||
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||||
|
s = arguments[i];
|
||||||
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||||
|
t[p] = s[p];
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
return __assign.apply(this, arguments);
|
||||||
|
};
|
||||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||||
|
@ -69,17 +80,6 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
}
|
}
|
||||||
HttpUtil_1 = HttpUtil;
|
HttpUtil_1 = HttpUtil;
|
||||||
HttpUtil.getShareInfo = function (shareUrl) {
|
|
||||||
return __awaiter(this, void 0, Promise, function () {
|
|
||||||
var time, url;
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
console.log("设置分享链接:", shareUrl);
|
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
|
||||||
url = HttpUtil_1.apiSign("/api/share/cfg?gameId=" + config.gameId + "&time=" + time + "&url=" + shareUrl, {});
|
|
||||||
return [2 /*return*/, this.post(url, null, null)];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
//排行榜
|
//排行榜
|
||||||
HttpUtil.rankData = function (type, callback, data) {
|
HttpUtil.rankData = function (type, callback, data) {
|
||||||
return __awaiter(this, void 0, Promise, function () {
|
return __awaiter(this, void 0, Promise, function () {
|
||||||
|
@ -87,7 +87,7 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
time = Math.floor((new Date().getTime()) / 1000);
|
||||||
url = HttpUtil_1.apiSign("/api/get/rank/data?gameId=" + config.gameId + "&dataType=" + type + "&time=" + time, data);
|
url = HttpUtil_1.apiSign("/api/get/rank/data?gameId=" + config.gameId + "&dataType=" + type + "&time=" + time, data);
|
||||||
this.post(url, data, callback);
|
this.post(url, data, callback, 0);
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -97,7 +97,7 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
var url;
|
var url;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
url = '/log/collect/data';
|
url = '/log/collect/data';
|
||||||
this.post(url, data, callback);
|
this.post(url, data, callback, 3);
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -109,17 +109,19 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
time = Math.floor((new Date().getTime()) / 1000);
|
||||||
url = HttpUtil_1.apiSign("/api/get/user/data?gameId=" + config.gameId + "&time=" + time, data);
|
url = HttpUtil_1.apiSign("/api/get/user/data?gameId=" + config.gameId + "&time=" + time, data);
|
||||||
this.post(url, data, callback);
|
this.post(url, data, callback, 0);
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
HttpUtil.post = function (url, data, callback) {
|
HttpUtil.get = function (url, callback, count) {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var response;
|
var repeat, response;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0: return [4 /*yield*/, this.fetchData(url, data, 'POST')];
|
case 0:
|
||||||
|
repeat = count ? count : 0;
|
||||||
|
return [4 /*yield*/, this.fetchData(url, null, 'GET', repeat)];
|
||||||
case 1:
|
case 1:
|
||||||
response = _a.sent();
|
response = _a.sent();
|
||||||
callback && callback(response);
|
callback && callback(response);
|
||||||
|
@ -128,12 +130,14 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
HttpUtil.get = function (url, callback) {
|
HttpUtil.post = function (url, data, callback, count) {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var response;
|
var repeat, response;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0: return [4 /*yield*/, this.fetchData(url, null, 'GET')];
|
case 0:
|
||||||
|
repeat = count ? count : 0;
|
||||||
|
return [4 /*yield*/, this.fetchData(url, data, 'POST', repeat)];
|
||||||
case 1:
|
case 1:
|
||||||
response = _a.sent();
|
response = _a.sent();
|
||||||
callback && callback(response);
|
callback && callback(response);
|
||||||
|
@ -142,9 +146,10 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
HttpUtil.fetchData = function (url, data, method) {
|
HttpUtil.fetchData = function (url, data, method, repeat) {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var fullUrl, headers, options, response, error_1;
|
var fullUrl, headers, options, response, error_1, timeOut;
|
||||||
|
var _this = this;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -158,23 +163,58 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
_a.label = 1;
|
_a.label = 1;
|
||||||
case 1:
|
case 1:
|
||||||
_a.trys.push([1, 4, , 5]);
|
_a.trys.push([1, 4, , 5]);
|
||||||
return [4 /*yield*/, fetch(fullUrl, options)];
|
return [4 /*yield*/, this.fetchWithTimeout(fullUrl, options)];
|
||||||
case 2:
|
case 2:
|
||||||
response = _a.sent();
|
response = _a.sent();
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("HTTP error! status: " + response.status);
|
throw new Error("HTTP_______________error! status: " + response.status);
|
||||||
}
|
}
|
||||||
return [4 /*yield*/, response.json()];
|
return [4 /*yield*/, response.json()];
|
||||||
case 3: return [2 /*return*/, _a.sent()];
|
case 3: return [2 /*return*/, _a.sent()];
|
||||||
case 4:
|
case 4:
|
||||||
error_1 = _a.sent();
|
error_1 = _a.sent();
|
||||||
console.error('Fetch error:', error_1);
|
console.error('Fetch_______________error:', error_1);
|
||||||
return [2 /*return*/, null];
|
if (repeat > 0) {
|
||||||
|
repeat -= 1;
|
||||||
|
timeOut = (3 - repeat) * 5000;
|
||||||
|
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0: return [4 /*yield*/, this.fetchData(url, data, method, repeat)];
|
||||||
|
case 1:
|
||||||
|
response = _a.sent();
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); }, timeOut);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [2 /*return*/, null];
|
||||||
|
}
|
||||||
|
return [3 /*break*/, 5];
|
||||||
case 5: return [2 /*return*/];
|
case 5: return [2 /*return*/];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
HttpUtil.fetchWithTimeout = function (resource, options) {
|
||||||
|
if (options === void 0) { options = {}; }
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var controller, id, response;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
controller = new AbortController();
|
||||||
|
id = setTimeout(function () { return controller.abort(); }, 5000);
|
||||||
|
return [4 /*yield*/, fetch(resource, __assign(__assign({}, options), { signal: controller.signal }))];
|
||||||
|
case 1:
|
||||||
|
response = _a.sent();
|
||||||
|
clearTimeout(id);
|
||||||
|
return [2 /*return*/, response];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param url {string} 接口地址
|
* @param url {string} 接口地址
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -28,48 +28,210 @@ var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
|
||||||
var GameManager = /** @class */ (function (_super) {
|
var GameManager = /** @class */ (function (_super) {
|
||||||
__extends(GameManager, _super);
|
__extends(GameManager, _super);
|
||||||
function GameManager() {
|
function GameManager() {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
_this.goal_Prefab = null;
|
||||||
|
_this.middle_Prefab = null;
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
GameManager.prototype.onLoad = function () { };
|
GameManager.prototype.onLoad = function () { };
|
||||||
GameManager.prototype.start = function () {
|
GameManager.prototype.start = function () {
|
||||||
|
var _this = this;
|
||||||
this.fit();
|
this.fit();
|
||||||
this.init();
|
this.init();
|
||||||
|
setTimeout(function () {
|
||||||
|
cc.fx.Notifications.on("moveTube", _this.moveTube, _this);
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
//初始化数据
|
//初始化数据
|
||||||
GameManager.prototype.init = function () {
|
GameManager.prototype.init = function () {
|
||||||
this.tube1 = this.node.getChildByName("tube1");
|
this.tube1 = this.node.getChildByName("GameArea").getChildByName("tube1");
|
||||||
this.tube3 = this.node.getChildByName("tube3");
|
this.tube2 = this.node.getChildByName("GameArea").getChildByName("tube2");
|
||||||
this.tube5 = this.node.getChildByName("tube5");
|
this.tube3 = this.node.getChildByName("GameArea").getChildByName("tube3");
|
||||||
this.ball1 = this.node.getChildByName("ball1");
|
this.ball1 = this.node.getChildByName("GameArea").getChildByName("ball1");
|
||||||
this.ball2 = this.node.getChildByName("ball2");
|
this.ball2 = this.node.getChildByName("GameArea").getChildByName("ball2");
|
||||||
this.ball3 = this.node.getChildByName("ball3");
|
this.ball3 = this.node.getChildByName("GameArea").getChildByName("ball3");
|
||||||
this.tube_Array = [[1, 3], [2], []];
|
this.goal = this.node.getChildByName("Goal");
|
||||||
|
this.middle = this.node.getChildByName("Middle");
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube1").zIndex = 1;
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube2").zIndex = 1;
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube3").zIndex = 1;
|
||||||
|
this.initMap();
|
||||||
this.initBall();
|
this.initBall();
|
||||||
};
|
};
|
||||||
|
//初始化 管子和球的关卡数据
|
||||||
|
GameManager.prototype.initMap = function () {
|
||||||
|
this.tube_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].start, "start");
|
||||||
|
this.middle_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].middle, "middle");
|
||||||
|
this.goal_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].goal, "goal");
|
||||||
|
this.steps = cc.fx.GameConfig.LEVEL_INFO[0].steps;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 转变地图参数到程序可用
|
||||||
|
* @param tagArr tagArr为目标数组,可能为二维数组
|
||||||
|
* @param name 关卡,球和管子的类型,有start,middle,goal,其中middle是二维数组,最多为3个
|
||||||
|
*/
|
||||||
|
GameManager.prototype.changeMap = function (tagArr, name) {
|
||||||
|
//中间态可能有多组目标 故单独处理
|
||||||
|
if (name == "middle") {
|
||||||
|
for (var k = 0; k < tagArr.length; k++) {
|
||||||
|
var tempArr = tagArr[k];
|
||||||
|
for (var i = 0; i < tempArr.length; i++) {
|
||||||
|
if (tempArr[i].length > 0) {
|
||||||
|
for (var j = 0; j < tagArr[i].length; j++) {
|
||||||
|
if (this.conversion_Char(tempArr[i][j]))
|
||||||
|
tempArr[i][j] = this.conversion_Char(tempArr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (var i = 0; i < tagArr.length; i++) {
|
||||||
|
if (tagArr[i].length > 0) {
|
||||||
|
for (var j = 0; j < tagArr[i].length; j++) {
|
||||||
|
if (this.conversion_Char(tagArr[i][j]))
|
||||||
|
tagArr[i][j] = this.conversion_Char(tagArr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tagArr;
|
||||||
|
};
|
||||||
|
//转换符号,"rgb"配置改为123
|
||||||
|
GameManager.prototype.conversion_Char = function (str) {
|
||||||
|
if (str == "r")
|
||||||
|
return 1;
|
||||||
|
else if (str == "g")
|
||||||
|
return 2;
|
||||||
|
else if (str == "b")
|
||||||
|
return 3;
|
||||||
|
};
|
||||||
|
//初始化球球 管子状态所有关都一样-
|
||||||
GameManager.prototype.initBall = function () {
|
GameManager.prototype.initBall = function () {
|
||||||
|
//初始状态,球的初始化
|
||||||
for (var i = 0; i < this.tube_Array.length; i++) {
|
for (var i = 0; i < this.tube_Array.length; i++) {
|
||||||
if (this.tube_Array[i].length > 0) {
|
if (this.tube_Array[i].length > 0) {
|
||||||
for (var j = 0; j < this.tube_Array[i].length; j++) {
|
for (var j = 0; j < this.tube_Array[i].length; j++) {
|
||||||
var name = "ball" + this.tube_Array[i][j];
|
var name = "ball" + this.tube_Array[i][j];
|
||||||
this[name].active = true;
|
this[name].active = true;
|
||||||
this[name].setPosition((i - 1) * 210, 50 + j * 100);
|
this[name].setPosition((i - 1) * 210, -100 + j * 100);
|
||||||
this[name].getComponent("Ball").init(j == (this.tube_Array[i].length - 1) ? true : false, this.tube_Array[i][j]);
|
this[name].getComponent("Ball").init(j == (this.tube_Array[i].length - 1) ? true : false, this.tube_Array[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//最终状态,球的初始化
|
||||||
|
for (var i = 0; i < this.goal_Array.length; i++) {
|
||||||
|
if (this.goal_Array[i].length > 0) {
|
||||||
|
for (var j = 0; j < this.goal_Array[i].length; j++) {
|
||||||
|
var name = this.goal_Array[i][j] + 4;
|
||||||
|
this.goal.children[name].active = true;
|
||||||
|
this.goal.children[name].setPosition((i - 1) * 210, -100 + j * 100);
|
||||||
|
this.goal.children[name].getComponent("Ball").init(false, this.goal_Array[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//中间状态,球的初始化
|
||||||
|
for (var i = 0; i < this.middle_Array.length; i++) {
|
||||||
|
if (this.middle_Array.length > 0) {
|
||||||
|
if (this.middle_Array.length == 1) {
|
||||||
|
this.createMiddle(0);
|
||||||
|
}
|
||||||
|
else if (this.middle_Array.length == 3) {
|
||||||
|
this.createMiddle(1);
|
||||||
|
this.createMiddle(2);
|
||||||
|
this.createMiddle(3);
|
||||||
|
// this.middle.getChildByName("part").active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
GameManager.prototype.createMiddle = function (num) {
|
||||||
|
var nodeName = "part";
|
||||||
|
if (num != 0)
|
||||||
|
nodeName = nodeName + num;
|
||||||
|
var mid = this.middle.getChildByName(nodeName);
|
||||||
|
mid.active = true;
|
||||||
|
var mid_Arr = this.middle_Array[num - 1];
|
||||||
|
for (var i = 0; i < mid_Arr.length; i++) {
|
||||||
|
if (mid_Arr[i].length > 0) {
|
||||||
|
for (var j = 0; j < mid_Arr[i].length; j++) {
|
||||||
|
var name = mid_Arr[i][j] + 4;
|
||||||
|
mid.children[name].active = true;
|
||||||
|
mid.children[name].setPosition((i - 1) * 210, -100 + j * 100);
|
||||||
|
mid.children[name].getComponent("Ball").init(false, mid_Arr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 当管子内球发生移动时,改变管子数组,并且重置所有球是否可移动状态
|
||||||
|
* @param data data格式为对象
|
||||||
|
* id:number 移动球的自己的id
|
||||||
|
* tube:number 移动到目标个管子,0,1,2
|
||||||
|
start_Pos:cc.v2(), 移动之前的位置
|
||||||
|
end_Pos:cc.v2() 移动之后的终点位置
|
||||||
|
*/
|
||||||
GameManager.prototype.moveTube = function (data) {
|
GameManager.prototype.moveTube = function (data) {
|
||||||
this.tube_Array[data.tube].push(data.id);
|
this.tube_Array[data.tube].push(data.id);
|
||||||
var tube_Arr = this.tube_Array[1];
|
var tube_Arr = this.tube_Array[1];
|
||||||
if (data.pos.x == -210) {
|
if (data.start_Pos.x == -210) {
|
||||||
tube_Arr = this.tube_Array[0];
|
tube_Arr = this.tube_Array[0];
|
||||||
}
|
}
|
||||||
else if (data.pos.x == 210) {
|
else if (data.start_Pos.x == 210) {
|
||||||
tube_Arr = this.tube_Array[2];
|
tube_Arr = this.tube_Array[2];
|
||||||
}
|
}
|
||||||
tube_Arr.pop();
|
if (tube_Arr.length > 0)
|
||||||
if (data.pos.y == 150) {
|
tube_Arr.pop();
|
||||||
|
if (data.start_Pos.y != 50 && tube_Arr.length > 0) {
|
||||||
|
var name = "ball" + tube_Arr[tube_Arr.length - 1];
|
||||||
|
this[name].getComponent("Ball").set_Touch(true);
|
||||||
}
|
}
|
||||||
|
if (data.end_Pos.y != 50) {
|
||||||
|
tube_Arr = this.tube_Array[1];
|
||||||
|
if (data.end_Pos.x == -210) {
|
||||||
|
tube_Arr = this.tube_Array[0];
|
||||||
|
}
|
||||||
|
else if (data.end_Pos.x == 210) {
|
||||||
|
tube_Arr = this.tube_Array[2];
|
||||||
|
}
|
||||||
|
if (tube_Arr.length > 1) {
|
||||||
|
var name = "ball" + tube_Arr[tube_Arr.length - 2];
|
||||||
|
console.log(name);
|
||||||
|
this[name].getComponent("Ball").set_Touch(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.gameWin();
|
||||||
|
};
|
||||||
|
GameManager.prototype.gameWin = function () {
|
||||||
|
var result = false;
|
||||||
|
//如果没有中间状态,或者中间状态都已达到,则达到最终目标则算胜利
|
||||||
|
if (this.middle_Array.length == 0) {
|
||||||
|
result = this.isArrEqual(this.goal_Array);
|
||||||
|
if (result) {
|
||||||
|
alert("成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (var i = 0; i < this.middle_Array.length; i++) {
|
||||||
|
if (this.isArrEqual(this.middle_Array[i])) {
|
||||||
|
alert("达到中间态");
|
||||||
|
this.middle_Array.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//判断数组是否相同,如果join情况下都不相同就不用往下比较
|
||||||
|
GameManager.prototype.isArrEqual = function (tagArr) {
|
||||||
|
var result = false;
|
||||||
|
if (this.tube_Array.join() == tagArr.join()) {
|
||||||
|
result = true;
|
||||||
|
for (var i = 0; i < this.tube_Array.length; i++) {
|
||||||
|
if (this.tube_Array[i].length != tagArr[i].length) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
//根据是否全面屏,做独立适配方面
|
//根据是否全面屏,做独立适配方面
|
||||||
GameManager.prototype.fit = function () {
|
GameManager.prototype.fit = function () {
|
||||||
|
@ -159,16 +321,21 @@ var GameManager = /** @class */ (function (_super) {
|
||||||
.start();
|
.start();
|
||||||
};
|
};
|
||||||
GameManager.prototype.onEnable = function () {
|
GameManager.prototype.onEnable = function () {
|
||||||
var _this = this;
|
// setTimeout(() => {
|
||||||
setTimeout(function () {
|
// cc.fx.Notifications.on("moveTube", this.moveTube, this);
|
||||||
cc.fx.Notifications.on("moveTube", _this.moveTube, _this);
|
// }, 100);
|
||||||
}, 100);
|
|
||||||
};
|
};
|
||||||
GameManager.prototype.onDisable = function () {
|
GameManager.prototype.onDisable = function () {
|
||||||
cc.fx.Notifications.off("moveTube", this.moveTube);
|
cc.fx.Notifications.off("moveTube", this.moveTube);
|
||||||
};
|
};
|
||||||
GameManager.prototype.update = function (dt) {
|
GameManager.prototype.update = function (dt) {
|
||||||
};
|
};
|
||||||
|
__decorate([
|
||||||
|
property(cc.Prefab)
|
||||||
|
], GameManager.prototype, "goal_Prefab", void 0);
|
||||||
|
__decorate([
|
||||||
|
property(cc.Prefab)
|
||||||
|
], GameManager.prototype, "middle_Prefab", void 0);
|
||||||
GameManager = __decorate([
|
GameManager = __decorate([
|
||||||
ccclass
|
ccclass
|
||||||
], GameManager);
|
], GameManager);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -45,14 +45,20 @@ var Ball = /** @class */ (function (_super) {
|
||||||
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
|
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
|
||||||
};
|
};
|
||||||
Ball.prototype.init = function (type, id) {
|
Ball.prototype.init = function (type, id) {
|
||||||
this.GameManager = this.node.parent.getComponent("GameManager");
|
this.set_Touch(type);
|
||||||
|
if (this.node.parent.name != "GameArea") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.GameManager = this.node.parent.parent.getComponent("GameManager");
|
||||||
this.tube_Array = this.GameManager.tube_Array;
|
this.tube_Array = this.GameManager.tube_Array;
|
||||||
this._posX = this.node.x;
|
this._posX = this.node.x;
|
||||||
this._posY = this.node.y;
|
this._posY = this.node.y;
|
||||||
this.size = cc.winSize;
|
this.size = cc.winSize;
|
||||||
this._touch = type;
|
|
||||||
this._id = id;
|
this._id = id;
|
||||||
};
|
};
|
||||||
|
Ball.prototype.set_Touch = function (type) {
|
||||||
|
this._touch = type;
|
||||||
|
};
|
||||||
Ball.prototype.start = function () {
|
Ball.prototype.start = function () {
|
||||||
};
|
};
|
||||||
//开始点击,提高层级
|
//开始点击,提高层级
|
||||||
|
@ -66,6 +72,7 @@ var Ball = /** @class */ (function (_super) {
|
||||||
};
|
};
|
||||||
//移动小球,跟随手指移动
|
//移动小球,跟随手指移动
|
||||||
Ball.prototype.touchMove = function (event) {
|
Ball.prototype.touchMove = function (event) {
|
||||||
|
this.node.zIndex = 2;
|
||||||
if (this._touch) {
|
if (this._touch) {
|
||||||
var touchTemp = cc.v2(event.touch._point.x - this.size.width / 2, event.touch._point.y - this.size.height / 2);
|
var touchTemp = cc.v2(event.touch._point.x - this.size.width / 2, event.touch._point.y - this.size.height / 2);
|
||||||
this.node.x = touchTemp.x;
|
this.node.x = touchTemp.x;
|
||||||
|
@ -75,26 +82,40 @@ var Ball = /** @class */ (function (_super) {
|
||||||
//松手,还原层级,判断是否落到玻璃管内
|
//松手,还原层级,判断是否落到玻璃管内
|
||||||
Ball.prototype.touchEnd = function (event) {
|
Ball.prototype.touchEnd = function (event) {
|
||||||
//先判断是否是回收
|
//先判断是否是回收
|
||||||
|
this.node.zIndex = 0;
|
||||||
if (this._touch) {
|
if (this._touch) {
|
||||||
var jg = this.getPos(cc.v2(this.node.x, this.node.y));
|
var jg = this.getPos(cc.v2(this.node.x, this.node.y));
|
||||||
if (jg == 0) {
|
if (jg == 0) {
|
||||||
this.node.x = this._posX;
|
this.node.x = this._posX;
|
||||||
this.node.y = this._posY;
|
this.node.y = this._posY;
|
||||||
}
|
}
|
||||||
|
else if (jg == 1 && this._posX == -210) {
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
|
else if (jg == 2 && this._posX == 0) {
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
|
else if (jg == 3 && this._posX == 210) {
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.runEnter(jg);
|
this.runEnter(jg);
|
||||||
}
|
}
|
||||||
this._posX = this.node.x;
|
this._posX = this.node.x;
|
||||||
this._posY = this.node.y;
|
this._posY = this.node.y;
|
||||||
}
|
}
|
||||||
// this.node.zIndex = 1;
|
|
||||||
};
|
};
|
||||||
//执行进管子动画
|
//执行进管子动画
|
||||||
Ball.prototype.runEnter = function (jg) {
|
Ball.prototype.runEnter = function (jg) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (jg == 1 && this.tube_Array[0].length < 3) {
|
if (jg == 1 && this.tube_Array[0].length < 3) {
|
||||||
var height = 50 + this.tube_Array[0].length * 100;
|
var height = -100 + this.tube_Array[0].length * 100;
|
||||||
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 0, pos: cc.v2(this._posX, this._posY) });
|
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 0,
|
||||||
|
start_Pos: cc.v2(this._posX, this._posY),
|
||||||
|
end_Pos: cc.v2(-210, height) });
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2, { x: -210 })
|
.to(0.2, { x: -210 })
|
||||||
.to(0.25, { y: height })
|
.to(0.25, { y: height })
|
||||||
|
@ -104,9 +125,11 @@ var Ball = /** @class */ (function (_super) {
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
else if (jg == 3 && this.tube_Array[1].length < 2) {
|
else if (jg == 2 && this.tube_Array[1].length < 2) {
|
||||||
var height = 50 + this.tube_Array[1].length * 100;
|
var height = -100 + this.tube_Array[1].length * 100;
|
||||||
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 1, pos: cc.v2(this._posX, this._posY) });
|
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 1,
|
||||||
|
start_Pos: cc.v2(this._posX, this._posY),
|
||||||
|
end_Pos: cc.v2(0, height) });
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2, { x: 0 })
|
.to(0.2, { x: 0 })
|
||||||
.to(0.25, { y: height })
|
.to(0.25, { y: height })
|
||||||
|
@ -116,9 +139,11 @@ var Ball = /** @class */ (function (_super) {
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
else if (jg == 5 && this.tube_Array[2].length < 1) {
|
else if (jg == 3 && this.tube_Array[2].length < 1) {
|
||||||
var height = 50 + this.tube_Array[2].length * 100;
|
var height = -100 + this.tube_Array[2].length * 100;
|
||||||
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 2, pos: cc.v2(this._posX, this._posY) });
|
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 2,
|
||||||
|
start_Pos: cc.v2(this._posX, this._posY),
|
||||||
|
end_Pos: cc.v2(210, height) });
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2, { x: 210 })
|
.to(0.2, { x: 210 })
|
||||||
.to(0.25, { y: height })
|
.to(0.25, { y: height })
|
||||||
|
@ -131,21 +156,19 @@ var Ball = /** @class */ (function (_super) {
|
||||||
};
|
};
|
||||||
Ball.prototype.getPos = function (point) {
|
Ball.prototype.getPos = function (point) {
|
||||||
var jg = 0;
|
var jg = 0;
|
||||||
var rect = this.GameManager.tube1.getBoundingBox();
|
var tube1 = this.GameManager.tube1;
|
||||||
if (rect.contains(point)) {
|
var tube2 = this.GameManager.tube2;
|
||||||
|
var tube3 = this.GameManager.tube3;
|
||||||
|
var rect1 = cc.rect(tube1.x, tube1.y, tube1.width, tube1.height);
|
||||||
|
var rect2 = cc.rect(tube2.x, tube2.y, tube2.width, tube2.height);
|
||||||
|
var rect3 = cc.rect(tube3.x, tube3.y, tube3.width, tube3.height);
|
||||||
|
var nodeRect = cc.rect(point.x, point.y, this.node.width, this.node.height);
|
||||||
|
if (nodeRect.intersects(rect1))
|
||||||
jg = 1;
|
jg = 1;
|
||||||
return jg;
|
else if (nodeRect.intersects(rect2))
|
||||||
}
|
jg = 2;
|
||||||
rect = this.GameManager.tube3.getBoundingBox();
|
else if (nodeRect.intersects(rect3))
|
||||||
if (rect.contains(point)) {
|
|
||||||
jg = 3;
|
jg = 3;
|
||||||
return jg;
|
|
||||||
}
|
|
||||||
rect = this.GameManager.tube5.getBoundingBox();
|
|
||||||
if (rect.contains(point)) {
|
|
||||||
jg = 5;
|
|
||||||
return jg;
|
|
||||||
}
|
|
||||||
return jg;
|
return jg;
|
||||||
};
|
};
|
||||||
Ball = __decorate([
|
Ball = __decorate([
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -3,9 +3,9 @@
|
||||||
"actualPlatform": "web-mobile",
|
"actualPlatform": "web-mobile",
|
||||||
"template": "link",
|
"template": "link",
|
||||||
"buildPath": "./build",
|
"buildPath": "./build",
|
||||||
"debug": true,
|
"debug": false,
|
||||||
"sourceMaps": true,
|
"sourceMaps": false,
|
||||||
"embedWebDebugger": true,
|
"embedWebDebugger": false,
|
||||||
"previewWidth": "1280",
|
"previewWidth": "1280",
|
||||||
"previewHeight": "720",
|
"previewHeight": "720",
|
||||||
"useDebugKeystore": true,
|
"useDebugKeystore": true,
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
"type": "dock-h",
|
"type": "dock-h",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"width": 205,
|
"width": 204.8541717529297,
|
||||||
"height": 556.3333740234375,
|
"height": 556.3333740234375,
|
||||||
"type": "dock-v",
|
"type": "dock-v",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"width": 205,
|
"width": 204.8541717529297,
|
||||||
"height": 300.1770935058594,
|
"height": 300.125,
|
||||||
"type": "panel",
|
"type": "panel",
|
||||||
"active": 0,
|
"active": 0,
|
||||||
"children": [
|
"children": [
|
||||||
|
@ -27,8 +27,8 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"width": 205,
|
"width": 204.8541717529297,
|
||||||
"height": 253.15625,
|
"height": 253.1979217529297,
|
||||||
"type": "panel",
|
"type": "panel",
|
||||||
"active": 0,
|
"active": 0,
|
||||||
"children": [
|
"children": [
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"width": 750.9896240234375,
|
"width": 751.1458740234375,
|
||||||
"height": 556.3333740234375,
|
"height": 556.3333740234375,
|
||||||
"type": "panel",
|
"type": "panel",
|
||||||
"active": 0,
|
"active": 0,
|
||||||
|
@ -65,7 +65,8 @@
|
||||||
"inspector",
|
"inspector",
|
||||||
"cocos-services"
|
"cocos-services"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
" common-asset-worker-worker": {}
|
||||||
},
|
},
|
||||||
"panels": {
|
"panels": {
|
||||||
"builder": {
|
"builder": {
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
"2d2f792f-a40c-49bb-a189-ed176a246e49",
|
"2d2f792f-a40c-49bb-a189-ed176a246e49",
|
||||||
"4b9c5a7e-c645-48a4-9aca-5df381ce4ef5",
|
"4b9c5a7e-c645-48a4-9aca-5df381ce4ef5",
|
||||||
"9c08062d-4cf1-4b6e-a8ba-4a3881cc7e7d",
|
"9c08062d-4cf1-4b6e-a8ba-4a3881cc7e7d",
|
||||||
"4eaf518b-35ec-4262-928d-4d497c3f2830"
|
"4eaf518b-35ec-4262-928d-4d497c3f2830",
|
||||||
|
"c27e9f02-e125-4ba1-9efb-9ff24d526a2a",
|
||||||
|
"891df9d4-29da-47e9-8b5e-22f99d946e08"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,11 +226,48 @@
|
||||||
"80QPlOdIJPoaH2q0H9durZ",
|
"80QPlOdIJPoaH2q0H9durZ",
|
||||||
"3b6z53P9FDL6t0qWgOypyL",
|
"3b6z53P9FDL6t0qWgOypyL",
|
||||||
"bdRIfCxsZBpLpMK3p5LzXO",
|
"bdRIfCxsZBpLpMK3p5LzXO",
|
||||||
"5dxBdyCr9Dd7WMwsS/0Owj",
|
|
||||||
"8bamKATtZDraFh2GkJfR3+",
|
"8bamKATtZDraFh2GkJfR3+",
|
||||||
"4cA7q0tFhBoqbHhb6ms4JS",
|
"4cA7q0tFhBoqbHhb6ms4JS",
|
||||||
"11mvPUKFJN77hNlPQmLVI2",
|
"11mvPUKFJN77hNlPQmLVI2",
|
||||||
|
"d7/cmCIxRE3onJjPbNQNgd",
|
||||||
|
"f84gfHLfVNroqdsO7QaGC3",
|
||||||
|
"23dZmRwhhEK6+m6u0awzJS",
|
||||||
|
"f1DUjCILpK8oPrCH3HSLcn",
|
||||||
|
"ddrfSlOx9CxqOxZgYBGuH4",
|
||||||
|
"40vYTjCeRMy5FhXiVXGXRQ",
|
||||||
|
"04erh99tpAQba36evSf4mm",
|
||||||
|
"33Kyh+lWRF5aNTm+SzuGPU",
|
||||||
|
"e8YKk9FC9G6qnqW9EKYjo5",
|
||||||
|
"e5cCWdzahAT7l9vA1Wkam7",
|
||||||
|
"deqDXOOhVAgKYcQ/hIPlzp",
|
||||||
|
"c3LpEA3ixBXLl96qnmYUdZ",
|
||||||
|
"5bO4qCh9tKwZO6tII25pZ1",
|
||||||
|
"8eDOCHTV1M7KLptP/PRCKB",
|
||||||
|
"d8EI44FNpHl5HCA3CQpEbW",
|
||||||
|
"3d8gt6MIVDmr0gTzIEW862",
|
||||||
|
"a2tq8TiohOiLTwbLzW1SzH",
|
||||||
|
"07b8TZ3jRD/LMIQ11zPTzA",
|
||||||
|
"6dEuxGe1lL9pdugwMEOdiw",
|
||||||
|
"78k6gZCeJFf6YJ7COLoh8b",
|
||||||
|
"f0BrSYSm1KGJoeqwQ0/sMU",
|
||||||
|
"1d254bwLdJlbZHZz4jgo2N",
|
||||||
|
"039EVs5TVMkoB677tGPS12",
|
||||||
|
"c8oMRtYvlK3Z4s2mR+chr5",
|
||||||
|
"96QXpG77NIULCj5B0NcZba",
|
||||||
|
"c2R3+I3HpF0IMmPqFutU8N",
|
||||||
|
"f1MZUoRrxNUZhoH9vQ5hml",
|
||||||
|
"a2b+jHhLVL242oFl1n2OLm",
|
||||||
|
"cf5UKd25FO05KPL8YKGrVz",
|
||||||
|
"5dxBdyCr9Dd7WMwsS/0Owj",
|
||||||
|
"16kFMW6RBKiYqo0DBGAp3k",
|
||||||
|
"3bHD9fTEBB1rTEbUreSz6A",
|
||||||
|
"1dkRYnimtKu6oWzSKgv3Nm",
|
||||||
"aaVQ+L81pDV6U2w2jt5hRt",
|
"aaVQ+L81pDV6U2w2jt5hRt",
|
||||||
"d7/cmCIxRE3onJjPbNQNgd"
|
"35gCtuf9ZEhp+Wlq/rIA8r",
|
||||||
|
"6aQrzONJ1H86bfZoDwAIn+",
|
||||||
|
"bco+CKSJRDn7buCXoGAsiw",
|
||||||
|
"42U8CsgrxKKZbmozy6FD1S",
|
||||||
|
"80GdedKR1JUqf0f7N+Ba3k",
|
||||||
|
"38BJNyFbRL64Brg3y+DE0l"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"mainCompressionType": "default",
|
"mainCompressionType": "default",
|
||||||
"mainIsRemote": false,
|
"mainIsRemote": false,
|
||||||
"optimizeHotUpdate": false,
|
"optimizeHotUpdate": false,
|
||||||
"md5Cache": false,
|
"md5Cache": true,
|
||||||
"nativeMd5Cache": true,
|
"nativeMd5Cache": true,
|
||||||
"encryptJs": true,
|
"encryptJs": true,
|
||||||
"xxteaKey": "07ac496c-82b0-4f",
|
"xxteaKey": "07ac496c-82b0-4f",
|
||||||
|
|
|
@ -9,7 +9,15 @@
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"excluded-modules": [
|
"excluded-modules": [
|
||||||
"3D Physics/Builtin"
|
"Spine Skeleton",
|
||||||
|
"TiledMap",
|
||||||
|
"VideoPlayer",
|
||||||
|
"WebView",
|
||||||
|
"3D",
|
||||||
|
"3D Primitive",
|
||||||
|
"3D Physics/cannon.js",
|
||||||
|
"3D Physics/Builtin",
|
||||||
|
"3D Particle"
|
||||||
],
|
],
|
||||||
"preview-port": 7456,
|
"preview-port": 7456,
|
||||||
"design-resolution-width": 960,
|
"design-resolution-width": 960,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
4030
temp/BackupAssets/assets/prefab/Middle.prefab
Normal file
4030
temp/BackupAssets/assets/prefab/Middle.prefab
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -1 +1 @@
|
||||||
{"version":"1.0.8","stats":{"C:/Work/Project/London/temp/quick-scripts/src/__qc_index__.js":"2024-08-16T01:18:59.977Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Config/GameConfig.js":"2024-08-16T01:18:59.940Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Sdk/DouyinEntranceView.js":"2024-08-16T01:18:59.932Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/GameStart/GameAppStart.js":"2024-08-16T01:18:59.925Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/GameManager.js":"2024-08-16T01:18:59.934Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Notification/Notification.js":"2024-08-16T01:18:59.920Z","C:/Work/Project/London/temp/quick-scripts/src/assets/migration/use_v2.1-2.2.1_cc.Toggle_event.js":"2024-08-16T01:18:59.929Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Share/share.js":"2024-08-16T01:18:59.926Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Crypto/HttpUtil.js":"2024-08-16T01:18:59.928Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/GameOver.js":"2024-08-16T01:18:59.931Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Storage/Storage.js":"2024-08-16T01:18:59.915Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Music/AudioManager.js":"2024-08-16T01:18:59.922Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/RankManager.js":"2024-08-16T01:18:59.947Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Load.js":"2024-08-16T01:18:59.918Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Tool/GameTool.js":"2024-08-16T01:18:59.917Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/RankList/ItemRender.js":"2024-08-16T01:18:59.942Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/GameScene.js":"2024-08-16T01:18:59.949Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Ball.js":"2024-08-16T01:18:59.936Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Sdk/MiniGameSdk.js":"2024-08-16T01:18:59.938Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/DynamicAtlasManager.js":"2024-08-16T01:18:59.923Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Sdk/MiniGameManager.js":"2024-08-16T01:18:59.913Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Crypto/crypto-js.min.js":"2024-08-16T01:18:59.945Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/RankList/List.js":"2024-08-16T01:18:59.943Z"}}
|
{"version":"1.0.8","stats":{"C:/Work/Project/London/temp/quick-scripts/src/__qc_index__.js":"2024-08-28T03:09:36.864Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Notification/Notification.js":"2024-08-28T03:09:36.779Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Sdk/MiniGameManager.js":"2024-08-28T03:09:36.771Z","C:/Work/Project/London/temp/quick-scripts/src/assets/migration/use_v2.1-2.2.1_cc.Toggle_event.js":"2024-08-28T03:09:36.794Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/GameOver.js":"2024-08-28T03:09:36.798Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Music/AudioManager.js":"2024-08-28T03:09:36.783Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Storage/Storage.js":"2024-08-28T03:09:36.775Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/RankList/ItemRender.js":"2024-08-28T03:09:36.811Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/GameScene.js":"2024-08-28T03:09:36.819Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Share/share.js":"2024-08-28T03:09:36.790Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Crypto/crypto-js.min.js":"2024-08-28T03:09:36.816Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/GameManager.js":"2024-08-28T03:09:36.799Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/RankManager.js":"2024-08-28T03:09:36.819Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Tool/GameTool.js":"2024-08-28T03:09:36.776Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Config/GameConfig.js":"2024-08-28T03:09:36.807Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Load.js":"2024-08-28T03:09:36.779Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Sdk/MiniGameSdk.js":"2024-08-28T03:09:36.807Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Ball.js":"2024-08-28T03:09:36.803Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/DynamicAtlasManager.js":"2024-08-28T03:09:36.786Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/Sdk/DouyinEntranceView.js":"2024-08-28T03:09:36.799Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/RankList/List.js":"2024-08-28T03:09:36.811Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/GameStart/GameAppStart.js":"2024-08-28T03:09:36.786Z","C:/Work/Project/London/temp/quick-scripts/src/assets/Script/module/Crypto/HttpUtil.js":"2024-08-28T03:09:36.790Z"}}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var scripts = [{"deps":{"./assets/Script/GameManager":4,"./assets/Script/GameOver":9,"./assets/Script/GameScene":16,"./assets/Script/Load":13,"./assets/Script/RankManager":12,"./assets/Script/Ball":17,"./assets/Script/Sdk/MiniGameManager":20,"./assets/Script/Sdk/MiniGameSdk":18,"./assets/Script/Sdk/DouyinEntranceView":2,"./assets/migration/use_v2.1-2.2.1_cc.Toggle_event":6,"./assets/Script/DynamicAtlasManager":19,"./assets/Script/module/Crypto/crypto-js.min":21,"./assets/Script/module/Crypto/HttpUtil":8,"./assets/Script/module/GameStart/GameAppStart":3,"./assets/Script/module/Music/AudioManager":11,"./assets/Script/module/Notification/Notification":5,"./assets/Script/module/RankList/List":22,"./assets/Script/module/RankList/ItemRender":15,"./assets/Script/module/Share/share":7,"./assets/Script/module/Storage/Storage":10,"./assets/Script/module/Tool/GameTool":14,"./assets/Script/module/Config/GameConfig":1},"path":"preview-scripts/__qc_index__.js"},{"deps":{"../Share/share":7},"path":"preview-scripts/assets/Script/module/Config/GameConfig.js"},{"deps":{"./MiniGameSdk":18},"path":"preview-scripts/assets/Script/Sdk/DouyinEntranceView.js"},{"deps":{"../Config/GameConfig":1,"../Crypto/HttpUtil":8,"../Music/AudioManager":11,"../Notification/Notification":5,"../Storage/Storage":10,"../Tool/GameTool":14},"path":"preview-scripts/assets/Script/module/GameStart/GameAppStart.js"},{"deps":{},"path":"preview-scripts/assets/Script/GameManager.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Notification/Notification.js"},{"deps":{},"path":"preview-scripts/assets/migration/use_v2.1-2.2.1_cc.Toggle_event.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Share/share.js"},{"deps":{"./crypto-js.min.js":21},"path":"preview-scripts/assets/Script/module/Crypto/HttpUtil.js"},{"deps":{},"path":"preview-scripts/assets/Script/GameOver.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Storage/Storage.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Music/AudioManager.js"},{"deps":{"./module/RankList/List":22},"path":"preview-scripts/assets/Script/RankManager.js"},{"deps":{},"path":"preview-scripts/assets/Script/Load.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Tool/GameTool.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/RankList/ItemRender.js"},{"deps":{},"path":"preview-scripts/assets/Script/GameScene.js"},{"deps":{},"path":"preview-scripts/assets/Script/Ball.js"},{"deps":{},"path":"preview-scripts/assets/Script/Sdk/MiniGameSdk.js"},{"deps":{},"path":"preview-scripts/assets/Script/DynamicAtlasManager.js"},{"deps":{"./MiniGameSdk":18},"path":"preview-scripts/assets/Script/Sdk/MiniGameManager.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Crypto/crypto-js.min.js"},{"deps":{"./ItemRender":15},"path":"preview-scripts/assets/Script/module/RankList/List.js"}];
|
var scripts = [{"deps":{"./assets/Script/module/Notification/Notification":1,"./assets/Script/Sdk/MiniGameManager":2,"./assets/migration/use_v2.1-2.2.1_cc.Toggle_event":3,"./assets/Script/GameOver":4,"./assets/Script/module/Music/AudioManager":5,"./assets/Script/module/Storage/Storage":6,"./assets/Script/module/RankList/ItemRender":7,"./assets/Script/GameScene":8,"./assets/Script/module/Share/share":9,"./assets/Script/module/Crypto/crypto-js.min":10,"./assets/Script/GameManager":11,"./assets/Script/RankManager":12,"./assets/Script/module/Tool/GameTool":13,"./assets/Script/module/Config/GameConfig":14,"./assets/Script/Load":15,"./assets/Script/Sdk/MiniGameSdk":16,"./assets/Script/Ball":17,"./assets/Script/DynamicAtlasManager":18,"./assets/Script/Sdk/DouyinEntranceView":19,"./assets/Script/module/RankList/List":20,"./assets/Script/module/GameStart/GameAppStart":21,"./assets/Script/module/Crypto/HttpUtil":22},"path":"preview-scripts/__qc_index__.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Notification/Notification.js"},{"deps":{"./MiniGameSdk":16},"path":"preview-scripts/assets/Script/Sdk/MiniGameManager.js"},{"deps":{},"path":"preview-scripts/assets/migration/use_v2.1-2.2.1_cc.Toggle_event.js"},{"deps":{},"path":"preview-scripts/assets/Script/GameOver.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Music/AudioManager.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Storage/Storage.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/RankList/ItemRender.js"},{"deps":{},"path":"preview-scripts/assets/Script/GameScene.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Share/share.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Crypto/crypto-js.min.js"},{"deps":{},"path":"preview-scripts/assets/Script/GameManager.js"},{"deps":{"./module/RankList/List":20},"path":"preview-scripts/assets/Script/RankManager.js"},{"deps":{},"path":"preview-scripts/assets/Script/module/Tool/GameTool.js"},{"deps":{"../Share/share":9},"path":"preview-scripts/assets/Script/module/Config/GameConfig.js"},{"deps":{},"path":"preview-scripts/assets/Script/Load.js"},{"deps":{},"path":"preview-scripts/assets/Script/Sdk/MiniGameSdk.js"},{"deps":{},"path":"preview-scripts/assets/Script/Ball.js"},{"deps":{},"path":"preview-scripts/assets/Script/DynamicAtlasManager.js"},{"deps":{"./MiniGameSdk":16},"path":"preview-scripts/assets/Script/Sdk/DouyinEntranceView.js"},{"deps":{"./ItemRender":7},"path":"preview-scripts/assets/Script/module/RankList/List.js"},{"deps":{"../Config/GameConfig":14,"../Crypto/HttpUtil":22,"../Music/AudioManager":5,"../Notification/Notification":1,"../Storage/Storage":6,"../Tool/GameTool":13},"path":"preview-scripts/assets/Script/module/GameStart/GameAppStart.js"},{"deps":{"./crypto-js.min.js":10},"path":"preview-scripts/assets/Script/module/Crypto/HttpUtil.js"}];
|
||||||
var entries = ["preview-scripts/__qc_index__.js"];
|
var entries = ["preview-scripts/__qc_index__.js"];
|
||||||
var bundleScript = 'preview-scripts/__qc_bundle__.js';
|
var bundleScript = 'preview-scripts/__qc_bundle__.js';
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -45,14 +45,20 @@ var Ball = /** @class */ (function (_super) {
|
||||||
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
|
this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd, this);
|
||||||
};
|
};
|
||||||
Ball.prototype.init = function (type, id) {
|
Ball.prototype.init = function (type, id) {
|
||||||
this.GameManager = this.node.parent.getComponent("GameManager");
|
this.set_Touch(type);
|
||||||
|
if (this.node.parent.name != "GameArea") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.GameManager = this.node.parent.parent.getComponent("GameManager");
|
||||||
this.tube_Array = this.GameManager.tube_Array;
|
this.tube_Array = this.GameManager.tube_Array;
|
||||||
this._posX = this.node.x;
|
this._posX = this.node.x;
|
||||||
this._posY = this.node.y;
|
this._posY = this.node.y;
|
||||||
this.size = cc.winSize;
|
this.size = cc.winSize;
|
||||||
this._touch = type;
|
|
||||||
this._id = id;
|
this._id = id;
|
||||||
};
|
};
|
||||||
|
Ball.prototype.set_Touch = function (type) {
|
||||||
|
this._touch = type;
|
||||||
|
};
|
||||||
Ball.prototype.start = function () {
|
Ball.prototype.start = function () {
|
||||||
};
|
};
|
||||||
//开始点击,提高层级
|
//开始点击,提高层级
|
||||||
|
@ -66,6 +72,7 @@ var Ball = /** @class */ (function (_super) {
|
||||||
};
|
};
|
||||||
//移动小球,跟随手指移动
|
//移动小球,跟随手指移动
|
||||||
Ball.prototype.touchMove = function (event) {
|
Ball.prototype.touchMove = function (event) {
|
||||||
|
this.node.zIndex = 2;
|
||||||
if (this._touch) {
|
if (this._touch) {
|
||||||
var touchTemp = cc.v2(event.touch._point.x - this.size.width / 2, event.touch._point.y - this.size.height / 2);
|
var touchTemp = cc.v2(event.touch._point.x - this.size.width / 2, event.touch._point.y - this.size.height / 2);
|
||||||
this.node.x = touchTemp.x;
|
this.node.x = touchTemp.x;
|
||||||
|
@ -75,26 +82,40 @@ var Ball = /** @class */ (function (_super) {
|
||||||
//松手,还原层级,判断是否落到玻璃管内
|
//松手,还原层级,判断是否落到玻璃管内
|
||||||
Ball.prototype.touchEnd = function (event) {
|
Ball.prototype.touchEnd = function (event) {
|
||||||
//先判断是否是回收
|
//先判断是否是回收
|
||||||
|
this.node.zIndex = 0;
|
||||||
if (this._touch) {
|
if (this._touch) {
|
||||||
var jg = this.getPos(cc.v2(this.node.x, this.node.y));
|
var jg = this.getPos(cc.v2(this.node.x, this.node.y));
|
||||||
if (jg == 0) {
|
if (jg == 0) {
|
||||||
this.node.x = this._posX;
|
this.node.x = this._posX;
|
||||||
this.node.y = this._posY;
|
this.node.y = this._posY;
|
||||||
}
|
}
|
||||||
|
else if (jg == 1 && this._posX == -210) {
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
|
else if (jg == 2 && this._posX == 0) {
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
|
else if (jg == 3 && this._posX == 210) {
|
||||||
|
this.node.x = this._posX;
|
||||||
|
this.node.y = this._posY;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.runEnter(jg);
|
this.runEnter(jg);
|
||||||
}
|
}
|
||||||
this._posX = this.node.x;
|
this._posX = this.node.x;
|
||||||
this._posY = this.node.y;
|
this._posY = this.node.y;
|
||||||
}
|
}
|
||||||
// this.node.zIndex = 1;
|
|
||||||
};
|
};
|
||||||
//执行进管子动画
|
//执行进管子动画
|
||||||
Ball.prototype.runEnter = function (jg) {
|
Ball.prototype.runEnter = function (jg) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (jg == 1 && this.tube_Array[0].length < 3) {
|
if (jg == 1 && this.tube_Array[0].length < 3) {
|
||||||
var height = 50 + this.tube_Array[0].length * 100;
|
var height = -100 + this.tube_Array[0].length * 100;
|
||||||
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 0, pos: cc.v2(this._posX, this._posY) });
|
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 0,
|
||||||
|
start_Pos: cc.v2(this._posX, this._posY),
|
||||||
|
end_Pos: cc.v2(-210, height) });
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2, { x: -210 })
|
.to(0.2, { x: -210 })
|
||||||
.to(0.25, { y: height })
|
.to(0.25, { y: height })
|
||||||
|
@ -104,9 +125,11 @@ var Ball = /** @class */ (function (_super) {
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
else if (jg == 3 && this.tube_Array[1].length < 2) {
|
else if (jg == 2 && this.tube_Array[1].length < 2) {
|
||||||
var height = 50 + this.tube_Array[1].length * 100;
|
var height = -100 + this.tube_Array[1].length * 100;
|
||||||
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 1, pos: cc.v2(this._posX, this._posY) });
|
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 1,
|
||||||
|
start_Pos: cc.v2(this._posX, this._posY),
|
||||||
|
end_Pos: cc.v2(0, height) });
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2, { x: 0 })
|
.to(0.2, { x: 0 })
|
||||||
.to(0.25, { y: height })
|
.to(0.25, { y: height })
|
||||||
|
@ -116,9 +139,11 @@ var Ball = /** @class */ (function (_super) {
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
}
|
}
|
||||||
else if (jg == 5 && this.tube_Array[2].length < 1) {
|
else if (jg == 3 && this.tube_Array[2].length < 1) {
|
||||||
var height = 50 + this.tube_Array[2].length * 100;
|
var height = -100 + this.tube_Array[2].length * 100;
|
||||||
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 2, pos: cc.v2(this._posX, this._posY) });
|
cc.fx.Notifications.emit("moveTube", { id: this._id, tube: 2,
|
||||||
|
start_Pos: cc.v2(this._posX, this._posY),
|
||||||
|
end_Pos: cc.v2(210, height) });
|
||||||
cc.tween(this.node)
|
cc.tween(this.node)
|
||||||
.to(0.2, { x: 210 })
|
.to(0.2, { x: 210 })
|
||||||
.to(0.25, { y: height })
|
.to(0.25, { y: height })
|
||||||
|
@ -131,21 +156,19 @@ var Ball = /** @class */ (function (_super) {
|
||||||
};
|
};
|
||||||
Ball.prototype.getPos = function (point) {
|
Ball.prototype.getPos = function (point) {
|
||||||
var jg = 0;
|
var jg = 0;
|
||||||
var rect = this.GameManager.tube1.getBoundingBox();
|
var tube1 = this.GameManager.tube1;
|
||||||
if (rect.contains(point)) {
|
var tube2 = this.GameManager.tube2;
|
||||||
|
var tube3 = this.GameManager.tube3;
|
||||||
|
var rect1 = cc.rect(tube1.x, tube1.y, tube1.width, tube1.height);
|
||||||
|
var rect2 = cc.rect(tube2.x, tube2.y, tube2.width, tube2.height);
|
||||||
|
var rect3 = cc.rect(tube3.x, tube3.y, tube3.width, tube3.height);
|
||||||
|
var nodeRect = cc.rect(point.x, point.y, this.node.width, this.node.height);
|
||||||
|
if (nodeRect.intersects(rect1))
|
||||||
jg = 1;
|
jg = 1;
|
||||||
return jg;
|
else if (nodeRect.intersects(rect2))
|
||||||
}
|
jg = 2;
|
||||||
rect = this.GameManager.tube3.getBoundingBox();
|
else if (nodeRect.intersects(rect3))
|
||||||
if (rect.contains(point)) {
|
|
||||||
jg = 3;
|
jg = 3;
|
||||||
return jg;
|
|
||||||
}
|
|
||||||
rect = this.GameManager.tube5.getBoundingBox();
|
|
||||||
if (rect.contains(point)) {
|
|
||||||
jg = 5;
|
|
||||||
return jg;
|
|
||||||
}
|
|
||||||
return jg;
|
return jg;
|
||||||
};
|
};
|
||||||
Ball = __decorate([
|
Ball = __decorate([
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -28,48 +28,210 @@ var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
|
||||||
var GameManager = /** @class */ (function (_super) {
|
var GameManager = /** @class */ (function (_super) {
|
||||||
__extends(GameManager, _super);
|
__extends(GameManager, _super);
|
||||||
function GameManager() {
|
function GameManager() {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
_this.goal_Prefab = null;
|
||||||
|
_this.middle_Prefab = null;
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
GameManager.prototype.onLoad = function () { };
|
GameManager.prototype.onLoad = function () { };
|
||||||
GameManager.prototype.start = function () {
|
GameManager.prototype.start = function () {
|
||||||
|
var _this = this;
|
||||||
this.fit();
|
this.fit();
|
||||||
this.init();
|
this.init();
|
||||||
|
setTimeout(function () {
|
||||||
|
cc.fx.Notifications.on("moveTube", _this.moveTube, _this);
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
//初始化数据
|
//初始化数据
|
||||||
GameManager.prototype.init = function () {
|
GameManager.prototype.init = function () {
|
||||||
this.tube1 = this.node.getChildByName("tube1");
|
this.tube1 = this.node.getChildByName("GameArea").getChildByName("tube1");
|
||||||
this.tube3 = this.node.getChildByName("tube3");
|
this.tube2 = this.node.getChildByName("GameArea").getChildByName("tube2");
|
||||||
this.tube5 = this.node.getChildByName("tube5");
|
this.tube3 = this.node.getChildByName("GameArea").getChildByName("tube3");
|
||||||
this.ball1 = this.node.getChildByName("ball1");
|
this.ball1 = this.node.getChildByName("GameArea").getChildByName("ball1");
|
||||||
this.ball2 = this.node.getChildByName("ball2");
|
this.ball2 = this.node.getChildByName("GameArea").getChildByName("ball2");
|
||||||
this.ball3 = this.node.getChildByName("ball3");
|
this.ball3 = this.node.getChildByName("GameArea").getChildByName("ball3");
|
||||||
this.tube_Array = [[1, 3], [2], []];
|
this.goal = this.node.getChildByName("Goal");
|
||||||
|
this.middle = this.node.getChildByName("Middle");
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube1").zIndex = 1;
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube2").zIndex = 1;
|
||||||
|
// this.node.getChildByName("GameArea").getChildByName("tube3").zIndex = 1;
|
||||||
|
this.initMap();
|
||||||
this.initBall();
|
this.initBall();
|
||||||
};
|
};
|
||||||
|
//初始化 管子和球的关卡数据
|
||||||
|
GameManager.prototype.initMap = function () {
|
||||||
|
this.tube_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].start, "start");
|
||||||
|
this.middle_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].middle, "middle");
|
||||||
|
this.goal_Array = this.changeMap(cc.fx.GameConfig.LEVEL_INFO[0].goal, "goal");
|
||||||
|
this.steps = cc.fx.GameConfig.LEVEL_INFO[0].steps;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 转变地图参数到程序可用
|
||||||
|
* @param tagArr tagArr为目标数组,可能为二维数组
|
||||||
|
* @param name 关卡,球和管子的类型,有start,middle,goal,其中middle是二维数组,最多为3个
|
||||||
|
*/
|
||||||
|
GameManager.prototype.changeMap = function (tagArr, name) {
|
||||||
|
//中间态可能有多组目标 故单独处理
|
||||||
|
if (name == "middle") {
|
||||||
|
for (var k = 0; k < tagArr.length; k++) {
|
||||||
|
var tempArr = tagArr[k];
|
||||||
|
for (var i = 0; i < tempArr.length; i++) {
|
||||||
|
if (tempArr[i].length > 0) {
|
||||||
|
for (var j = 0; j < tagArr[i].length; j++) {
|
||||||
|
if (this.conversion_Char(tempArr[i][j]))
|
||||||
|
tempArr[i][j] = this.conversion_Char(tempArr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (var i = 0; i < tagArr.length; i++) {
|
||||||
|
if (tagArr[i].length > 0) {
|
||||||
|
for (var j = 0; j < tagArr[i].length; j++) {
|
||||||
|
if (this.conversion_Char(tagArr[i][j]))
|
||||||
|
tagArr[i][j] = this.conversion_Char(tagArr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tagArr;
|
||||||
|
};
|
||||||
|
//转换符号,"rgb"配置改为123
|
||||||
|
GameManager.prototype.conversion_Char = function (str) {
|
||||||
|
if (str == "r")
|
||||||
|
return 1;
|
||||||
|
else if (str == "g")
|
||||||
|
return 2;
|
||||||
|
else if (str == "b")
|
||||||
|
return 3;
|
||||||
|
};
|
||||||
|
//初始化球球 管子状态所有关都一样-
|
||||||
GameManager.prototype.initBall = function () {
|
GameManager.prototype.initBall = function () {
|
||||||
|
//初始状态,球的初始化
|
||||||
for (var i = 0; i < this.tube_Array.length; i++) {
|
for (var i = 0; i < this.tube_Array.length; i++) {
|
||||||
if (this.tube_Array[i].length > 0) {
|
if (this.tube_Array[i].length > 0) {
|
||||||
for (var j = 0; j < this.tube_Array[i].length; j++) {
|
for (var j = 0; j < this.tube_Array[i].length; j++) {
|
||||||
var name = "ball" + this.tube_Array[i][j];
|
var name = "ball" + this.tube_Array[i][j];
|
||||||
this[name].active = true;
|
this[name].active = true;
|
||||||
this[name].setPosition((i - 1) * 210, 50 + j * 100);
|
this[name].setPosition((i - 1) * 210, -100 + j * 100);
|
||||||
this[name].getComponent("Ball").init(j == (this.tube_Array[i].length - 1) ? true : false, this.tube_Array[i][j]);
|
this[name].getComponent("Ball").init(j == (this.tube_Array[i].length - 1) ? true : false, this.tube_Array[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//最终状态,球的初始化
|
||||||
|
for (var i = 0; i < this.goal_Array.length; i++) {
|
||||||
|
if (this.goal_Array[i].length > 0) {
|
||||||
|
for (var j = 0; j < this.goal_Array[i].length; j++) {
|
||||||
|
var name = this.goal_Array[i][j] + 4;
|
||||||
|
this.goal.children[name].active = true;
|
||||||
|
this.goal.children[name].setPosition((i - 1) * 210, -100 + j * 100);
|
||||||
|
this.goal.children[name].getComponent("Ball").init(false, this.goal_Array[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//中间状态,球的初始化
|
||||||
|
for (var i = 0; i < this.middle_Array.length; i++) {
|
||||||
|
if (this.middle_Array.length > 0) {
|
||||||
|
if (this.middle_Array.length == 1) {
|
||||||
|
this.createMiddle(0);
|
||||||
|
}
|
||||||
|
else if (this.middle_Array.length == 3) {
|
||||||
|
this.createMiddle(1);
|
||||||
|
this.createMiddle(2);
|
||||||
|
this.createMiddle(3);
|
||||||
|
// this.middle.getChildByName("part").active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
GameManager.prototype.createMiddle = function (num) {
|
||||||
|
var nodeName = "part";
|
||||||
|
if (num != 0)
|
||||||
|
nodeName = nodeName + num;
|
||||||
|
var mid = this.middle.getChildByName(nodeName);
|
||||||
|
mid.active = true;
|
||||||
|
var mid_Arr = this.middle_Array[num - 1];
|
||||||
|
for (var i = 0; i < mid_Arr.length; i++) {
|
||||||
|
if (mid_Arr[i].length > 0) {
|
||||||
|
for (var j = 0; j < mid_Arr[i].length; j++) {
|
||||||
|
var name = mid_Arr[i][j] + 4;
|
||||||
|
mid.children[name].active = true;
|
||||||
|
mid.children[name].setPosition((i - 1) * 210, -100 + j * 100);
|
||||||
|
mid.children[name].getComponent("Ball").init(false, mid_Arr[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 当管子内球发生移动时,改变管子数组,并且重置所有球是否可移动状态
|
||||||
|
* @param data data格式为对象
|
||||||
|
* id:number 移动球的自己的id
|
||||||
|
* tube:number 移动到目标个管子,0,1,2
|
||||||
|
start_Pos:cc.v2(), 移动之前的位置
|
||||||
|
end_Pos:cc.v2() 移动之后的终点位置
|
||||||
|
*/
|
||||||
GameManager.prototype.moveTube = function (data) {
|
GameManager.prototype.moveTube = function (data) {
|
||||||
this.tube_Array[data.tube].push(data.id);
|
this.tube_Array[data.tube].push(data.id);
|
||||||
var tube_Arr = this.tube_Array[1];
|
var tube_Arr = this.tube_Array[1];
|
||||||
if (data.pos.x == -210) {
|
if (data.start_Pos.x == -210) {
|
||||||
tube_Arr = this.tube_Array[0];
|
tube_Arr = this.tube_Array[0];
|
||||||
}
|
}
|
||||||
else if (data.pos.x == 210) {
|
else if (data.start_Pos.x == 210) {
|
||||||
tube_Arr = this.tube_Array[2];
|
tube_Arr = this.tube_Array[2];
|
||||||
}
|
}
|
||||||
tube_Arr.pop();
|
if (tube_Arr.length > 0)
|
||||||
if (data.pos.y == 150) {
|
tube_Arr.pop();
|
||||||
|
if (data.start_Pos.y != 50 && tube_Arr.length > 0) {
|
||||||
|
var name = "ball" + tube_Arr[tube_Arr.length - 1];
|
||||||
|
this[name].getComponent("Ball").set_Touch(true);
|
||||||
}
|
}
|
||||||
|
if (data.end_Pos.y != 50) {
|
||||||
|
tube_Arr = this.tube_Array[1];
|
||||||
|
if (data.end_Pos.x == -210) {
|
||||||
|
tube_Arr = this.tube_Array[0];
|
||||||
|
}
|
||||||
|
else if (data.end_Pos.x == 210) {
|
||||||
|
tube_Arr = this.tube_Array[2];
|
||||||
|
}
|
||||||
|
if (tube_Arr.length > 1) {
|
||||||
|
var name = "ball" + tube_Arr[tube_Arr.length - 2];
|
||||||
|
console.log(name);
|
||||||
|
this[name].getComponent("Ball").set_Touch(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.gameWin();
|
||||||
|
};
|
||||||
|
GameManager.prototype.gameWin = function () {
|
||||||
|
var result = false;
|
||||||
|
//如果没有中间状态,或者中间状态都已达到,则达到最终目标则算胜利
|
||||||
|
if (this.middle_Array.length == 0) {
|
||||||
|
result = this.isArrEqual(this.goal_Array);
|
||||||
|
if (result) {
|
||||||
|
alert("成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (var i = 0; i < this.middle_Array.length; i++) {
|
||||||
|
if (this.isArrEqual(this.middle_Array[i])) {
|
||||||
|
alert("达到中间态");
|
||||||
|
this.middle_Array.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//判断数组是否相同,如果join情况下都不相同就不用往下比较
|
||||||
|
GameManager.prototype.isArrEqual = function (tagArr) {
|
||||||
|
var result = false;
|
||||||
|
if (this.tube_Array.join() == tagArr.join()) {
|
||||||
|
result = true;
|
||||||
|
for (var i = 0; i < this.tube_Array.length; i++) {
|
||||||
|
if (this.tube_Array[i].length != tagArr[i].length) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
//根据是否全面屏,做独立适配方面
|
//根据是否全面屏,做独立适配方面
|
||||||
GameManager.prototype.fit = function () {
|
GameManager.prototype.fit = function () {
|
||||||
|
@ -159,16 +321,21 @@ var GameManager = /** @class */ (function (_super) {
|
||||||
.start();
|
.start();
|
||||||
};
|
};
|
||||||
GameManager.prototype.onEnable = function () {
|
GameManager.prototype.onEnable = function () {
|
||||||
var _this = this;
|
// setTimeout(() => {
|
||||||
setTimeout(function () {
|
// cc.fx.Notifications.on("moveTube", this.moveTube, this);
|
||||||
cc.fx.Notifications.on("moveTube", _this.moveTube, _this);
|
// }, 100);
|
||||||
}, 100);
|
|
||||||
};
|
};
|
||||||
GameManager.prototype.onDisable = function () {
|
GameManager.prototype.onDisable = function () {
|
||||||
cc.fx.Notifications.off("moveTube", this.moveTube);
|
cc.fx.Notifications.off("moveTube", this.moveTube);
|
||||||
};
|
};
|
||||||
GameManager.prototype.update = function (dt) {
|
GameManager.prototype.update = function (dt) {
|
||||||
};
|
};
|
||||||
|
__decorate([
|
||||||
|
property(cc.Prefab)
|
||||||
|
], GameManager.prototype, "goal_Prefab", void 0);
|
||||||
|
__decorate([
|
||||||
|
property(cc.Prefab)
|
||||||
|
], GameManager.prototype, "middle_Prefab", void 0);
|
||||||
GameManager = __decorate([
|
GameManager = __decorate([
|
||||||
ccclass
|
ccclass
|
||||||
], GameManager);
|
], GameManager);
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -16,6 +16,17 @@ var __extends = (this && this.__extends) || (function () {
|
||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
var __assign = (this && this.__assign) || function () {
|
||||||
|
__assign = Object.assign || function(t) {
|
||||||
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||||
|
s = arguments[i];
|
||||||
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||||
|
t[p] = s[p];
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
return __assign.apply(this, arguments);
|
||||||
|
};
|
||||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||||
|
@ -69,17 +80,6 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
return _super !== null && _super.apply(this, arguments) || this;
|
||||||
}
|
}
|
||||||
HttpUtil_1 = HttpUtil;
|
HttpUtil_1 = HttpUtil;
|
||||||
HttpUtil.getShareInfo = function (shareUrl) {
|
|
||||||
return __awaiter(this, void 0, Promise, function () {
|
|
||||||
var time, url;
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
console.log("设置分享链接:", shareUrl);
|
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
|
||||||
url = HttpUtil_1.apiSign("/api/share/cfg?gameId=" + config.gameId + "&time=" + time + "&url=" + shareUrl, {});
|
|
||||||
return [2 /*return*/, this.post(url, null, null)];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
//排行榜
|
//排行榜
|
||||||
HttpUtil.rankData = function (type, callback, data) {
|
HttpUtil.rankData = function (type, callback, data) {
|
||||||
return __awaiter(this, void 0, Promise, function () {
|
return __awaiter(this, void 0, Promise, function () {
|
||||||
|
@ -87,7 +87,7 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
time = Math.floor((new Date().getTime()) / 1000);
|
||||||
url = HttpUtil_1.apiSign("/api/get/rank/data?gameId=" + config.gameId + "&dataType=" + type + "&time=" + time, data);
|
url = HttpUtil_1.apiSign("/api/get/rank/data?gameId=" + config.gameId + "&dataType=" + type + "&time=" + time, data);
|
||||||
this.post(url, data, callback);
|
this.post(url, data, callback, 0);
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -97,7 +97,7 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
var url;
|
var url;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
url = '/log/collect/data';
|
url = '/log/collect/data';
|
||||||
this.post(url, data, callback);
|
this.post(url, data, callback, 3);
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -109,17 +109,19 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
time = Math.floor((new Date().getTime()) / 1000);
|
||||||
url = HttpUtil_1.apiSign("/api/get/user/data?gameId=" + config.gameId + "&time=" + time, data);
|
url = HttpUtil_1.apiSign("/api/get/user/data?gameId=" + config.gameId + "&time=" + time, data);
|
||||||
this.post(url, data, callback);
|
this.post(url, data, callback, 0);
|
||||||
return [2 /*return*/];
|
return [2 /*return*/];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
HttpUtil.post = function (url, data, callback) {
|
HttpUtil.get = function (url, callback, count) {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var response;
|
var repeat, response;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0: return [4 /*yield*/, this.fetchData(url, data, 'POST')];
|
case 0:
|
||||||
|
repeat = count ? count : 0;
|
||||||
|
return [4 /*yield*/, this.fetchData(url, null, 'GET', repeat)];
|
||||||
case 1:
|
case 1:
|
||||||
response = _a.sent();
|
response = _a.sent();
|
||||||
callback && callback(response);
|
callback && callback(response);
|
||||||
|
@ -128,12 +130,14 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
HttpUtil.get = function (url, callback) {
|
HttpUtil.post = function (url, data, callback, count) {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var response;
|
var repeat, response;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0: return [4 /*yield*/, this.fetchData(url, null, 'GET')];
|
case 0:
|
||||||
|
repeat = count ? count : 0;
|
||||||
|
return [4 /*yield*/, this.fetchData(url, data, 'POST', repeat)];
|
||||||
case 1:
|
case 1:
|
||||||
response = _a.sent();
|
response = _a.sent();
|
||||||
callback && callback(response);
|
callback && callback(response);
|
||||||
|
@ -142,9 +146,10 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
HttpUtil.fetchData = function (url, data, method) {
|
HttpUtil.fetchData = function (url, data, method, repeat) {
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
var fullUrl, headers, options, response, error_1;
|
var fullUrl, headers, options, response, error_1, timeOut;
|
||||||
|
var _this = this;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -158,23 +163,58 @@ var HttpUtil = /** @class */ (function (_super) {
|
||||||
_a.label = 1;
|
_a.label = 1;
|
||||||
case 1:
|
case 1:
|
||||||
_a.trys.push([1, 4, , 5]);
|
_a.trys.push([1, 4, , 5]);
|
||||||
return [4 /*yield*/, fetch(fullUrl, options)];
|
return [4 /*yield*/, this.fetchWithTimeout(fullUrl, options)];
|
||||||
case 2:
|
case 2:
|
||||||
response = _a.sent();
|
response = _a.sent();
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("HTTP error! status: " + response.status);
|
throw new Error("HTTP_______________error! status: " + response.status);
|
||||||
}
|
}
|
||||||
return [4 /*yield*/, response.json()];
|
return [4 /*yield*/, response.json()];
|
||||||
case 3: return [2 /*return*/, _a.sent()];
|
case 3: return [2 /*return*/, _a.sent()];
|
||||||
case 4:
|
case 4:
|
||||||
error_1 = _a.sent();
|
error_1 = _a.sent();
|
||||||
console.error('Fetch error:', error_1);
|
console.error('Fetch_______________error:', error_1);
|
||||||
return [2 /*return*/, null];
|
if (repeat > 0) {
|
||||||
|
repeat -= 1;
|
||||||
|
timeOut = (3 - repeat) * 5000;
|
||||||
|
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0: return [4 /*yield*/, this.fetchData(url, data, method, repeat)];
|
||||||
|
case 1:
|
||||||
|
response = _a.sent();
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); }, timeOut);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [2 /*return*/, null];
|
||||||
|
}
|
||||||
|
return [3 /*break*/, 5];
|
||||||
case 5: return [2 /*return*/];
|
case 5: return [2 /*return*/];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
HttpUtil.fetchWithTimeout = function (resource, options) {
|
||||||
|
if (options === void 0) { options = {}; }
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var controller, id, response;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
controller = new AbortController();
|
||||||
|
id = setTimeout(function () { return controller.abort(); }, 5000);
|
||||||
|
return [4 /*yield*/, fetch(resource, __assign(__assign({}, options), { signal: controller.signal }))];
|
||||||
|
case 1:
|
||||||
|
response = _a.sent();
|
||||||
|
clearTimeout(id);
|
||||||
|
return [2 /*return*/, response];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param url {string} 接口地址
|
* @param url {string} 接口地址
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -115,7 +115,7 @@ var WeChat = /** @class */ (function () {
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
time = Math.floor((new Date().getTime()) / 1000);
|
time = Math.floor((new Date().getTime()) / 1000);
|
||||||
url = cc.fx.HttpUtil.apiSign("/api/share/cfg?gameId=" + shareConfig.gameId + "&time=" + time + "&url=" + shareUrl, {});
|
url = cc.fx.HttpUtil.apiSign("/api/share/cfg?gameId=" + shareConfig.gameId + "&time=" + time + "&url=" + shareUrl, {});
|
||||||
return [2 /*return*/, cc.fx.HttpUtil.get(url, callback)];
|
return [2 /*return*/, cc.fx.HttpUtil.get(url, callback, 0)];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
{"pid":404}
|
{"pid":15632}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user