ShenNong/library/imports/b0/b0432040-dbde-438c-839c-ba2b5d18a3b5.js
YZ\249929363 c2b3325788 修复BUG
2024-08-02 17:24:09 +08:00

432 lines
17 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
cc._RF.push(module, 'b0432BA295DjIOcuitdGKO1', 'GameManager');
// Script/GameManager.ts
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
// 主游戏控制类
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GameManager = /** @class */ (function (_super) {
__extends(GameManager, _super);
function GameManager() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.Btn_New = null;
_this.Btn_Hear = null;
_this.Btn_See = null;
_this.Btn_Firewood = null;
_this.Plant = null;
_this.timeNode = null;
_this.FoodPlist = null;
return _this;
}
GameManager.prototype.onLoad = function () {
this.fit();
this.init();
this.startGame();
};
GameManager.prototype.start = function () {
};
//初始化数据
GameManager.prototype.init = function () {
this.touchable = false;
this.result = -1;
this.foodAudioArray = [];
this.foodPicArray = [];
this.timeTween = null;
this.needleTween = null;
this.choice = 0;
cc.fx.GameConfig.GM_INFO.stepTimeList = 0;
cc.fx.GameConfig.GM_INFO.successList = [];
cc.fx.GameConfig.GM_INFO.level = 0;
this.voiceSpriteFrame = this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame;
this.btnReset();
};
//开始游戏
GameManager.prototype.startGame = function () {
var _this = this;
cc.tween(this.node.getChildByName("Begin"))
.to(0.1, { opacity: 0 })
.to(0.5, { opacity: 255 })
.delay(1)
.to(0.5, { opacity: 0 })
.call(function () {
_this.createCustom();
})
.start();
};
//根据是否全面屏,做独立适配方面
GameManager.prototype.fit = function () {
var jg = cc.fx.GameTool.setFit();
if (!jg) {
this.Btn_Hear.y = -330;
this.Btn_See.y = -460;
this.Btn_Firewood.y = -600;
}
};
//创建关卡
GameManager.prototype.createCustom = function () {
var _this = this;
this.choice = 0;
this.Plant.opacity = 0;
this.timeNode.getChildByName("time").getComponent(cc.Sprite).fillRange = 0;
this.timeNode.getChildByName("needle").angle = 0;
if (cc.fx.GameConfig.GM_INFO.level >= cc.fx.GameConfig.LEVEL_INFO[cc.fx.GameConfig.GM_INFO.custom].custom.length) {
setTimeout(function () {
cc.director.loadScene("OverScene");
}, 1000);
return;
}
this.customData = cc.fx.GameConfig.LEVEL_INFO[cc.fx.GameConfig.GM_INFO.custom].custom[cc.fx.GameConfig.GM_INFO.level];
var name = this.customData.item;
//埋点数据设置
cc.fx.GameConfig.CLICK_SET("round", cc.fx.GameConfig.GM_INFO.level + 1);
cc.fx.GameConfig.CLICK_SET("levelConfig", (cc.fx.GameConfig.GM_INFO.custom + 1));
cc.fx.GameConfig.CLICK_SET("item", name);
cc.fx.GameConfig.CLICK_SET("roundType", this.customData.type);
if (this.customData.type == 1) {
this.Plant.getChildByName("name").getComponent(cc.Label).string = cc.fx.GameTool.getFoodName(name);
name = "prop_" + name;
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.FoodPlist["_spriteFrames"][name];
this.now_Food = name;
cc.tween(this.Plant)
.to(0.2, { opacity: 255 })
.call(function () {
_this.startTimer();
})
.start();
}
else {
this.Plant.getChildByName("name").getComponent(cc.Label).string = "";
this.Plant.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = this.voiceSpriteFrame;
var audioName = name + "_audio";
name = "audio" + name;
this.now_Food = name;
cc.fx.AudioManager._instance.playEffect(audioName, this.startTimer.bind(this));
cc.tween(this.Plant)
.to(0.2, { opacity: 255 })
.call(function () {
})
.start();
}
//关卡+1
cc.fx.GameConfig.GM_INFO.level += 1;
};
//开始转圈倒计时
GameManager.prototype.startTimer = function () {
var _this = this;
this.startTime = cc.fx.GameTool.getTime();
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = true;
this.Btn_Firewood.getComponent(cc.Button).interactable = true;
// if(this.containsNanana(this.now_Food) == true){
// console.log("可以点火");
// }
this.timeNode.getChildByName("time").getComponent(cc.Sprite).fillRange = 0;
this.needleTween =
cc.tween(this.timeNode.getChildByName("needle"))
.to(5, { angle: -360 })
.start();
this.timeTween =
cc.tween(this.timeNode.getChildByName("time").getComponent(cc.Sprite))
.to(5, { fillRange: 1 })
.call(function () {
_this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
_this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
_this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
_this.Btn_Firewood.getComponent(cc.Button).interactable = false;
_this.click_Choice(null, null);
_this.timeTween = null;
})
.start();
};
GameManager.prototype.containsNanana = function (str) {
return /muchai/i.test(str);
};
//新植物按钮
GameManager.prototype.click_Choice = function (customData, data) {
//关掉计时器 处理逻辑之前,先行关掉按钮开关
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_Firewood.getComponent(cc.Button).interactable = false;
this.timeTween.stop();
this.timeTween = null;
this.needleTween.stop();
this.needleTween = null;
//判断是否正确,并把出现的物品存入数组
this.result = this.judgingResult();
if (data == "Btn_New") {
if (this.result == -1) {
this.result = 1;
}
else {
this.result = -1;
}
}
var tempNode = null;
if (data != null)
tempNode = this[data];
//设置按钮状态
this.setBtnState(tempNode, data);
//获取反应时间
this.setTimeData();
//根据答题,设置上传数据
this.setData(data);
//进行下一关
this.nextLevel();
};
//点火按钮
GameManager.prototype.click_Ignition = function () {
var _this = this;
cc.fx.GameConfig.CLICK_SET("ignite", true);
this.Btn_Firewood.getComponent(cc.Button).interactable = false;
if (this.containsNanana(this.now_Food) == true) {
var igniteCount = cc.fx.GameConfig.GM_INFO.igniteCount + 1;
cc.fx.GameConfig.GM_INFO_SET("igniteCount", igniteCount);
cc.fx.GameConfig.CLICK_SET("igniteCount", igniteCount);
this.Btn_Firewood.getChildByName("fireBg").active = true;
this.Btn_Firewood.getChildByName("fire").active = true;
setTimeout(function () {
if (_this.Btn_Firewood) {
_this.Btn_Firewood.getChildByName("fireBg").active = false;
_this.Btn_Firewood.getChildByName("fire").active = false;
}
}, 1050);
console.log("正确点火");
}
else if (this.customData.flamable == 1) {
console.log("错误点火");
// console.log("正确点火");
}
};
//判断是否有过的结果 type只为new hear see 三选一
GameManager.prototype.judgingResult = function () {
var result = -1;
//先检查音频
var name = this.now_Food.substring(5, this.now_Food.length);
if (this.foodAudioArray.length > 0) {
for (var i = 0; i < this.foodAudioArray.length; i++) {
if (name == this.foodAudioArray[i].substring(5, this.now_Food.length)) {
result = 2;
this.foodAudioArray.splice(i, 1);
cc.fx.GameConfig.CLICK_SET("rightChoice", 2);
console.log("听到过");
i = 10000;
break;
}
}
}
//再检查图盘
if (this.foodPicArray.length > 0) {
for (var i = 0; i < this.foodPicArray.length; i++) {
if (name == this.foodPicArray[i].substring(5, this.now_Food.length)) {
//如果图片里面有
result = 3;
this.foodPicArray.splice(i, 1);
console.log("看到过");
cc.fx.GameConfig.CLICK_SET("rightChoice", 3);
i = 10000;
break;
}
}
}
//把新生成的存放进数组里
if (this.now_Food.substring(0, 4) != "prop") {
this.foodAudioArray.push(this.now_Food);
}
else {
this.foodPicArray.push(this.now_Food);
}
if (result != 2 && result != 3) {
console.log("没出险过");
cc.fx.GameConfig.CLICK_SET("rightChoice", 1);
}
return result;
};
//计算反应时间
GameManager.prototype.setTimeData = function () {
this.overTime = cc.fx.GameTool.getTime();
var time = this.overTime - this.startTime;
//防止溢出
if (time < 0 || time > 5000)
time = 5000;
cc.fx.GameConfig.CLICK_SET("stepTime", time);
cc.fx.GameConfig.GM_INFO.stepTimeList += time;
};
//设置按钮状态
GameManager.prototype.setBtnState = function (node, data) {
if (data == "Btn_New")
this.choice = 1;
else if (data == "Btn_Hear")
this.choice = 2;
else if (data == "Btn_See")
this.choice = 3;
if (data == null) {
this.choice = 0;
}
if (this.choice != cc.fx.GameConfig.CLICK_DATA.rightChoice) {
if (node) {
cc.fx.AudioManager._instance.playEffect("err", null);
node.getChildByName("err").active = true;
node.getChildByName("correct").active = false;
}
}
else {
if (node) {
cc.fx.AudioManager._instance.playEffect("yes", null);
node.getChildByName("err").active = false;
node.getChildByName("correct").active = true;
}
}
if (node)
node.getChildByName("nomal").active = false;
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
};
//下一轮 首先重置按钮状态
GameManager.prototype.nextLevel = function () {
var _this = this;
cc.tween(this.Plant)
.delay(1)
.call(function () {
_this.btnReset();
})
.to(0.5, { opacity: 0 })
.call(function () {
_this.createCustom();
})
.start();
};
GameManager.prototype.btnReset = function () {
this.Btn_New.getChildByName("nomal").active = true;
this.Btn_New.getChildByName("err").active = false;
this.Btn_New.getChildByName("correct").active = false;
this.Btn_Hear.getChildByName("nomal").active = true;
this.Btn_Hear.getChildByName("err").active = false;
this.Btn_Hear.getChildByName("correct").active = false;
this.Btn_See.getChildByName("nomal").active = true;
this.Btn_See.getChildByName("err").active = false;
this.Btn_See.getChildByName("correct").active = false;
this.Btn_Hear.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_New.getChildByName("nomal").getComponent(cc.Button).interactable = false;
this.Btn_See.getChildByName("nomal").getComponent(cc.Button).interactable = false;
// this.Btn_Firewood.getComponent(cc.Button).interactable = false;
};
//返回首页
GameManager.prototype.backScene = function () {
cc.director.loadScene("LoadScene");
};
//下一关或者重新开始或者返回上一关根据level决定
GameManager.prototype.reStart = function (type) {
};
//获取时间戳
GameManager.prototype.getTime = function () {
var timestamp = new Date().getTime();
return timestamp;
};
//获胜
GameManager.prototype.passLevel = function () {
};
//失败
GameManager.prototype.loseLevel = function (type) {
};
//如果是倒计时 调用此方法
GameManager.prototype.startCountDownTime = function () {
this.timeNode.getChildByName("time").getComponent(cc.Sprite).fillRange = 0;
this.timeNode.getChildByName("needle").angle = 0;
};
//上传每次操作数据
GameManager.prototype.setData = function (data) {
console.log("进入上传埋点");
if (data == "Btn_New")
this.choice = 1;
else if (data == "Btn_Hear")
this.choice = 2;
else if (data == "Btn_See")
this.choice = 3;
else if (data == null) {
this.choice = 0;
cc.fx.GameConfig.CLICK_SET("stepTime", 5000);
}
var jg = false;
if (this.choice == cc.fx.GameConfig.CLICK_DATA.rightChoice) {
jg = true;
cc.fx.GameConfig.GM_INFO.successList.push(jg);
}
cc.fx.GameConfig.CLICK_SET("choice", this.choice);
cc.fx.GameConfig.CLICK_SET("success", jg);
console.log("进入GameTool.setGameData", cc.fx.GameConfig.CLICK_DATA);
cc.fx.GameTool.setGameData();
};
//上传排行榜数据
GameManager.prototype.gameOver = function (time) {
cc.fx.GameTool.setRank(time);
this.node.getChildByName("GameOver").active = true;
this.node.getChildByName("GameOver").opacity = 0;
cc.tween(this.node.getChildByName("GameOver"))
.to(0.4, { opacity: 255 })
.delay(2)
.to(0.4, { opacity: 50 })
.call(function () {
cc.director.loadScene("OverScene");
})
.start();
};
GameManager.prototype.onEnable = function () {
// cc.fx.Notifications.on("clickSun", this.clickSun, this);
};
GameManager.prototype.onDisable = function () {
// cc.fx.Notifications.off("clickSun", this.clickSun);
};
GameManager.prototype.update = function (dt) {
};
__decorate([
property(cc.Node)
], GameManager.prototype, "Btn_New", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "Btn_Hear", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "Btn_See", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "Btn_Firewood", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "Plant", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "timeNode", void 0);
__decorate([
property(cc.SpriteAtlas)
], GameManager.prototype, "FoodPlist", void 0);
GameManager = __decorate([
ccclass
], GameManager);
return GameManager;
}(cc.Component));
exports.default = GameManager;
cc._RF.pop();