Преглед изворни кода

Merge branch 'qqplay-1.0' of http://svn.ouj.com:3000/DWG/budingGame into qqplay-1.0

Roy пре 5 година
родитељ
комит
b258f2ec23
3 измењених фајлова са 91 додато и 54 уклоњено
  1. 29 19
      assets/Script/Game/GameSence.js
  2. 28 35
      assets/Script/Home/HomeSence.js
  3. 34 0
      assets/Script/UserInfoJS.js

+ 29 - 19
assets/Script/Game/GameSence.js

@@ -244,23 +244,30 @@ cc.Class({
     gameOver: function () {
         var gameOverNode = this.node.getChildByName("GameOver");
         var historyScoreLabel = gameOverNode.getChildByName("EndNode").getChildByName("HistoryScoreLabel");
-        var newRecordSp = gameOverNode.getChildByName("EndNode").getChildByName("NewRecordSp");
-        if (this.sumScore > UserInfo.getHistoryScore()) {
-            newRecordSp.active = true;
-            UserInfo.setString("historyScore", this.sumScore);
-            cc.audioEngine.playEffect(this.newRecordAudio);
-            newRecordSp.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.5), cc.scaleTo(0.5, 1))));
-        } else {
-            newRecordSp.active = false;
-        }
-
-        if (this.sumScore > UserInfo.getScore()) {
-            UserInfo.setScore(this.sumScore);
-        }
-
-        historyScoreLabel.getComponent("cc.Label").string = "历史最高分:" + UserInfo.getHistoryScore();
-
-        UserInfo.addGold(this.sumScore);
+		var newRecordSp = gameOverNode.getChildByName("EndNode").getChildByName("NewRecordSp");
+		
+		UserInfo.getUserGameData((data) => {
+			var maxScore = data.maxScore || 0;
+			
+			if (this.sumScore > maxScore) {
+				maxScore = this.sumScore;
+				newRecordSp.active = true;
+				UserInfo.setUserGameData(this.sumScore);
+				
+				cc.audioEngine.playEffect(this.newRecordAudio);
+				newRecordSp.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.5), cc.scaleTo(0.5, 1))));
+			} else {
+				newRecordSp.active = false;
+			}
+	
+			if (this.sumScore > UserInfo.getScore()) {
+				UserInfo.setScore(this.sumScore);
+			}
+	
+			historyScoreLabel.getComponent("cc.Label").string = "历史最高分:" + maxScore;
+	
+			UserInfo.addGold(this.sumScore);
+		})
 
         // window.deadBanner.hide();
         // window.accountBanner.show();
@@ -292,6 +299,7 @@ cc.Class({
         this.node.runAction(cc.sequence(cc.delayTime(1), cc.callFunc(this.createObstacle, this), cc.delayTime(1), cc.callFunc(this.createObstacle, this)));
     },
 
+	// 创建障碍物
     createObstacle: function () {
         var obstacleType = this.randomObstacleType();
         //根据当前分数控制障碍物之间的高度
@@ -396,6 +404,7 @@ cc.Class({
         })
     },
 
+	// 随机生成障碍物类型
     randomObstacleType: function () {
         var obstacleType = 0;
         this.obstacleNum++;
@@ -446,6 +455,7 @@ cc.Class({
         return obstacleType;
     },
 
+	// 销毁障碍物
     destroyObstacle: function () {
         let obstacle1 = this.obstacleNode.getChildByName("obstacle1"),
             obstacle2 = this.obstacleNode.getChildByName("obstacle2"),
@@ -707,7 +717,7 @@ cc.Class({
 
     onShareBtn: function () {
         //接分享
-        if (CC_WECHATGAME && cc.vv.isRank) {
+        if (CC_QQPLAY) {
             var data = {
                 titleData: UserInfo.shareDesc,
                 imgurlData: UserInfo.shareUrl,
@@ -907,7 +917,7 @@ cc.Class({
 				}
 			},
 		};
-		
+
 		BK.QQ.uploadScoreWithoutRoom(1, data, function(errCode, cmd, data) {
 			// 返回错误码信息
 			if (errCode !== 0) {

+ 28 - 35
assets/Script/Home/HomeSence.js

@@ -46,16 +46,11 @@ cc.Class({
 		if(CC_QQPLAY && window.GameStatusInfo) {
 			GameStatusInfo.startMs = ((new Date()).getTime()).toString()
 		}
-        if (CC_WECHATGAME) {
-            // this.initShare();
-            // wx.setPreferredFramesPerSecond(30);
-			// this.listenGame();
-		}
 		
-		if (CC_QQPLAY) {
-			this.QQLogin();
-			this.initShare();
-		}
+		// if (CC_QQPLAY) {
+		// 	this.QQLogin();
+		// 	this.initShare();
+		// }
     },
 
     start() {
@@ -69,33 +64,33 @@ cc.Class({
     },
 
 	QQLogin() {
-		if(GameStatusInfo && GameStatusInfo.openId) {
+		if(window.GameStatusInfo && window.GameStatusInfo.openId) {
 			BK.Console.log('登录成功')
 		}
 	},
 
-    initShare(data) {
-        let datavalue = UserInfo.getString('allscore');
-        let key = UserInfo.getCurWeekScoreValue();
-        if (UserInfo.IsEmpty(datavalue)) {
-            UserInfo.setString('allscore', key);
-            return;
-        }
-        let datalist = datavalue.split('*');
-        let removeIndex = -1;
-        for (let index = 0; index < datalist.length; ++index) {
-            if (key == datalist[index]) {
-                // UserInfo.removeString(datalist[index]);
-                removeIndex = index;
-            }
-        }
-
-        if (removeIndex != -1) {
-            datalist.splice(removeIndex, 1);
-        }
-        // WxCommon.RemoveUserCloudStorage(datalist, this, this.RemoveScoreKey);
-        // this.RemoveScoreKey(datalist, true);
-    },
+    // initShare(data) {
+    //     let datavalue = UserInfo.getString('allscore');
+    //     let key = UserInfo.getCurWeekScoreValue();
+    //     if (UserInfo.IsEmpty(datavalue)) {
+    //         UserInfo.setString('allscore', key);
+    //         return;
+    //     }
+    //     let datalist = datavalue.split('*');
+    //     let removeIndex = -1;
+    //     for (let index = 0; index < datalist.length; ++index) {
+    //         if (key == datalist[index]) {
+    //             // UserInfo.removeString(datalist[index]);
+    //             removeIndex = index;
+    //         }
+    //     }
+
+    //     if (removeIndex != -1) {
+    //         datalist.splice(removeIndex, 1);
+    //     }
+    //     // WxCommon.RemoveUserCloudStorage(datalist, this, this.RemoveScoreKey);
+    //     // this.RemoveScoreKey(datalist, true);
+    // },
 
     // listenGame() {
 	// 	// var date = UserInfo.GetNowFormatDate();
@@ -183,9 +178,7 @@ cc.Class({
 
 
     update: function () {
-        // if (cc.find("Canvas/PHB").active) {
-        //     this.showRank();
-        // }
+        
     },
 
     onGameStartBtn: function () {

+ 34 - 0
assets/Script/UserInfoJS.js

@@ -19,6 +19,7 @@ window.UserInfo = {
 
 	GameCount : 2,
 
+	// 获取每周排行榜分数
 	getScore: function () {
 		let score = BK.localStorage.getItem('score');
 		return score ? parseInt(score) : 0;
@@ -228,6 +229,39 @@ window.UserInfo = {
 		return parseInt(score);
 	},
 	
+	// 获取用户保存在QQ轻游戏云端的数据
+	getUserGameData(callback) {
+		if(CC_QQPLAY) {
+			BK.QQ.loadGameData(function(errCode, cmd, data) {
+				// BK.UI.showAlert({
+				// 	title: 'loadGameData',
+				// 	content: JSON.stringify(data)
+				// })
+
+				callback && callback(data)
+			});
+		} else {
+			callback && callback({
+				maxScore: 0
+			})
+		}
+	},
+
+	// 设置用户在QQ轻游戏的云端数据
+	setUserGameData(score) {
+		var data = {
+			maxScore: score
+		}
+
+		// 保存个人数据
+		BK.QQ.saveGameData(data, function(errCode, cmd, data) {
+			// BK.UI.showAlert({
+			// 	title: 'saveGameData',
+			// 	content: JSON.stringify(data)
+			// })
+		});
+	},
+
 	getCurWeekScoreValue() {
 		return this.getNowFormatDate();
 	},