136 lines
4.1 KiB
TypeScript
136 lines
4.1 KiB
TypeScript
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class NewClass extends cc.Component {
|
|
@property(cc.Label)
|
|
count: cc.Label = null;
|
|
@property(cc.Label)
|
|
time: cc.Label = null;
|
|
@property(cc.Node)
|
|
selfNode: cc.Node = null;
|
|
@property(cc.Node)
|
|
one: cc.Node = null;
|
|
@property(cc.Node)
|
|
two: cc.Node = null;
|
|
@property(cc.Node)
|
|
three: cc.Node = null;
|
|
@property(cc.Node)
|
|
four: cc.Node = null;
|
|
@property(cc.Node)
|
|
five: cc.Node = null;
|
|
listData: any;
|
|
selfData: any;
|
|
// onLoad () {}
|
|
start () {
|
|
this.count.string = cc.fx.GameConfig.GM_INFO.score + "";
|
|
var yes = 0;
|
|
var successList = cc.fx.GameConfig.GM_INFO.successList;
|
|
if(successList.length > 0){
|
|
var success = 0;
|
|
for(let i=0; i<successList.length; i++){
|
|
if(successList[i] == true) success += 1;
|
|
}
|
|
yes = success/successList.length;
|
|
}
|
|
yes = Math.floor(yes * 1000)/10;
|
|
this.time.string = yes + "%";
|
|
this.init();
|
|
}
|
|
//初始化数据
|
|
init(){
|
|
this.listData = [];
|
|
this.selfData = null;
|
|
this.one.active = false;
|
|
this.two.active = false;
|
|
this.three.active = false;
|
|
this.four.active = false;
|
|
this.five.active = false;
|
|
var urlNow = window.location.href;
|
|
if(this.containsTrain(urlNow)){
|
|
this.node.getChildByName("again").active = false;
|
|
this.node.getChildByName("back").active = false;
|
|
this.node.getChildByName("finishi").active = true;
|
|
}
|
|
else{
|
|
this.node.getChildByName("again").active = true;
|
|
this.node.getChildByName("back").active = true;
|
|
this.node.getChildByName("finishi").active = false;
|
|
}
|
|
this.getRank();
|
|
}
|
|
//打开排行榜
|
|
openRank(){
|
|
cc.director.loadScene("RankScene");
|
|
}
|
|
//重新开始玩
|
|
again(){
|
|
cc.fx.GameConfig.GM_INFO.round = 0;
|
|
cc.fx.GameConfig.GM_INFO.level = 0;
|
|
cc.fx.GameConfig.GM_INFO.stepTimeList = 0;
|
|
cc.fx.GameConfig.GM_INFO.successList = [];
|
|
cc.fx.GameConfig.GM_INFO.fen = 0;
|
|
cc.fx.GameConfig.GM_INFO.score = 0;
|
|
cc.fx.GameConfig.GM_INFO.min_Steps = 0;
|
|
cc.fx.GameConfig.GM_INFO.min_Time = 0;
|
|
cc.fx.GameConfig.TIME_INFO.totalTime = 120;
|
|
cc.director.loadScene("GameScene");
|
|
}
|
|
//判断来源
|
|
containsTrain(str) {
|
|
return /from=train/i.test(str);
|
|
}
|
|
//获取排行榜
|
|
getRank(){
|
|
//获取排行榜数据 所需数据量
|
|
let dataFile = {
|
|
length:5
|
|
}
|
|
cc.fx.GameTool.getRank(dataFile,data =>this.getRankData(data));
|
|
}
|
|
//打开排行榜
|
|
jumpFinishi(){
|
|
let url = "https://train.sparkus.cn/poster/game/";
|
|
window.location.href = url;
|
|
}
|
|
//设置排行信息
|
|
getRankData(data){
|
|
|
|
if(data){
|
|
cc.fx.GameTool.getRankData(data,this,4);
|
|
cc.fx.GameTool.setPic(this.selfNode.getChildByName("pic").getChildByName("icon"),this.selfData.pic);
|
|
var length = this.listData.length-1; if(length > 4) length = 4;
|
|
for(let i=0;i<=length;i++){
|
|
this.setRank(i,this.listData[i]);
|
|
}
|
|
}
|
|
}
|
|
//根据内容填充排行榜
|
|
setRank(num,data){
|
|
var hitNode = null;
|
|
if(num == 0){
|
|
hitNode = this.one;
|
|
}
|
|
else if(num == 1){
|
|
hitNode = this.two;
|
|
}
|
|
else if(num == 2){
|
|
hitNode = this.three;
|
|
}
|
|
else if(num == 3){
|
|
hitNode = this.four;
|
|
}
|
|
else if(num == 4){
|
|
hitNode = this.five;
|
|
}
|
|
if(hitNode){
|
|
hitNode.active = true;
|
|
if(data.nickName.length >= 4)
|
|
cc.fx.GameTool.subName(data.nickName,4);
|
|
hitNode.getChildByName("name").getComponent(cc.Label).string = data.nickName;
|
|
hitNode.getChildByName("total").getComponent(cc.Label).string = data.score;
|
|
cc.fx.GameTool.setPic(hitNode.getChildByName("pic").getChildByName("icon"),data.pic);
|
|
}
|
|
}
|
|
}
|