LockDiagram/library/imports/b0/b0432040-dbde-438c-839c-ba2b5d18a3b5.js
2024-10-30 15:21:35 +08:00

536 lines
22 KiB
JavaScript

"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.kuang1_Prefab = null;
_this.kuang2_Prefab = null;
_this.Block = null;
_this.TimeLabel = null;
_this.LevelLabel = null;
_this.Guide = null;
_this.progress = null; //-95 640
_this.Top = null; //80 -725
return _this;
}
GameManager.prototype.onLoad = function () {
this.guide_State = false;
this.level = cc.fx.GameConfig.GM_INFO.level;
this.guide_Level = cc.fx.GameConfig.GM_INFO.guide_Level;
this.LevelLabel.string = (this.level + 1) + "";
this.progress.fillRange = cc.fx.GameConfig.GM_INFO.score / 24;
if (this.progress.fillRange >= 0.2)
this.Top.getChildByName("star1").active = true;
if (this.progress.fillRange >= 0.5)
this.Top.getChildByName("star2").active = true;
if (this.progress.fillRange >= 0.8)
this.Top.getChildByName("star3").active = true;
if ((this.level == 0 && this.guide_Level == 4) ||
(this.level == 4 && this.guide_Level == 3) ||
(this.level == 8 && this.guide_Level == 1)) {
this.openGuide(false);
}
else {
this.LevelLabel.node.active = true;
this.node.getChildByName("Top").getChildByName("lianxi").getComponent(cc.Label).string = "第 轮";
this.init();
}
};
GameManager.prototype.init = function () {
var _this = this;
if (this.level == 4 && this.guide_Level == 2) {
cc.fx.GameConfig.GM_INFO.guide_Level -= 1;
this.guide_State = true;
this.LevelLabel.node.active = false;
this.node.getChildByName("Top").getChildByName("lianxi").getComponent(cc.Label).string = "练 习";
// this.node.getChildByName("tip").active = true;
}
this.result = 0;
this.countTime = 6;
this.TimeLabel.string = cc.fx.GameTool.getTimeMargin(this.countTime);
this.createBlock();
setTimeout(function () {
_this.createCustom();
}, 1000);
};
GameManager.prototype.openGuide = function (type) {
this.Guide.active = true;
this.guide_State = true;
// this.node.getChildByName("tip").active = true;
if (!type)
cc.fx.GameConfig.GM_INFO.guide_Level -= 1;
this.Guide.getChildByName("one").active = false;
this.Guide.getChildByName("two").active = false;
this.Guide.getChildByName("three").active = false;
this.Guide.getChildByName("four").active = false;
var name = "one";
if (this.level == 0) {
name = "one";
this.LevelLabel.node.active = false;
this.node.getChildByName("Top").getChildByName("lianxi").getComponent(cc.Label).string = "练 习";
}
else if (this.level == 4) {
name = "two";
this.LevelLabel.node.active = false;
this.node.getChildByName("Top").getChildByName("lianxi").getComponent(cc.Label).string = "练 习";
}
else if (this.level == 8) {
name = "three";
this.guide_State = false;
}
if (type)
name = "four";
this.Guide.getChildByName(name).active = true;
cc.tween(this.Guide.getChildByName(name))
.to(0.5, { opacity: 255 })
.start();
};
GameManager.prototype.closeGuide = function () {
if (this.Guide.getChildByName("four").active) {
this.Guide.active = false;
cc.director.loadScene("GameScene");
}
else {
this.Guide.active = false;
this.init();
}
//
};
//创建方块地图
GameManager.prototype.createBlock = function () {
this.outside_Array = [];
this.inside_Array = [];
this.outside = [];
this.inside = [];
for (var i = 0; i < 16; i++) {
var block = cc.instantiate(this.kuang1_Prefab);
block.getComponent("Block").setId(i);
block.parent = this.Block.getChildByName("outside");
var x = void 0, y = 0;
if (i < 5) {
x = -284 + 142 * i;
y = 259;
}
else if (i < 9) {
x = 284;
y = 259 - (i - 4) * 142;
}
else if (i < 13) {
x = 284 - (i - 8) * 142;
y = -309;
}
else if (i < 16) {
x = -284;
y = -309 + (i - 12) * 142;
}
block.setPosition(x, y);
this.outside_Array.push(block);
}
for (var j = 3; j < 12; j++) {
var block = cc.instantiate(this.kuang2_Prefab);
block.getComponent("Block").setId(j);
block.parent = this.Block.getChildByName("inside");
block.setPosition(-132 + j % 3 * 132, 239 - parseInt(j / 3 + "") * 132);
this.inside_Array.push(block);
}
};
//创建关卡
GameManager.prototype.createCustom = function () {
//初始化关卡配置数据
this.level = cc.fx.GameConfig.GM_INFO.level;
this.LevelLabel.string = (this.level + 1) + "";
this.config = cc.fx.GameConfig.LEVEL_INFO[this.level];
if (this.level == 4 && this.guide_Level == 2) {
this.config = cc.fx.GameConfig.LEVEL_INFO[6];
}
this.pass = false;
//放正确答案和错误答案
this.answerInsideTexture = Math.floor(Math.random() * 14 + 1);
//内圈错误答案随机
this.insideTexture = [];
this.outsideTexture = [];
for (var k = 0; k < 14; k++) {
if ((k + 1) != this.answerInsideTexture) {
this.insideTexture.push(k + 1);
}
}
cc.fx.GameTool.shuffleArray(this.insideTexture);
this.answerOutsideTexture = this.insideTexture[11];
//分配正确答案和错误答案位置
if (this.config["inside"] > 0) {
this.result += 1;
var random = Math.random() * 100;
var arrayTemp = [0, 1, 2, 3, 5, 6, 7, 8];
if (this.config["insideType"] == 1) {
if (random >= 50)
this.inside = [0, 1, 2];
else
this.inside = [6, 7, 8];
}
else if (this.config["insideType"] == 2) {
if (random >= 50)
this.inside = [0, 3, 6];
else
this.inside = [2, 5, 8];
}
else {
this.inside = cc.fx.GameTool.shuffleArray(arrayTemp);
this.inside.splice(this.config["inside"], this.inside.length - this.config["inside"]);
}
this.answerInside = this.inside[Math.floor(Math.random() * this.inside.length)];
}
//分配外圈正确答案和错误答案位置
if (this.config["outside"] > 0) {
this.result += 1;
if (this.config["outsideType"] == 1) {
this.outside = [1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15];
}
else if (this.config["outsideType"] == 2) {
this.outside = [0, 4, 8, 12];
}
else {
this.outside = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
}
cc.fx.GameTool.shuffleArray(this.outside);
this.answerOutside = this.outside[Math.floor(Math.random() * this.outside.length)];
if (this.config["outside"] == 2) {
for (var j = 0; j < 15; j++) {
this.outsideTexture.push(this.insideTexture[3]);
}
}
else if (this.config["outside"] == 3) {
this.outsideTexture = [this.insideTexture[5], this.insideTexture[6], this.insideTexture[5], this.insideTexture[6], this.insideTexture[5]];
for (var j = 0; j < 10; j++) {
var randomTemp = Math.random() * 100;
if (randomTemp > 50)
this.outsideTexture.push(this.insideTexture[5]);
else
this.outsideTexture.push(this.insideTexture[6]);
}
cc.fx.GameTool.shuffleArray(this.outsideTexture);
}
else if (this.config["outside"] == 4) {
this.outsideTexture = [this.insideTexture[2], this.insideTexture[4], this.insideTexture[6],
this.insideTexture[2], this.insideTexture[4], this.insideTexture[6]];
for (var j = 0; j < 9; j++) {
var randomTemp = Math.random() * 100;
if (randomTemp < 33)
this.outsideTexture.push(this.insideTexture[2]);
else if (randomTemp < 66)
this.outsideTexture.push(this.insideTexture[4]);
else
this.outsideTexture.push(this.insideTexture[6]);
}
cc.fx.GameTool.shuffleArray(this.outsideTexture);
}
}
this.runBlock();
};
//块执行图片出现消失动画
GameManager.prototype.runBlock = function () {
var _this = this;
if (this.config["inside"] > 0) {
this.inside_Array[4].getComponent("Block").answerShow(this.answerInsideTexture);
setTimeout(function () {
var insideNumber = 0;
for (var i = 0; i < _this.inside.length; i++) {
if (_this.inside[i] == _this.answerInside)
_this.inside_Array[_this.inside[i]].getComponent("Block").show(true, true, _this.answerInsideTexture);
else {
_this.inside_Array[_this.inside[i]].getComponent("Block").show(false, true, _this.insideTexture[insideNumber]);
insideNumber += 1;
}
}
}, this.config["showTime"] * 1000);
}
if (this.config["outside"] > 0) {
this.outside_Array[this.answerOutside].getComponent("Block").answerShow(this.answerOutsideTexture);
if (this.config["outside"] > 1) {
var outsideNumber = 0;
for (var i = 0; i < this.outside_Array.length; i++) {
if (i == this.answerOutside)
this.outside_Array[i].getComponent("Block").show(true, false, this.answerOutsideTexture);
else {
this.outside_Array[i].getComponent("Block").show(false, false, this.outsideTexture[outsideNumber]);
outsideNumber += 1;
}
}
}
setTimeout(function () {
var outsideNumber = 0;
for (var i = 0; i < _this.outside_Array.length; i++) {
if (i == _this.answerOutside)
_this.outside_Array[i].getComponent("Block").lockShow(true, false);
else {
_this.outside_Array[i].getComponent("Block").lockShow(false, false);
outsideNumber += 1;
}
}
}, this.config["showTime"] * 1000);
}
setTimeout(function () {
if (!_this.guide_State) {
_this.startTime = cc.fx.GameTool.getTime();
_this.schedule(_this.updateCountDownTime, 1);
}
}, this.config["showTime"] * 1000);
};
//正确
GameManager.prototype.openResult = function (result) {
var _this = this;
this.result -= 1;
//非引导状态
if (!this.guide_State) {
this.flipBlock(result);
if (this.result == 0) {
this.unschedule(this.updateCountDownTime);
setTimeout(function () {
_this.setData(result);
}, 1000);
setTimeout(function () {
if (cc.fx.GameConfig.GM_INFO.level < cc.fx.GameConfig.LEVEL_INFO.length - 1) {
cc.fx.GameConfig.GM_INFO.level += 1;
cc.director.loadScene("GameScene");
}
}, 2000);
}
}
//引导状态下
else {
if (result.result) {
this.flipBlock(result);
setTimeout(function () {
if (_this.level == 4 && cc.fx.GameConfig.GM_INFO.guide_Level == 2) {
cc.director.loadScene("GameScene");
}
else
_this.openGuide(true);
}, 1000);
}
}
};
//翻转形状变成问号
GameManager.prototype.flipBlock = function (result) {
if (result.type) {
var pos = this.changePos(true, result.id);
if (!this.guide_State)
cc.fx.GameConfig.CLICK_DATA.userChoiceInner.push(pos.x, pos.y);
for (var i = 0; i < this.inside.length; i++) {
if (this.inside[i] == this.answerInside) {
this.inside_Array[4].getChildByName("texture").active = true;
this.inside_Array[4].getChildByName("texture").opacity = 255;
this.inside_Array[this.inside[i]].getChildByName("yes").active = true;
var pos_1 = this.changePos(true, this.inside_Array[this.inside[i]].getComponent("Block")._idNumber);
if (!this.guide_State)
cc.fx.GameConfig.CLICK_DATA.rightChoiceInner.push(pos_1.x, pos_1.y);
}
this.inside_Array[this.inside[i]].getComponent("Block")._touch = false;
}
if (result.result) {
this.addScore();
}
}
else {
var pos = this.changePos(false, result.id);
if (!this.guide_State)
cc.fx.GameConfig.CLICK_DATA.userChoiceOuter.push(pos.x, pos.y);
for (var i = 0; i < this.outside_Array.length; i++) {
this.outside_Array[i].getComponent("Block").lockHide();
this.outside_Array[i].getChildByName("texture").active = true;
if (i == this.answerOutside) {
this.outside_Array[i].getChildByName("yes").active = true;
this.outside_Array[i].getComponent("Block").show(true, false, this.answerOutsideTexture);
var pos_2 = this.changePos(false, this.outside_Array[i].getComponent("Block")._idNumber);
if (!this.guide_State)
cc.fx.GameConfig.CLICK_DATA.rightChoiceOuter.push(pos_2.x, pos_2.y);
}
}
if (result.result) {
this.addScore();
}
}
};
//加分 加进度条,加星星
GameManager.prototype.addScore = function () {
var _this = this;
if (!this.guide_State) {
cc.fx.GameConfig.GM_INFO.score += 1;
var progress = cc.fx.GameConfig.GM_INFO.score / 24;
if (progress >= 1)
progress = 1;
cc.tween(this.progress)
.to(0.2, { fillRange: progress })
.call(function () {
if (_this.Top.getChildByName("star1").active == false && progress >= 0.2) {
_this.Top.getChildByName("star1").active = true;
_this.Top.getChildByName("star1").opacity = 0;
_this.Top.getChildByName("star1").scale = 0.1;
cc.tween(_this.Top.getChildByName("star1"))
.to(0.3, { opacity: 255, scale: 1.1 })
.to(0.1, { opacity: 255, scale: 0.9 })
.to(0.1, { opacity: 255, scale: 1 })
.start();
}
if (_this.Top.getChildByName("star2").active == false && progress >= 0.5) {
_this.Top.getChildByName("star2").active = true;
_this.Top.getChildByName("star2").opacity = 0;
_this.Top.getChildByName("star2").scale = 0.1;
cc.tween(_this.Top.getChildByName("star2"))
.to(0.3, { opacity: 255, scale: 1.1 })
.to(0.1, { opacity: 255, scale: 0.9 })
.to(0.1, { opacity: 255, scale: 1 })
.start();
}
if (_this.Top.getChildByName("star3").active == false && progress >= 0.8) {
_this.Top.getChildByName("star3").active = true;
_this.Top.getChildByName("star3").opacity = 0;
_this.Top.getChildByName("star3").scale = 0.1;
cc.tween(_this.Top.getChildByName("star3"))
.to(0.3, { opacity: 255, scale: 1.1 })
.to(0.1, { opacity: 255, scale: 0.9 })
.to(0.1, { opacity: 255, scale: 1 })
.start();
}
})
.start();
}
};
//返回首页
GameManager.prototype.backScene = function () {
cc.director.loadScene("LoadScene");
};
//重新开始
GameManager.prototype.reStart = function () {
};
//获取时间戳
GameManager.prototype.getTime = function () {
var timestamp = new Date().getTime();
return timestamp;
};
//获胜
GameManager.prototype.passLevel = function () {
};
//失败
GameManager.prototype.loseLevel = function (type) {
};
GameManager.prototype.changePos = function (type, num) {
var x = 0;
var y = 0;
//内部
if (type) {
y = parseInt(num / 3 + "");
x = num % 3;
}
//外部
else {
if (num < 5) {
y = 0;
x = num;
}
else if (num < 9) {
x = 5;
y = num - 4;
}
else if (num < 13) {
y = 4;
x = 12 - num;
}
else if (num < 16) {
x = 0;
y = 16 - num;
}
}
var jg = cc.v2(x, y);
return jg;
};
//如果是倒计时 调用此方法
GameManager.prototype.updateCountDownTime = function () {
if (this.countTime > 0) {
this.countTime -= 1;
// this.TimeLabel.string =this.countTime + "";
this.TimeLabel.string = cc.fx.GameTool.getTimeMargin(this.countTime);
if (this.countTime <= 0) {
this.unschedule(this.updateCountDownTime);
this.node.getChildByName("Mask").active = true;
var data = { "result": false, "type": true, "id": null };
if (this.config["inside"] > 0)
cc.fx.Notifications.emit("result", data);
var data2 = { "result": false, "type": false, "id": null };
if (this.config["outside"] > 0)
cc.fx.Notifications.emit("result", data2);
}
}
};
//上传每次操作数据
GameManager.prototype.setData = function (result) {
cc.fx.GameConfig.CLICK_DATA.success = result.result;
cc.fx.GameConfig.CLICK_DATA.round = (cc.fx.GameConfig.GM_INFO.level + 1);
cc.fx.GameConfig.CLICK_DATA.duration = new Date().getTime() - this.startTime - 1000;
cc.fx.GameTool.setGameData();
};
GameManager.prototype.onEnable = function () {
cc.fx.Notifications.on("result", this.openResult, this);
};
GameManager.prototype.onDisable = function () {
cc.fx.Notifications.off("result", this.openResult, this);
};
GameManager.prototype.update = function (dt) {
};
__decorate([
property(cc.Prefab)
], GameManager.prototype, "kuang1_Prefab", void 0);
__decorate([
property(cc.Prefab)
], GameManager.prototype, "kuang2_Prefab", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "Block", void 0);
__decorate([
property(cc.Label)
], GameManager.prototype, "TimeLabel", void 0);
__decorate([
property(cc.Label)
], GameManager.prototype, "LevelLabel", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "Guide", void 0);
__decorate([
property(cc.Sprite)
], GameManager.prototype, "progress", void 0);
__decorate([
property(cc.Node)
], GameManager.prototype, "Top", void 0);
GameManager = __decorate([
ccclass
], GameManager);
return GameManager;
}(cc.Component));
exports.default = GameManager;
cc._RF.pop();