Commit f1cc991a authored by XieChuanJin's avatar XieChuanJin

集合所有内容到game类

parent 877333e1
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -26,6 +26,9 @@ import DropPoolGroup from "../Pools/DropPool";
import DropBlinkMgr from "../Mgr/DropBlinkMgr";
import GameMgr from "../Mgr/GameMgr";
import { DataMgr } from "../Mgr/DataMgr";
import { initNECaptcha } from "../Component/InitNECaptcha";
import { NetUtils } from "../Global/NetUtils";
import Net from "../Global/Net";
type LayerName = "Bullet" | "Ball" | "Drop" | "Effect";
......@@ -109,6 +112,111 @@ export default class Game {
public _animationMgr: FrameAnimationMgr = new FrameAnimationMgr();
public _horizontalMoveMgr: HorizontalMoveMgr = new HorizontalMoveMgr();
private constantSubmitSeq = 1;
private needSubmitCount = 0; //实际分数减去ConstantSubmitScoreNum的次数
private isSubmiting = false;
public startId: number = 0;
private _localScore: number = 0;
public get localScore(): number {
return this._localScore;
}
public set localScore(v: number) {
this._localScore = v;
if (this._localScore >= MConst.ConstantSubmitScoreNum) {
let count = Math.floor(this._localScore / MConst.ConstantSubmitScoreNum);
this.needSubmitCount += count;
this._localScore -= MConst.ConstantSubmitScoreNum * count;
if (!this.isSubmiting) {
this.constantSubmit();
}
}
}
private constantSubmit(score: number = MConst.ConstantSubmitScoreNum) {
if (this.isSubmiting) {
return;
}
if (this.needSubmitCount == 0) {
return;
} else if (this.needSubmitCount < 0) {
//异常,有bug
console.error("invalid needSubmitCount value");
return;
}
this.isSubmiting = true;
let seq = NetUtils.encryptSeq(this.constantSubmitSeq);
return new Promise((resolve, reject) => {
Net.sendPost(Net.Url.constantSubmit, {
startId: this.startId,
seq: seq,
score: score,
token: NetUtils.md5(this.startId.toString() + seq.toString() + score.toString() + "qzBankRPW@dui88")
}, () => {
this.constantSubmitSeq++;
console.error("submited", this.constantSubmitSeq, this.needSubmitCount);
this.needSubmitCount--;
this.isSubmiting = false;
resolve();
}, (res) => {
this.isSubmiting = false;
reject();
});
});
}
public async finalSubmit(propsId?: string, onSubmited?: () => void) {
if (this.needSubmitCount > 0) {
if (!this.isSubmiting) {
while (this.needSubmitCount > 0) {
await this.constantSubmit();
}
}
}
const score = this.score;
let serverScore = this.localScore + (this.constantSubmitSeq - 1 + this.needSubmitCount) * MConst.ConstantSubmitScoreNum;
if (serverScore != score) {
console.error(`[score error] server:${serverScore} local:${score}`);
} else {
console.log(`[score] server:${serverScore} local:${score}`);
}
//中途提交最后一次
if (this.localScore > 0) {
this.needSubmitCount++;
await this.constantSubmit(this.localScore);
console.log("extra submit:" + this.localScore);
}
//滑块验证
let validate = await new Promise<string>(resolve => {
if (typeof engine.env.minEnableCaptchaScore == "number" && score >= engine.env.minEnableCaptchaScore) {
initNECaptcha({
captchaId: MConst.captchaId,
callback: (ret: { validate: string }) => {
resolve(ret.validate);
}
});
} else {
resolve("");
}
});
engine.globalEvent.dispatchEvent("ShootPlanetFinalSubmit", {
startId: this.startId,
score: score,
useSpId: propsId || "",
token: NetUtils.md5(this.startId.toString() + score.toString() + "qzBankRPW@dui88"),
validate: validate
});
}
private loadRes() {
FrameAnimation.loadRes(RES.getRes("217164f4-a185-429c-8706-818137a4e438"), DuangAltaData);
SpriteFont.load(RES.getRes("b4d821e8-8274-4b60-95d0-47da803ac5cf"), NumFontData);
......@@ -201,6 +309,7 @@ export default class Game {
private over() {
this.pause = true;
engine.globalEvent.dispatchEvent("ShootPlanetGameOver");
this.finalSubmit();
this.onGameOver && this.onGameOver();
}
......@@ -296,6 +405,7 @@ export default class Game {
//时间到
this.pause = true;
engine.globalEvent.dispatchEvent("ShootPlanetGameOver");
this.finalSubmit();
this.onGameOver && this.onGameOver();
}
}
......@@ -396,7 +506,7 @@ export default class Game {
return this.__score;
}
public set _score(v: number) {
this.onScoreChange && this.onScoreChange(v - this.__score);
this.localScore += (v - this.__score);
this.__score = v;
}
/**不建议使用 */
......
import { NetUtils } from "./NetUtils";
import { ToastPanel } from "../ShootPlanet";
const projectId = NetUtils.getProjectId();
export default class Net {
......@@ -92,13 +91,13 @@ export default class Net {
let errorMsg = res && ((res["desc"] || res["message"]) || ((res["code"] && "network error:" + res["code"]) || "network error")) || "network error";
if (typeof net.onFail == "function") {
if (!net.onFail(res)) { //若客户没有处理错误码,怎么默认显示错误消息或描述文字的弹窗
ToastPanel.show(errorMsg);
console.error(errorMsg);
}
} else {
if (typeof net.onFail == "boolean" && net.onFail == true) {
Net.defaultOnFail && Net.defaultOnFail(res);
}
ToastPanel.show(errorMsg);
console.error(errorMsg);
}
}
......
......@@ -16,28 +16,6 @@ import { initNECaptcha } from "./Component/InitNECaptcha";
export class ShootPlanet extends engine.Container {
public game: Game = null;
private constantSubmitSeq = 1;
private needSubmitCount = 0; //实际分数减去ConstantSubmitScoreNum的次数
private isSubmiting = false;
public startId: number = 0;
private _localScore: number = 0;
public get localScore(): number {
return this._localScore;
}
public set localScore(v: number) {
this._localScore = v;
if (this._localScore >= MConst.ConstantSubmitScoreNum) {
let count = Math.floor(this._localScore / MConst.ConstantSubmitScoreNum);
this.needSubmitCount += count;
this._localScore -= MConst.ConstantSubmitScoreNum * count;
if (!this.isSubmiting) {
this.constantSubmit();
}
}
}
public onSleep() {
this.game.destroy();
......@@ -45,19 +23,7 @@ export class ShootPlanet extends engine.Container {
}
public onActive() {
this.constantSubmitSeq = 1;
this.needSubmitCount = 0;
this.isSubmiting = false;
this._localScore=0;
this.game = new Game(this);
//监听游戏分数变化
this.game.onScoreChange = (delta: number) => {
this.localScore += delta;
};
this.game.onGameOver = () => {
this.finalSubmit();
}
if (GuideMgr.instance.guideFlag == true) {
const car = this.game._car;
GuideMgr.instance.runGuide(0, car.x + car.width / 2, car.y + car.height / 2 /* - 130 */);
......@@ -70,6 +36,8 @@ export class ShootPlanet extends engine.Container {
this.width = 750;
this.height = 1624;
this.init();
this.onActive();
}
private init() {
......@@ -100,94 +68,4 @@ export class ShootPlanet extends engine.Container {
this.parent.removeChild(this);
}
}
private constantSubmit(score: number = MConst.ConstantSubmitScoreNum) {
if (this.isSubmiting) {
return;
}
if (this.needSubmitCount == 0) {
return;
} else if (this.needSubmitCount < 0) {
//异常,有bug
console.error("invalid needSubmitCount value");
return;
}
this.isSubmiting = true;
let seq = NetUtils.encryptSeq(this.constantSubmitSeq);
return new Promise((resolve, reject) => {
Net.sendPost(Net.Url.constantSubmit, {
startId: this.startId,
seq: seq,
score: score,
token: NetUtils.md5(this.startId.toString() + seq.toString() + score.toString() + "qzBankRPW@dui88")
}, () => {
this.constantSubmitSeq++;
console.error("submited", this.constantSubmitSeq);
this.needSubmitCount--;
this.isSubmiting = false;
resolve();
}, (res) => {
this.isSubmiting = false;
Net.defaultOnFail(res);
reject();
});
});
}
public async finalSubmit(propsId?: string, onSubmited?: () => void) {
Loading.instace.show();
if (this.needSubmitCount > 0) {
if (!this.isSubmiting) {
while (this.needSubmitCount > 0) {
await this.constantSubmit();
}
}
}
const score = this.game.score;
let serverScore = this.localScore + (this.constantSubmitSeq - 1 + this.needSubmitCount) * MConst.ConstantSubmitScoreNum;
if (serverScore != score) {
console.error(`[score error] server:${serverScore} local:${score}`);
} else {
console.log(`[score] server:${serverScore} local:${score}`);
}
//中途提交最后一次
if (this.localScore > 0) {
this.needSubmitCount++;
await this.constantSubmit(this.localScore);
console.log("extra submit:" + this.localScore);
}
//滑块验证
let validate = await new Promise<string>(resolve => {
if (typeof engine.env.minEnableCaptchaScore == "number" && score >= engine.env.minEnableCaptchaScore) {
initNECaptcha({
captchaId: MConst.captchaId,
callback: (ret: { validate: string }) => {
resolve(ret.validate);
}
});
} else {
resolve("");
}
});
engine.globalEvent.dispatchEvent("ShootPlanetFinalSubmit", {
startId: this.startId,
score: score,
useSpId: propsId || "",
token: NetUtils.md5(this.startId.toString() + score.toString() + "qzBankRPW@dui88"),
validate: validate
});
}
}
export class ToastPanel {
public static show(msg: string) {
console.log("toast:" + msg);
}
}
let labelMsg = new engine.Label();
let share = {
title: engine.env.shareTitle,
desc: engine.env.shareDesc,
link: engine.env.shareLink,
imgUrl: engine.env.shareImgUrl
};
if (typeof msg != "string") {
msg = typeof msg;
}
\ No newline at end of file
const share = args;
wx.onMenuShareTimeline({
title: share.title,
desc: share.desc,
link: share.url,
imgUrl: share.imgUrl,
success: function () {
mui.Toast.show("分享成功");
engine.globalEvent.dispatchEvent("ShareSuccess");
},
cancel: function () {
mui.Toast.show("分享取消");
engine.globalEvent.dispatchEvent("ShareCancel");
}
});
wx.onMenuShareAppMessage({
title: share.title,
desc: share.desc,
link: share.url,
imgUrl: share.imgUrl,
success: function () {
mui.Toast.show("分享成功");
engine.globalEvent.dispatchEvent("ShareSuccess");
},
cancel: function () {
mui.Toast.show("分享取消");
engine.globalEvent.globa.dispatchEvent("ShareCancel");
}
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment