{ "sourceFile": "assets/scripts/Manager/GameManager.ts", "activeCommit": 0, "commits": [ { "activePatchIndex": 25, "patches": [ { "date": 1692861938334, "content": "Index: \n===================================================================\n--- \n+++ \n" }, { "date": 1692861956921, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,331 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager:UIManager=null;\r\n+ \r\n+ curLevel:number=1; //当前关卡\r\n+ curLevelScore:number=0; //当前关卡分数\r\n+ curLevelTime:number=0; //当前关卡所玩时间\r\n+ curLevelData:LevelData=null;\r\n+\r\n+ gameTotalTime:number=0; //游戏总的时间\r\n+ gameTotalScore:number=0; //游戏总分数\r\n+\r\n+ playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+ \r\n+ levelDifficulty=3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+ \r\n+ //游戏状态\r\n+ isPaused:boolean=false; \r\n+ isStartGame:boolean=false;\r\n+ @property(Label)\r\n+ textLabel:Label=null;\r\n+\r\n+ onLoad() {\r\n+ if(GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if(!Global.IsDevelop)\r\n+ {\r\n+ Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.playClass=this.getParameterByName('playClass');\r\n+ \r\n+ }\r\n+ console.log(' Global.GameCode:'+ Global.GameCode);\r\n+ \r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+ \r\n+ start() {\r\n+ this.timer=Global.GameSetTime;\r\n+ if(this.playClass==='A')\r\n+ {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+ \r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+ \r\n+ \r\n+ //开始计时\r\n+ startCountTime()\r\n+ {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if(this.isStartGame)\r\n+ {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame=false;\r\n+ //保存数据\r\n+ \r\n+ AudioManage.instance.pauseMusic();\r\n+ \r\n+ if(this.playClass==='A')\r\n+ {\r\n+ if( this.curLevelScore>this.curLevelData.targetScore)\r\n+ { \r\n+ this.saveDataToServer(0);\r\n+\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ \r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime()\r\n+ {\r\n+ this.timer=Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score:number)\r\n+ {\r\n+ this.curLevelScore+=score;\r\n+ this.gameTotalScore+=score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n+ {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if(this.playClass!=='A')\r\n+ {\r\n+ this.isStartGame=false;\r\n+ if(this.curLevel===Global.MaxLv)\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ \r\n+ }else{\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n+ \r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score:number)\r\n+ {\r\n+ this.curLevelScore-=score;\r\n+ this.gameTotalScore-=score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if( this.curLevelScore<=0)\r\n+ { \r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if(this.playClass!=='A'){\r\n+ this.isStartGame=false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n+\r\n+ }\r\n+ }\r\n+ \r\n+ }\r\n+ \r\n+ //进入下一关\r\n+ public NextLevel()\r\n+ {\r\n+ this.curLevel++;\r\n+ this.curLevelScore=0;\r\n+ this.curLevelTime=0\r\n+ this.resetCountTime();\r\n+ if(this.curLevel>Global.MaxLv)\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+ \r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ \r\n+ this.StartGame();\r\n+ }\r\n+ \r\n+ //开始游戏\r\n+ public StartGame()\r\n+ {\r\n+ this.isStartGame=true;\r\n+ const levelManager=LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+ \r\n+ public ContinueGame()\r\n+ { \r\n+ if(this.isPaused)\r\n+ {\r\n+ this.resumeGame();\r\n+ }else{\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused=true;\r\n+ this.isStartGame=false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused=false;\r\n+ this.isStartGame=true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage()\r\n+ {\r\n+ \r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame()\r\n+ {\r\n+ this.curLevelScore=0;\r\n+ this.curLevelTime=0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ \r\n+ public GameOver()\r\n+ {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame()\r\n+ {\r\n+ if(this.playClass==='A')\r\n+ {\r\n+ if( this.curLevelScore>this.curLevelData.targetScore)\r\n+ { \r\n+ this.saveDataToServer(0);\r\n+\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+ \r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass:number)\r\n+ {\r\n+ if(Global.IsDevelop){\r\n+ return;\r\n+ }\r\n+ const requestData=new SaveData();\r\n+ requestData.gameCode= Global.GameCode;\r\n+ requestData.gameLevel=this.curLevel;\r\n+ requestData.gameScore=this.curLevelScore;\r\n+ requestData.duration=this.curLevelTime;\r\n+ requestData.playClass= this.playClass;\r\n+ requestData.isPass=ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData=responseData as ResponseInfo;\r\n+ if(endData.success===false)\r\n+ {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+ \r\n+}\r\n+\r\n+\r\n" }, { "date": 1692862255489, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,332 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager:UIManager=null;\r\n+ \r\n+ curLevel:number=1; //当前关卡\r\n+ curLevelScore:number=0; //当前关卡分数\r\n+ curLevelTime:number=0; //当前关卡所玩时间\r\n+ curLevelData:LevelData=null;\r\n+\r\n+ gameTotalTime:number=0; //游戏总的时间\r\n+ gameTotalScore:number=0; //游戏总分数\r\n+\r\n+ playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+ \r\n+ levelDifficulty=3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+ \r\n+ //游戏状态\r\n+ isPaused:boolean=false; \r\n+ isStartGame:boolean=false;\r\n+ @property(Label)\r\n+ textLabel:Label=null;\r\n+\r\n+ onLoad() {\r\n+ if(GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if(!Global.IsDevelop)\r\n+ {\r\n+ Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel=1;\r\n+ this.playClass=this.getParameterByName('playClass');\r\n+ \r\n+ }\r\n+ console.log(' Global.GameCode:'+ Global.GameCode);\r\n+ \r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+ \r\n+ start() {\r\n+ this.timer=Global.GameSetTime;\r\n+ if(this.playClass==='A')\r\n+ {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+ \r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+ \r\n+ \r\n+ //开始计时\r\n+ startCountTime()\r\n+ {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if(this.isStartGame)\r\n+ {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame=false;\r\n+ //保存数据\r\n+ \r\n+ AudioManage.instance.pauseMusic();\r\n+ \r\n+ if(this.playClass==='A')\r\n+ {\r\n+ if( this.curLevelScore>this.curLevelData.targetScore)\r\n+ { \r\n+ this.saveDataToServer(0);\r\n+\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ \r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime()\r\n+ {\r\n+ this.timer=Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score:number)\r\n+ {\r\n+ this.curLevelScore+=score;\r\n+ this.gameTotalScore+=score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n+ {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if(this.playClass!=='A')\r\n+ {\r\n+ this.isStartGame=false;\r\n+ if(this.curLevel===Global.MaxLv)\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ \r\n+ }else{\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n+ \r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score:number)\r\n+ {\r\n+ this.curLevelScore-=score;\r\n+ this.gameTotalScore-=score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if( this.curLevelScore<=0)\r\n+ { \r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if(this.playClass!=='A'){\r\n+ this.isStartGame=false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n+\r\n+ }\r\n+ }\r\n+ \r\n+ }\r\n+ \r\n+ //进入下一关\r\n+ public NextLevel()\r\n+ {\r\n+ this.curLevel++;\r\n+ this.curLevelScore=0;\r\n+ this.curLevelTime=0\r\n+ this.resetCountTime();\r\n+ if(this.curLevel>Global.MaxLv)\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+ \r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ \r\n+ this.StartGame();\r\n+ }\r\n+ \r\n+ //开始游戏\r\n+ public StartGame()\r\n+ {\r\n+ this.isStartGame=true;\r\n+ const levelManager=LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+ \r\n+ public ContinueGame()\r\n+ { \r\n+ if(this.isPaused)\r\n+ {\r\n+ this.resumeGame();\r\n+ }else{\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused=true;\r\n+ this.isStartGame=false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused=false;\r\n+ this.isStartGame=true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage()\r\n+ {\r\n+ \r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame()\r\n+ {\r\n+ this.curLevelScore=0;\r\n+ this.curLevelTime=0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ \r\n+ public GameOver()\r\n+ {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame()\r\n+ {\r\n+ if(this.playClass==='A')\r\n+ {\r\n+ if( this.curLevelScore>this.curLevelData.targetScore)\r\n+ { \r\n+ this.saveDataToServer(0);\r\n+\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+ \r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass:number)\r\n+ {\r\n+ if(Global.IsDevelop){\r\n+ return;\r\n+ }\r\n+ const requestData=new SaveData();\r\n+ requestData.gameCode= Global.GameCode;\r\n+ requestData.gameLevel=this.curLevel;\r\n+ requestData.gameScore=this.curLevelScore;\r\n+ requestData.duration=this.curLevelTime;\r\n+ requestData.playClass= this.playClass;\r\n+ requestData.isPass=ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData=responseData as ResponseInfo;\r\n+ if(endData.success===false)\r\n+ {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+ \r\n+}\r\n+\r\n+\r\n" }, { "date": 1692862896684, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,333 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager:UIManager=null;\r\n+ \r\n+ curLevel:number=1; //当前关卡\r\n+ curLevelScore:number=0; //当前关卡分数\r\n+ curLevelTime:number=0; //当前关卡所玩时间\r\n+ curLevelData:LevelData=null;\r\n+\r\n+ gameTotalTime:number=0; //游戏总的时间\r\n+ gameTotalScore:number=0; //游戏总分数\r\n+\r\n+ playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+ \r\n+ levelDifficulty=3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+ \r\n+ //游戏状态\r\n+ isPaused:boolean=false; \r\n+ isStartGame:boolean=false;\r\n+ @property(Label)\r\n+ textLabel:Label=null;\r\n+\r\n+ onLoad() {\r\n+ if(GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if(!Global.IsDevelop)\r\n+ {\r\n+ Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel=1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass=\"0\";\r\n+ \r\n+ }\r\n+ console.log(' Global.GameCode:'+ Global.GameCode);\r\n+ \r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+ \r\n+ start() {\r\n+ this.timer=Global.GameSetTime;\r\n+ if(this.playClass==='A')\r\n+ {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+ \r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+ \r\n+ \r\n+ //开始计时\r\n+ startCountTime()\r\n+ {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if(this.isStartGame)\r\n+ {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame=false;\r\n+ //保存数据\r\n+ \r\n+ AudioManage.instance.pauseMusic();\r\n+ \r\n+ if(this.playClass==='A')\r\n+ {\r\n+ if( this.curLevelScore>this.curLevelData.targetScore)\r\n+ { \r\n+ this.saveDataToServer(0);\r\n+\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ \r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime()\r\n+ {\r\n+ this.timer=Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score:number)\r\n+ {\r\n+ this.curLevelScore+=score;\r\n+ this.gameTotalScore+=score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n+ {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if(this.playClass!=='A')\r\n+ {\r\n+ this.isStartGame=false;\r\n+ if(this.curLevel===Global.MaxLv)\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ \r\n+ }else{\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n+ \r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score:number)\r\n+ {\r\n+ this.curLevelScore-=score;\r\n+ this.gameTotalScore-=score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if( this.curLevelScore<=0)\r\n+ { \r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if(this.playClass!=='A'){\r\n+ this.isStartGame=false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n+\r\n+ }\r\n+ }\r\n+ \r\n+ }\r\n+ \r\n+ //进入下一关\r\n+ public NextLevel()\r\n+ {\r\n+ this.curLevel++;\r\n+ this.curLevelScore=0;\r\n+ this.curLevelTime=0\r\n+ this.resetCountTime();\r\n+ if(this.curLevel>Global.MaxLv)\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+ \r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ \r\n+ this.StartGame();\r\n+ }\r\n+ \r\n+ //开始游戏\r\n+ public StartGame()\r\n+ {\r\n+ this.isStartGame=true;\r\n+ const levelManager=LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+ \r\n+ public ContinueGame()\r\n+ { \r\n+ if(this.isPaused)\r\n+ {\r\n+ this.resumeGame();\r\n+ }else{\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused=true;\r\n+ this.isStartGame=false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame()\r\n+ {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused=false;\r\n+ this.isStartGame=true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage()\r\n+ {\r\n+ \r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame()\r\n+ {\r\n+ this.curLevelScore=0;\r\n+ this.curLevelTime=0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ \r\n+ public GameOver()\r\n+ {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame()\r\n+ {\r\n+ if(this.playClass==='A')\r\n+ {\r\n+ if( this.curLevelScore>this.curLevelData.targetScore)\r\n+ { \r\n+ this.saveDataToServer(0);\r\n+\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }else{\r\n+ this.saveDataToServer(1);\r\n+ \r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass:number)\r\n+ {\r\n+ if(Global.IsDevelop){\r\n+ return;\r\n+ }\r\n+ const requestData=new SaveData();\r\n+ requestData.gameCode= Global.GameCode;\r\n+ requestData.gameLevel=this.curLevel;\r\n+ requestData.gameScore=this.curLevelScore;\r\n+ requestData.duration=this.curLevelTime;\r\n+ requestData.playClass= this.playClass;\r\n+ requestData.isPass=ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData=responseData as ResponseInfo;\r\n+ if(endData.success===false)\r\n+ {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+ \r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863143337, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,305 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore > this.curLevelData[\"targetScore\"]) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863218599, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,305 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863276249, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -198,8 +198,9 @@\n this.isStartGame = true;\r\n const levelManager = LevelManager.getInstance();\r\n //得到当前关卡配置数据\r\n this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ console.log(\"============ 当前关卡数据 =\", this.curLevelData);\r\n this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n AudioManage.instance.playMusic();\r\n this.startCountTime();\r\n //开始游戏后处理生成游戏场景\r\n@@ -302,1636 +303,4 @@\n \r\n }\r\n \r\n \r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore > this.curLevelData[\"targetScore\"]) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager:UIManager=null;\r\n- \r\n- curLevel:number=1; //当前关卡\r\n- curLevelScore:number=0; //当前关卡分数\r\n- curLevelTime:number=0; //当前关卡所玩时间\r\n- curLevelData:LevelData=null;\r\n-\r\n- gameTotalTime:number=0; //游戏总的时间\r\n- gameTotalScore:number=0; //游戏总分数\r\n-\r\n- playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n- \r\n- levelDifficulty=3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n- \r\n- //游戏状态\r\n- isPaused:boolean=false; \r\n- isStartGame:boolean=false;\r\n- @property(Label)\r\n- textLabel:Label=null;\r\n-\r\n- onLoad() {\r\n- if(GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if(!Global.IsDevelop)\r\n- {\r\n- Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel=1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass=\"0\";\r\n- \r\n- }\r\n- console.log(' Global.GameCode:'+ Global.GameCode);\r\n- \r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n- \r\n- start() {\r\n- this.timer=Global.GameSetTime;\r\n- if(this.playClass==='A')\r\n- {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n- \r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n-   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n- \r\n- \r\n- //开始计时\r\n- startCountTime()\r\n- {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if(this.isStartGame)\r\n- {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame=false;\r\n- //保存数据\r\n- \r\n- AudioManage.instance.pauseMusic();\r\n- \r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- \r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime()\r\n- {\r\n- this.timer=Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score:number)\r\n- {\r\n- this.curLevelScore+=score;\r\n- this.gameTotalScore+=score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n- {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if(this.playClass!=='A')\r\n- {\r\n- this.isStartGame=false;\r\n- if(this.curLevel===Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- \r\n- }else{\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n- \r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score:number)\r\n- {\r\n- this.curLevelScore-=score;\r\n- this.gameTotalScore-=score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if( this.curLevelScore<=0)\r\n- { \r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if(this.playClass!=='A'){\r\n- this.isStartGame=false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n-\r\n- }\r\n- }\r\n- \r\n- }\r\n- \r\n- //进入下一关\r\n- public NextLevel()\r\n- {\r\n- this.curLevel++;\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- if(this.curLevel>Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n- \r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- \r\n- this.StartGame();\r\n- }\r\n- \r\n- //开始游戏\r\n- public StartGame()\r\n- {\r\n- this.isStartGame=true;\r\n- const levelManager=LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n- \r\n- public ContinueGame()\r\n- { \r\n- if(this.isPaused)\r\n- {\r\n- this.resumeGame();\r\n- }else{\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused=true;\r\n- this.isStartGame=false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused=false;\r\n- this.isStartGame=true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage()\r\n- {\r\n- \r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame()\r\n- {\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n- \r\n- public GameOver()\r\n- {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame()\r\n- {\r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- \r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass:number)\r\n- {\r\n- if(Global.IsDevelop){\r\n- return;\r\n- }\r\n- const requestData=new SaveData();\r\n- requestData.gameCode= Global.GameCode;\r\n- requestData.gameLevel=this.curLevel;\r\n- requestData.gameScore=this.curLevelScore;\r\n- requestData.duration=this.curLevelTime;\r\n- requestData.playClass= this.playClass;\r\n- requestData.isPass=ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData=responseData as ResponseInfo;\r\n- if(endData.success===false)\r\n- {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n- \r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager:UIManager=null;\r\n- \r\n- curLevel:number=1; //当前关卡\r\n- curLevelScore:number=0; //当前关卡分数\r\n- curLevelTime:number=0; //当前关卡所玩时间\r\n- curLevelData:LevelData=null;\r\n-\r\n- gameTotalTime:number=0; //游戏总的时间\r\n- gameTotalScore:number=0; //游戏总分数\r\n-\r\n- playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n- \r\n- levelDifficulty=3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n- \r\n- //游戏状态\r\n- isPaused:boolean=false; \r\n- isStartGame:boolean=false;\r\n- @property(Label)\r\n- textLabel:Label=null;\r\n-\r\n- onLoad() {\r\n- if(GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if(!Global.IsDevelop)\r\n- {\r\n- Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel=1;\r\n- this.playClass=this.getParameterByName('playClass');\r\n- \r\n- }\r\n- console.log(' Global.GameCode:'+ Global.GameCode);\r\n- \r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n- \r\n- start() {\r\n- this.timer=Global.GameSetTime;\r\n- if(this.playClass==='A')\r\n- {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n- \r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n-   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n- \r\n- \r\n- //开始计时\r\n- startCountTime()\r\n- {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if(this.isStartGame)\r\n- {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame=false;\r\n- //保存数据\r\n- \r\n- AudioManage.instance.pauseMusic();\r\n- \r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- \r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime()\r\n- {\r\n- this.timer=Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score:number)\r\n- {\r\n- this.curLevelScore+=score;\r\n- this.gameTotalScore+=score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n- {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if(this.playClass!=='A')\r\n- {\r\n- this.isStartGame=false;\r\n- if(this.curLevel===Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- \r\n- }else{\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n- \r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score:number)\r\n- {\r\n- this.curLevelScore-=score;\r\n- this.gameTotalScore-=score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if( this.curLevelScore<=0)\r\n- { \r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if(this.playClass!=='A'){\r\n- this.isStartGame=false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n-\r\n- }\r\n- }\r\n- \r\n- }\r\n- \r\n- //进入下一关\r\n- public NextLevel()\r\n- {\r\n- this.curLevel++;\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- if(this.curLevel>Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n- \r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- \r\n- this.StartGame();\r\n- }\r\n- \r\n- //开始游戏\r\n- public StartGame()\r\n- {\r\n- this.isStartGame=true;\r\n- const levelManager=LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n- \r\n- public ContinueGame()\r\n- { \r\n- if(this.isPaused)\r\n- {\r\n- this.resumeGame();\r\n- }else{\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused=true;\r\n- this.isStartGame=false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused=false;\r\n- this.isStartGame=true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage()\r\n- {\r\n- \r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame()\r\n- {\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n- \r\n- public GameOver()\r\n- {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame()\r\n- {\r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- \r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass:number)\r\n- {\r\n- if(Global.IsDevelop){\r\n- return;\r\n- }\r\n- const requestData=new SaveData();\r\n- requestData.gameCode= Global.GameCode;\r\n- requestData.gameLevel=this.curLevel;\r\n- requestData.gameScore=this.curLevelScore;\r\n- requestData.duration=this.curLevelTime;\r\n- requestData.playClass= this.playClass;\r\n- requestData.isPass=ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData=responseData as ResponseInfo;\r\n- if(endData.success===false)\r\n- {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n- \r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager:UIManager=null;\r\n- \r\n- curLevel:number=1; //当前关卡\r\n- curLevelScore:number=0; //当前关卡分数\r\n- curLevelTime:number=0; //当前关卡所玩时间\r\n- curLevelData:LevelData=null;\r\n-\r\n- gameTotalTime:number=0; //游戏总的时间\r\n- gameTotalScore:number=0; //游戏总分数\r\n-\r\n- playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n- \r\n- levelDifficulty=3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n- \r\n- //游戏状态\r\n- isPaused:boolean=false; \r\n- isStartGame:boolean=false;\r\n- @property(Label)\r\n- textLabel:Label=null;\r\n-\r\n- onLoad() {\r\n- if(GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if(!Global.IsDevelop)\r\n- {\r\n- Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.playClass=this.getParameterByName('playClass');\r\n- \r\n- }\r\n- console.log(' Global.GameCode:'+ Global.GameCode);\r\n- \r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n- \r\n- start() {\r\n- this.timer=Global.GameSetTime;\r\n- if(this.playClass==='A')\r\n- {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n- \r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n-   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n- \r\n- \r\n- //开始计时\r\n- startCountTime()\r\n- {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if(this.isStartGame)\r\n- {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame=false;\r\n- //保存数据\r\n- \r\n- AudioManage.instance.pauseMusic();\r\n- \r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- \r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime()\r\n- {\r\n- this.timer=Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score:number)\r\n- {\r\n- this.curLevelScore+=score;\r\n- this.gameTotalScore+=score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n- {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if(this.playClass!=='A')\r\n- {\r\n- this.isStartGame=false;\r\n- if(this.curLevel===Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- \r\n- }else{\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n- \r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score:number)\r\n- {\r\n- this.curLevelScore-=score;\r\n- this.gameTotalScore-=score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if( this.curLevelScore<=0)\r\n- { \r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if(this.playClass!=='A'){\r\n- this.isStartGame=false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n-\r\n- }\r\n- }\r\n- \r\n- }\r\n- \r\n- //进入下一关\r\n- public NextLevel()\r\n- {\r\n- this.curLevel++;\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- if(this.curLevel>Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n- \r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- \r\n- this.StartGame();\r\n- }\r\n- \r\n- //开始游戏\r\n- public StartGame()\r\n- {\r\n- this.isStartGame=true;\r\n- const levelManager=LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n- \r\n- public ContinueGame()\r\n- { \r\n- if(this.isPaused)\r\n- {\r\n- this.resumeGame();\r\n- }else{\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused=true;\r\n- this.isStartGame=false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused=false;\r\n- this.isStartGame=true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage()\r\n- {\r\n- \r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame()\r\n- {\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n- \r\n- public GameOver()\r\n- {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame()\r\n- {\r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- \r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass:number)\r\n- {\r\n- if(Global.IsDevelop){\r\n- return;\r\n- }\r\n- const requestData=new SaveData();\r\n- requestData.gameCode= Global.GameCode;\r\n- requestData.gameLevel=this.curLevel;\r\n- requestData.gameScore=this.curLevelScore;\r\n- requestData.duration=this.curLevelTime;\r\n- requestData.playClass= this.playClass;\r\n- requestData.isPass=ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData=responseData as ResponseInfo;\r\n- if(endData.success===false)\r\n- {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n- \r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager:UIManager=null;\r\n- \r\n- curLevel:number=1; //当前关卡\r\n- curLevelScore:number=0; //当前关卡分数\r\n- curLevelTime:number=0; //当前关卡所玩时间\r\n- curLevelData:LevelData=null;\r\n-\r\n- gameTotalTime:number=0; //游戏总的时间\r\n- gameTotalScore:number=0; //游戏总分数\r\n-\r\n- playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n- \r\n- levelDifficulty=3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n- \r\n- //游戏状态\r\n- isPaused:boolean=false; \r\n- isStartGame:boolean=false;\r\n- @property(Label)\r\n- textLabel:Label=null;\r\n-\r\n- onLoad() {\r\n- if(GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if(!Global.IsDevelop)\r\n- {\r\n- Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.playClass=this.getParameterByName('playClass');\r\n- \r\n- }\r\n- console.log(' Global.GameCode:'+ Global.GameCode);\r\n- \r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n- \r\n- start() {\r\n- this.timer=Global.GameSetTime;\r\n- if(this.playClass==='A')\r\n- {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n- \r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n-   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n- \r\n- \r\n- //开始计时\r\n- startCountTime()\r\n- {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if(this.isStartGame)\r\n- {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame=false;\r\n- //保存数据\r\n- \r\n- AudioManage.instance.pauseMusic();\r\n- \r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- \r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime()\r\n- {\r\n- this.timer=Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score:number)\r\n- {\r\n- this.curLevelScore+=score;\r\n- this.gameTotalScore+=score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n- {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if(this.playClass!=='A')\r\n- {\r\n- this.isStartGame=false;\r\n- if(this.curLevel===Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- \r\n- }else{\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n- \r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score:number)\r\n- {\r\n- this.curLevelScore-=score;\r\n- this.gameTotalScore-=score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if( this.curLevelScore<=0)\r\n- { \r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if(this.playClass!=='A'){\r\n- this.isStartGame=false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n-\r\n- }\r\n- }\r\n- \r\n- }\r\n- \r\n- //进入下一关\r\n- public NextLevel()\r\n- {\r\n- this.curLevel++;\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- if(this.curLevel>Global.MaxLv)\r\n- {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n- \r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- \r\n- this.StartGame();\r\n- }\r\n- \r\n- //开始游戏\r\n- public StartGame()\r\n- {\r\n- this.isStartGame=true;\r\n- const levelManager=LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n- \r\n- public ContinueGame()\r\n- { \r\n- if(this.isPaused)\r\n- {\r\n- this.resumeGame();\r\n- }else{\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused=true;\r\n- this.isStartGame=false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame()\r\n- {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused=false;\r\n- this.isStartGame=true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage()\r\n- {\r\n- \r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame()\r\n- {\r\n- this.curLevelScore=0;\r\n- this.curLevelTime=0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n- \r\n- public GameOver()\r\n- {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame()\r\n- {\r\n- if(this.playClass==='A')\r\n- {\r\n- if( this.curLevelScore>this.curLevelData.targetScore)\r\n- { \r\n- this.saveDataToServer(0);\r\n-\r\n- }else{\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }else{\r\n- this.saveDataToServer(1);\r\n- \r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass:number)\r\n- {\r\n- if(Global.IsDevelop){\r\n- return;\r\n- }\r\n- const requestData=new SaveData();\r\n- requestData.gameCode= Global.GameCode;\r\n- requestData.gameLevel=this.curLevel;\r\n- requestData.gameScore=this.curLevelScore;\r\n- requestData.duration=this.curLevelTime;\r\n- requestData.playClass= this.playClass;\r\n- requestData.isPass=ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData=responseData as ResponseInfo;\r\n- if(endData.success===false)\r\n- {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n- \r\n-}\r\n-\r\n-\r\n" }, { "date": 1692863327527, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,305 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863346383, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,305 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863686297, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,307 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ \r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863738683, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,306 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863966899, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,308 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692863967302, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -305,1533 +305,4 @@\n \r\n }\r\n \r\n \r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- \r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- console.log(\"============ 当前关卡数据 =\", this.curLevelData);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n" }, { "date": 1692865049808, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,308 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ // this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692865050048, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,308 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ // this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692865055758, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -183,319 +183,11 @@\n \r\n this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n this.unscheduleAllCallbacks();\r\n- // this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n this.StartGame();\r\n- }\r\n \r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-import { EventUtils } from '../Game/EventUtils';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- // this.StartGame();\r\n-\r\n- }\r\n //进入游戏场景\r\n public EnterGameScene() {\r\n this.uiManager.showPanel(PanelType.GamePanel);\r\n this.uiManager.hidePanel(PanelType.StartPanel);\r\n@@ -613,312 +305,4 @@\n \r\n }\r\n \r\n \r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-import { EventUtils } from '../Game/EventUtils';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n" }, { "date": 1692865056056, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,308 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692868933788, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,309 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ console.log(\"============ results =\", results);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692868944717, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,309 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n+ // this.curLevel = 1;\r\n+ // this.playClass=this.getParameterByName('playClass');\r\n+ this.playClass = \"0\";\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ console.log(\"============ results =\", results);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692869254032, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,307 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel=parseInt(this.getParameterByName('gameLevel')) || 1; //得到游戏初始关卡\r\n+ this.playClass=this.getParameterByName('playClass');\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ console.log(\"============ results =\", results);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692869254502, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -304,1238 +304,4 @@\n \r\n }\r\n \r\n \r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-import { EventUtils } from '../Game/EventUtils';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- // this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- console.log(\"============ results =\", results);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-import { EventUtils } from '../Game/EventUtils';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- console.log(\"============ results =\", results);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-import { EventUtils } from '../Game/EventUtils';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-import { EventUtils } from '../Game/EventUtils';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- // this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n- this.curLevel = 1;\r\n- // this.playClass=this.getParameterByName('playClass');\r\n- this.playClass = \"0\";\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n" }, { "date": 1692869332290, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,306 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel=parseInt(this.getParameterByName('gameLevel')) || 1; //得到游戏初始关卡\r\n+ this.playClass=this.getParameterByName('playClass');\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692869332720, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -303,311 +303,4 @@\n \r\n }\r\n \r\n \r\n-import { _decorator, Component, Label, Node } from 'cc';\r\n-const { ccclass, property } = _decorator;\r\n-import { PanelType, UIManager } from './UIManager';\r\n-import LevelData from '../Data/LevelData';\r\n-import LevelManager from './LevelManager';\r\n-import { Global } from '../Common/Global';\r\n-import { AudioManage } from './AudioManage';\r\n-import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n-import { HttpManager } from './HttpManager';\r\n-import { MainGame } from '../MainGame';\r\n-import { EventUtils } from '../Game/EventUtils';\r\n-\r\n-@ccclass('GameManager')\r\n-export class GameManager extends Component {\r\n- private static _instance: GameManager = null;\r\n- static getInstance(): GameManager {\r\n- return GameManager._instance;\r\n- }\r\n-\r\n- @property(UIManager)\r\n- uiManager: UIManager = null;\r\n-\r\n- curLevel: number = 1; //当前关卡\r\n- curLevelScore: number = 0; //当前关卡分数\r\n- curLevelTime: number = 0; //当前关卡所玩时间\r\n- curLevelData: LevelData = null;\r\n-\r\n- gameTotalTime: number = 0; //游戏总的时间\r\n- gameTotalScore: number = 0; //游戏总分数\r\n-\r\n- playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n-\r\n- levelDifficulty = 3; //游戏难度\r\n- timer: number = 0; // 2分钟,单位为秒\r\n-\r\n- //游戏状态\r\n- isPaused: boolean = false;\r\n- isStartGame: boolean = false;\r\n- @property(Label)\r\n- textLabel: Label = null;\r\n-\r\n- onLoad() {\r\n- if (GameManager._instance) {\r\n- this.node.destroy();\r\n- return;\r\n- }\r\n- GameManager._instance = this;\r\n- if (!Global.IsDevelop) {\r\n- Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n- Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n- this.curLevel=parseInt(this.getParameterByName('gameLevel')) || 1; //得到游戏初始关卡\r\n- this.playClass=this.getParameterByName('playClass');\r\n-\r\n- }\r\n- console.log(' Global.GameCode:' + Global.GameCode);\r\n-\r\n- //this.textLabel.string=Global.GameCode.toString();\r\n- }\r\n-\r\n- start() {\r\n- this.timer = Global.GameSetTime;\r\n- if (this.playClass === 'A') {\r\n- this.uiManager.gamePanel.hideLevelUi();\r\n- }\r\n-\r\n- }\r\n-\r\n- update(deltaTime: number) {\r\n-\r\n- }\r\n- //初始化\r\n- initialize() {\r\n-\r\n- }\r\n-\r\n- //得到url参数值\r\n- getParameterByName(name) {\r\n- let url = window.location.href;\r\n- name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n- let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n- results = regex.exec(url);\r\n- console.log(\"============ results =\", results);\r\n- if (!results) return null;\r\n- if (!results[2]) return '';\r\n- return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n- }\r\n-\r\n-\r\n- //开始计时\r\n- startCountTime() {\r\n- this.schedule(this.updateTimer, 1);\r\n- }\r\n-\r\n- updateTimer() {\r\n- if (this.isStartGame) {\r\n- this.timer--;\r\n- this.uiManager.gamePanel.RefreshTime(this.timer);\r\n- this.curLevelTime++;\r\n- this.gameTotalTime++;\r\n- if (this.timer <= 0) {\r\n- this.unschedule(this.updateTimer);\r\n- this.isStartGame = false;\r\n- //保存数据\r\n-\r\n- AudioManage.instance.pauseMusic();\r\n-\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n-\r\n- this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n- } else {\r\n- this.saveDataToServer(1);\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n- }\r\n- // 倒计时结束游戏失败\r\n- }\r\n- }\r\n- }\r\n- //重置时间\r\n- resetCountTime() {\r\n- this.timer = Global.GameSetTime;;\r\n- }\r\n-\r\n- //加分\r\n- addScore(score: number) {\r\n- this.curLevelScore += score;\r\n- this.gameTotalScore += score;\r\n- //当前分数大于关卡目标分数进入下一关\r\n- if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n- //保存数据\r\n- this.saveDataToServer(0);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- if (this.curLevel === Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n-\r\n- } else {\r\n- console.log(\"=========== 进入下一关\");\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n-\r\n- }\r\n- }\r\n- }\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- }\r\n- //减分\r\n- minusScore(score: number) {\r\n- this.curLevelScore -= score;\r\n- this.gameTotalScore -= score;\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- if (this.curLevelScore <= 0) {\r\n- //保存数据\r\n- this.saveDataToServer(1);\r\n- if (this.playClass !== 'A') {\r\n- this.isStartGame = false;\r\n- //游戏失败\r\n- this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n-\r\n- }\r\n- }\r\n-\r\n- }\r\n-\r\n- //进入下一关\r\n- public NextLevel() {\r\n- this.curLevel++;\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- if (this.curLevel > Global.MaxLv) {\r\n- this.uiManager.showPanel(PanelType.EndPanel);\r\n- this.GameOver();\r\n- return;\r\n- }\r\n-\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- this.unscheduleAllCallbacks();\r\n- this.StartGame();\r\n-\r\n- }\r\n- //进入游戏场景\r\n- public EnterGameScene() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n-\r\n- this.StartGame();\r\n- }\r\n-\r\n- //开始游戏\r\n- public StartGame() {\r\n- this.isStartGame = true;\r\n- const levelManager = LevelManager.getInstance();\r\n- //得到当前关卡配置数据\r\n- this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n- this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n- AudioManage.instance.playMusic();\r\n- this.startCountTime();\r\n- //开始游戏后处理生成游戏场景\r\n- EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n- }\r\n-\r\n- public ContinueGame() {\r\n- if (this.isPaused) {\r\n- this.resumeGame();\r\n- } else {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.RestartGame();\r\n- }\r\n-\r\n- }\r\n- //暂停游戏\r\n- public PauseGame() {\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.isPaused = true;\r\n- this.isStartGame = false;\r\n- AudioManage.instance.pauseMusic();\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n- //暂停后处理游戏内暂停\r\n- }\r\n- //继续游戏\r\n- public resumeGame() {\r\n- this.uiManager.showPanel(PanelType.GamePanel);\r\n- this.isPaused = false;\r\n- this.isStartGame = true;\r\n- AudioManage.instance.playMusic();\r\n- this.uiManager.hidePanel(PanelType.StartPanel);\r\n- //继续游戏后处理游戏内继续游戏\r\n- }\r\n-\r\n- //返回首页\r\n- public BackHomePage() {\r\n-\r\n- this.uiManager.showPanel(PanelType.StartPanel);\r\n- this.uiManager.hidePanel(PanelType.GamePanel);\r\n-\r\n- //返回首页相当于暂时退出游戏 需处理清空游戏\r\n-\r\n- }\r\n- //重新开始\r\n- public RestartGame() {\r\n- this.curLevelScore = 0;\r\n- this.curLevelTime = 0\r\n- this.resetCountTime();\r\n- this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n- AudioManage.instance.playMusic();\r\n- //处理清空游戏\r\n- this.StartGame();\r\n- }\r\n-\r\n-\r\n- public GameOver() {\r\n- this.unscheduleAllCallbacks();\r\n- AudioManage.instance.pauseMusic();\r\n- }\r\n- quitGame() {\r\n- if (this.playClass === 'A') {\r\n- if (this.curLevelScore > this.curLevelData.targetScore) {\r\n- this.saveDataToServer(0);\r\n-\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- } else {\r\n- this.saveDataToServer(1);\r\n-\r\n- }\r\n- }\r\n-\r\n- //保存游戏数据到服务器\r\n- saveDataToServer(ispass: number) {\r\n- if (Global.IsDevelop) {\r\n- return;\r\n- }\r\n- const requestData = new SaveData();\r\n- requestData.gameCode = Global.GameCode;\r\n- requestData.gameLevel = this.curLevel;\r\n- requestData.gameScore = this.curLevelScore;\r\n- requestData.duration = this.curLevelTime;\r\n- requestData.playClass = this.playClass;\r\n- requestData.isPass = ispass;\r\n- const jsonRequestData = JSON.stringify(requestData);\r\n-\r\n- HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n- .then(responseData => {\r\n- const endData = responseData as ResponseInfo;\r\n- if (endData.success === false) {\r\n- console.log('请求失败');\r\n- }\r\n- console.log(responseData);\r\n- })\r\n- .catch(error => {\r\n- console.error(error);\r\n- });\r\n- }\r\n-\r\n-}\r\n-\r\n-\r\n" }, { "date": 1692869389782, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,306 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel=parseInt(this.getParameterByName('gameLevel')) || 1; //得到游戏初始关卡\r\n+ this.playClass=this.getParameterByName('playClass');\r\n+\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692869513756, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,305 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel = parseInt(this.getParameterByName('gameLevel')) || 1; //得到游戏初始关卡\r\n+ this.playClass = this.getParameterByName('playClass');\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" }, { "date": 1692869879956, "content": "Index: \n===================================================================\n--- \n+++ \n@@ -0,0 +1,305 @@\n+import { _decorator, Component, Label, Node } from 'cc';\r\n+const { ccclass, property } = _decorator;\r\n+import { PanelType, UIManager } from './UIManager';\r\n+import LevelData from '../Data/LevelData';\r\n+import LevelManager from './LevelManager';\r\n+import { Global } from '../Common/Global';\r\n+import { AudioManage } from './AudioManage';\r\n+import { ResponseInfo, SaveData } from '../Data/SaveData';\r\n+import { HttpManager } from './HttpManager';\r\n+import { MainGame } from '../MainGame';\r\n+import { EventUtils } from '../Game/EventUtils';\r\n+\r\n+@ccclass('GameManager')\r\n+export class GameManager extends Component {\r\n+ private static _instance: GameManager = null;\r\n+ static getInstance(): GameManager {\r\n+ return GameManager._instance;\r\n+ }\r\n+\r\n+ @property(UIManager)\r\n+ uiManager: UIManager = null;\r\n+\r\n+ curLevel: number = 1; //当前关卡\r\n+ curLevelScore: number = 0; //当前关卡分数\r\n+ curLevelTime: number = 0; //当前关卡所玩时间\r\n+ curLevelData: LevelData = null;\r\n+\r\n+ gameTotalTime: number = 0; //游戏总的时间\r\n+ gameTotalScore: number = 0; //游戏总分数\r\n+\r\n+ playClass: string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n+\r\n+ levelDifficulty = 3; //游戏难度\r\n+ timer: number = 0; // 2分钟,单位为秒\r\n+\r\n+ //游戏状态\r\n+ isPaused: boolean = false;\r\n+ isStartGame: boolean = false;\r\n+ @property(Label)\r\n+ textLabel: Label = null;\r\n+\r\n+ onLoad() {\r\n+ if (GameManager._instance) {\r\n+ this.node.destroy();\r\n+ return;\r\n+ }\r\n+ GameManager._instance = this;\r\n+ if (!Global.IsDevelop) {\r\n+ Global.Net_UserToken = this.getParameterByName('userToken'); //得到usertoken\r\n+ Global.GameCode = parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n+ this.curLevel = parseInt(this.getParameterByName('gameLevel')) || 1; //得到游戏初始关卡\r\n+ this.playClass = this.getParameterByName('playClass');\r\n+ }\r\n+ console.log(' Global.GameCode:' + Global.GameCode);\r\n+\r\n+ //this.textLabel.string=Global.GameCode.toString();\r\n+ }\r\n+\r\n+ start() {\r\n+ this.timer = Global.GameSetTime;\r\n+ if (this.playClass === 'A') {\r\n+ this.uiManager.gamePanel.hideLevelUi();\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ update(deltaTime: number) {\r\n+\r\n+ }\r\n+ //初始化\r\n+ initialize() {\r\n+\r\n+ }\r\n+\r\n+ //得到url参数值\r\n+ getParameterByName(name) {\r\n+ let url = window.location.href;\r\n+ name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n+ let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n+ results = regex.exec(url);\r\n+ if (!results) return null;\r\n+ if (!results[2]) return '';\r\n+ return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n+ }\r\n+\r\n+\r\n+ //开始计时\r\n+ startCountTime() {\r\n+ this.schedule(this.updateTimer, 1);\r\n+ }\r\n+\r\n+ updateTimer() {\r\n+ if (this.isStartGame) {\r\n+ this.timer--;\r\n+ this.uiManager.gamePanel.RefreshTime(this.timer);\r\n+ this.curLevelTime++;\r\n+ this.gameTotalTime++;\r\n+ if (this.timer <= 0) {\r\n+ this.unschedule(this.updateTimer);\r\n+ this.isStartGame = false;\r\n+ //保存数据\r\n+\r\n+ AudioManage.instance.pauseMusic();\r\n+\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+ }\r\n+ // 倒计时结束游戏失败\r\n+ }\r\n+ }\r\n+ }\r\n+ //重置时间\r\n+ resetCountTime() {\r\n+ this.timer = Global.GameSetTime;;\r\n+ }\r\n+\r\n+ //加分\r\n+ addScore(score: number) {\r\n+ this.curLevelScore += score;\r\n+ this.gameTotalScore += score;\r\n+ //当前分数大于关卡目标分数进入下一关\r\n+ if (this.curLevelScore >= this.curLevelData.targetScore) {\r\n+ //保存数据\r\n+ this.saveDataToServer(0);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ if (this.curLevel === Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+\r\n+ } else {\r\n+ console.log(\"=========== 进入下一关\");\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, true);\r\n+\r\n+ }\r\n+ }\r\n+ }\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ }\r\n+ //减分\r\n+ minusScore(score: number) {\r\n+ this.curLevelScore -= score;\r\n+ this.gameTotalScore -= score;\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ if (this.curLevelScore <= 0) {\r\n+ //保存数据\r\n+ this.saveDataToServer(1);\r\n+ if (this.playClass !== 'A') {\r\n+ this.isStartGame = false;\r\n+ //游戏失败\r\n+ this.uiManager.gamePanel.showGameEndTip(this.curLevel, this.curLevelScore, this.gameTotalScore, false);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ }\r\n+\r\n+ //进入下一关\r\n+ public NextLevel() {\r\n+ this.curLevel++;\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ if (this.curLevel > Global.MaxLv) {\r\n+ this.uiManager.showPanel(PanelType.EndPanel);\r\n+ this.GameOver();\r\n+ return;\r\n+ }\r\n+\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ this.unscheduleAllCallbacks();\r\n+ this.StartGame();\r\n+\r\n+ }\r\n+ //进入游戏场景\r\n+ public EnterGameScene() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+ //开始游戏\r\n+ public StartGame() {\r\n+ this.isStartGame = true;\r\n+ const levelManager = LevelManager.getInstance();\r\n+ //得到当前关卡配置数据\r\n+ this.curLevelData = levelManager.getLevelData(this.curLevel);\r\n+ this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n+ AudioManage.instance.playMusic();\r\n+ this.startCountTime();\r\n+ //开始游戏后处理生成游戏场景\r\n+ EventUtils.dispatchEvent(\"GameStart\", this.curLevelData);\r\n+ }\r\n+\r\n+ public ContinueGame() {\r\n+ if (this.isPaused) {\r\n+ this.resumeGame();\r\n+ } else {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.RestartGame();\r\n+ }\r\n+\r\n+ }\r\n+ //暂停游戏\r\n+ public PauseGame() {\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.isPaused = true;\r\n+ this.isStartGame = false;\r\n+ AudioManage.instance.pauseMusic();\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+ //暂停后处理游戏内暂停\r\n+ }\r\n+ //继续游戏\r\n+ public resumeGame() {\r\n+ this.uiManager.showPanel(PanelType.GamePanel);\r\n+ this.isPaused = false;\r\n+ this.isStartGame = true;\r\n+ AudioManage.instance.playMusic();\r\n+ this.uiManager.hidePanel(PanelType.StartPanel);\r\n+ //继续游戏后处理游戏内继续游戏\r\n+ }\r\n+\r\n+ //返回首页\r\n+ public BackHomePage() {\r\n+\r\n+ this.uiManager.showPanel(PanelType.StartPanel);\r\n+ this.uiManager.hidePanel(PanelType.GamePanel);\r\n+\r\n+ //返回首页相当于暂时退出游戏 需处理清空游戏\r\n+\r\n+ }\r\n+ //重新开始\r\n+ public RestartGame() {\r\n+ this.curLevelScore = 0;\r\n+ this.curLevelTime = 0\r\n+ this.resetCountTime();\r\n+ this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n+ AudioManage.instance.playMusic();\r\n+ //处理清空游戏\r\n+ this.StartGame();\r\n+ }\r\n+\r\n+\r\n+ public GameOver() {\r\n+ this.unscheduleAllCallbacks();\r\n+ AudioManage.instance.pauseMusic();\r\n+ }\r\n+ quitGame() {\r\n+ if (this.playClass === 'A') {\r\n+ if (this.curLevelScore > this.curLevelData.targetScore) {\r\n+ this.saveDataToServer(0);\r\n+\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ } else {\r\n+ this.saveDataToServer(1);\r\n+\r\n+ }\r\n+ }\r\n+\r\n+ //保存游戏数据到服务器\r\n+ saveDataToServer(ispass: number) {\r\n+ if (Global.IsDevelop) {\r\n+ return;\r\n+ }\r\n+ const requestData = new SaveData();\r\n+ requestData.gameCode = Global.GameCode;\r\n+ requestData.gameLevel = this.curLevel;\r\n+ requestData.gameScore = this.curLevelScore;\r\n+ requestData.duration = this.curLevelTime;\r\n+ requestData.playClass = this.playClass;\r\n+ requestData.isPass = ispass;\r\n+ const jsonRequestData = JSON.stringify(requestData);\r\n+\r\n+ HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n+ .then(responseData => {\r\n+ const endData = responseData as ResponseInfo;\r\n+ if (endData.success === false) {\r\n+ console.log('请求失败');\r\n+ }\r\n+ console.log(responseData);\r\n+ })\r\n+ .catch(error => {\r\n+ console.error(error);\r\n+ });\r\n+ }\r\n+\r\n+}\r\n+\r\n+\r\n" } ], "date": 1692861938334, "name": "Commit-0", "content": "import { _decorator, Component, Label, Node } from 'cc';\r\nconst { ccclass, property } = _decorator;\r\nimport { PanelType, UIManager } from './UIManager';\r\nimport LevelData from '../Data/LevelData';\r\nimport LevelManager from './LevelManager';\r\nimport { Global } from '../Common/Global';\r\nimport { AudioManage } from './AudioManage';\r\nimport { ResponseInfo, SaveData } from '../Data/SaveData';\r\nimport { HttpManager } from './HttpManager';\r\n\r\n@ccclass('GameManager')\r\nexport class GameManager extends Component {\r\n private static _instance: GameManager = null;\r\n static getInstance(): GameManager {\r\n return GameManager._instance;\r\n }\r\n\r\n @property(UIManager)\r\n uiManager:UIManager=null;\r\n \r\n curLevel:number=1; //当前关卡\r\n curLevelScore:number=0; //当前关卡分数\r\n curLevelTime:number=0; //当前关卡所玩时间\r\n curLevelData:LevelData=null;\r\n\r\n gameTotalTime:number=0; //游戏总的时间\r\n gameTotalScore:number=0; //游戏总分数\r\n\r\n playClass:string; //关卡分类 0代表可以继续下一关1代表只有1关\r\n \r\n levelDifficulty=3; //游戏难度\r\n timer: number = 0; // 2分钟,单位为秒\r\n \r\n //游戏状态\r\n isPaused:boolean=false; \r\n isStartGame:boolean=false;\r\n @property(Label)\r\n textLabel:Label=null;\r\n\r\n onLoad() {\r\n if(GameManager._instance) {\r\n this.node.destroy();\r\n return;\r\n }\r\n GameManager._instance = this;\r\n if(!Global.IsDevelop)\r\n {\r\n Global.Net_UserToken=this.getParameterByName('userToken'); //得到usertoken\r\n Global.GameCode=parseInt(this.getParameterByName('gameCode')); //得到游戏编号\r\n this.curLevel=parseInt(this.getParameterByName('gameLevel')); //得到游戏初始关卡\r\n this.playClass=this.getParameterByName('playClass');\r\n \r\n }\r\n console.log(' Global.GameCode:'+ Global.GameCode);\r\n \r\n //this.textLabel.string=Global.GameCode.toString();\r\n }\r\n \r\n start() {\r\n this.timer=Global.GameSetTime;\r\n if(this.playClass==='A')\r\n {\r\n this.uiManager.gamePanel.hideLevelUi();\r\n }\r\n\r\n }\r\n\r\n update(deltaTime: number) {\r\n \r\n }\r\n //初始化\r\n initialize() {\r\n\r\n }\r\n\r\n //得到url参数值\r\n getParameterByName(name) {\r\n let url = window.location.href;\r\n name = name.replace(/[\\[\\]]/g, '\\\\$&');\r\n let regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),\r\n results = regex.exec(url);\r\n if (!results) return null;\r\n if (!results[2]) return '';\r\n   return decodeURIComponent(results[2].replace(/\\+/g, ' '));\r\n }\r\n \r\n \r\n //开始计时\r\n startCountTime()\r\n {\r\n this.schedule(this.updateTimer, 1);\r\n }\r\n\r\n updateTimer() {\r\n if(this.isStartGame)\r\n {\r\n this.timer--;\r\n this.uiManager.gamePanel.RefreshTime(this.timer);\r\n this.curLevelTime++;\r\n this.gameTotalTime++;\r\n if (this.timer <= 0) {\r\n this.unschedule(this.updateTimer);\r\n this.isStartGame=false;\r\n //保存数据\r\n \r\n AudioManage.instance.pauseMusic();\r\n \r\n if(this.playClass==='A')\r\n {\r\n if( this.curLevelScore>this.curLevelData.targetScore)\r\n { \r\n this.saveDataToServer(0);\r\n\r\n }else{\r\n this.saveDataToServer(1);\r\n\r\n }\r\n \r\n this.uiManager.gamePanel.showPlayAendTip(this.curLevelScore);\r\n }else{\r\n this.saveDataToServer(1);\r\n this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n }\r\n // 倒计时结束游戏失败\r\n }\r\n }\r\n }\r\n //重置时间\r\n resetCountTime()\r\n {\r\n this.timer=Global.GameSetTime;;\r\n }\r\n\r\n //加分\r\n addScore(score:number)\r\n {\r\n this.curLevelScore+=score;\r\n this.gameTotalScore+=score;\r\n //当前分数大于关卡目标分数进入下一关\r\n if( this.curLevelScore>this.curLevelData[\"targetScore\"])\r\n {\r\n //保存数据\r\n this.saveDataToServer(0);\r\n if(this.playClass!=='A')\r\n {\r\n this.isStartGame=false;\r\n if(this.curLevel===Global.MaxLv)\r\n {\r\n this.uiManager.showPanel(PanelType.EndPanel);\r\n this.GameOver();\r\n \r\n }else{\r\n this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,true);\r\n \r\n }\r\n }\r\n }\r\n this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n }\r\n //减分\r\n minusScore(score:number)\r\n {\r\n this.curLevelScore-=score;\r\n this.gameTotalScore-=score;\r\n this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n if( this.curLevelScore<=0)\r\n { \r\n //保存数据\r\n this.saveDataToServer(1);\r\n if(this.playClass!=='A'){\r\n this.isStartGame=false;\r\n //游戏失败\r\n this.uiManager.gamePanel.showGameEndTip(this.curLevel,this.curLevelScore,this.gameTotalScore,false);\r\n\r\n }\r\n }\r\n \r\n }\r\n \r\n //进入下一关\r\n public NextLevel()\r\n {\r\n this.curLevel++;\r\n this.curLevelScore=0;\r\n this.curLevelTime=0\r\n this.resetCountTime();\r\n if(this.curLevel>Global.MaxLv)\r\n {\r\n this.uiManager.showPanel(PanelType.EndPanel);\r\n this.GameOver();\r\n return;\r\n }\r\n\r\n this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n this.unscheduleAllCallbacks();\r\n this.StartGame();\r\n \r\n }\r\n //进入游戏场景\r\n public EnterGameScene()\r\n {\r\n this.uiManager.showPanel(PanelType.GamePanel);\r\n this.uiManager.hidePanel(PanelType.StartPanel);\r\n \r\n this.StartGame();\r\n }\r\n \r\n //开始游戏\r\n public StartGame()\r\n {\r\n this.isStartGame=true;\r\n const levelManager=LevelManager.getInstance();\r\n //得到当前关卡配置数据\r\n this.curLevelData=levelManager.getLevelData(this.curLevel);\r\n this.uiManager.gamePanel.RefreshLevel(this.curLevel);\r\n AudioManage.instance.playMusic();\r\n this.startCountTime();\r\n //开始游戏后处理生成游戏场景\r\n }\r\n \r\n public ContinueGame()\r\n { \r\n if(this.isPaused)\r\n {\r\n this.resumeGame();\r\n }else{\r\n this.uiManager.showPanel(PanelType.GamePanel);\r\n this.RestartGame();\r\n }\r\n\r\n }\r\n //暂停游戏\r\n public PauseGame()\r\n {\r\n this.uiManager.showPanel(PanelType.StartPanel);\r\n this.isPaused=true;\r\n this.isStartGame=false;\r\n AudioManage.instance.pauseMusic();\r\n this.uiManager.hidePanel(PanelType.GamePanel);\r\n //暂停后处理游戏内暂停\r\n }\r\n //继续游戏\r\n public resumeGame()\r\n {\r\n this.uiManager.showPanel(PanelType.GamePanel);\r\n this.isPaused=false;\r\n this.isStartGame=true;\r\n AudioManage.instance.playMusic();\r\n this.uiManager.hidePanel(PanelType.StartPanel);\r\n //继续游戏后处理游戏内继续游戏\r\n }\r\n\r\n //返回首页\r\n public BackHomePage()\r\n {\r\n \r\n this.uiManager.showPanel(PanelType.StartPanel);\r\n this.uiManager.hidePanel(PanelType.GamePanel);\r\n\r\n //返回首页相当于暂时退出游戏 需处理清空游戏\r\n\r\n }\r\n //重新开始\r\n public RestartGame()\r\n {\r\n this.curLevelScore=0;\r\n this.curLevelTime=0\r\n this.resetCountTime();\r\n this.uiManager.gamePanel.RefreshScore(this.curLevelScore);\r\n AudioManage.instance.playMusic();\r\n //处理清空游戏\r\n this.StartGame();\r\n }\r\n\r\n \r\n public GameOver()\r\n {\r\n this.unscheduleAllCallbacks();\r\n AudioManage.instance.pauseMusic();\r\n }\r\n quitGame()\r\n {\r\n if(this.playClass==='A')\r\n {\r\n if( this.curLevelScore>this.curLevelData.targetScore)\r\n { \r\n this.saveDataToServer(0);\r\n\r\n }else{\r\n this.saveDataToServer(1);\r\n\r\n }\r\n }else{\r\n this.saveDataToServer(1);\r\n \r\n }\r\n }\r\n\r\n //保存游戏数据到服务器\r\n saveDataToServer(ispass:number)\r\n {\r\n if(Global.IsDevelop){\r\n return;\r\n }\r\n const requestData=new SaveData();\r\n requestData.gameCode= Global.GameCode;\r\n requestData.gameLevel=this.curLevel;\r\n requestData.gameScore=this.curLevelScore;\r\n requestData.duration=this.curLevelTime;\r\n requestData.playClass= this.playClass;\r\n requestData.isPass=ispass;\r\n const jsonRequestData = JSON.stringify(requestData);\r\n\r\n HttpManager.Instanct().httpPost(Global.Net_SaveUrl, jsonRequestData)\r\n .then(responseData => {\r\n const endData=responseData as ResponseInfo;\r\n if(endData.success===false)\r\n {\r\n console.log('请求失败');\r\n }\r\n console.log(responseData);\r\n })\r\n .catch(error => {\r\n console.error(error);\r\n });\r\n }\r\n \r\n}\r\n\r\n\r\n" } ] }