| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | import { _decorator, Node, instantiate, Vec3, Label } from "cc";import UIParent from "../../../Common/Base/UIParent";import { GameEvent } from "../../../Common/Base/GameEventConfig";import GameMainCtrl from "../../Ctrl/GameMainCtrl";import LevelCtrl from "../../Ctrl/LevelCtrl";import GameUtils from "../../GameUtils/GameUtils";import GameMainLine from "./GameMainLine";import GameMainPoint from "./GameMainPoint";import { GameManager } from "../../../Manager/GameManager";import GameEventManager from "../../../Common/Base/GameEventManager";import { LevelData } from "../../Config/LevelConfig";const { ccclass, property } = _decorator;@ccclassexport default class GameMain extends UIParent {    @property(Node)    pointNode: Node = null;    @property(Node)    pointNodeParent: Node = null;    @property(Node)    ropeNode: Node = null;    @property(Node)    ropeNodeParent: Node = null;    @property(Label)    moveCountLabel: Label = null;    @property(Node)    gameDes: Node = null;    movecount: number = 0;    levelDatas: LevelData[] = []    start() {        GameEventManager.getInstance().pushNodeEvent(this);    }    ShowUI() {        super.ShowUI();        this.InitLevelConfig();        // this.pathNode.scale = GameMainCtrl.getInstance().getViewSize()        let leveldata = this.levelDatas[GameManager.getInstance().curLevel - 1];        if (leveldata == null) return;        GameMainCtrl.getInstance().setNowLevelData(leveldata);        this.createLevelConfig()    }    HideUI() {        super.HideUI();        this.removeObjs();    }    InitUI(uiMain) {        super.InitUI(uiMain)        GameUtils.getInstance().setVisible(this.pointNode, false)        GameUtils.getInstance().setVisible(this.ropeNode, false)        GameUtils.getInstance().setVisible(this.gameDes, false)    }    private removeObjs() {        for (let i = 0; i < this.pointNodeParent.children.length; i++) {            this.pointNodeParent.children[i].getComponent(GameMainPoint).destroySelf();        }        for (let i = 0; i < this.ropeNodeParent.children.length; i++) {            this.ropeNodeParent.children[i].getComponent(GameMainLine).destroySelf();        }    }    InitData() {    }    Pause(flag) {        super.Pause(flag);    }    //获取关卡配置,按配置生成连线    createLevelConfig() {        let levelData = GameMainCtrl.getInstance().getNowLevelData()        console.log(levelData);        let pathList = levelData.pathList        let allPoint: GameMainPoint[] = []        this.movecount = pathList[2];        this.moveCountLabel.string = "剩余拖拽次数:" + this.movecount;        this.removeObjs();        let posList = pathList[0]        for (let index = 0; index < posList.length; index++) {            let data = posList[index];            let obj = instantiate(this.pointNode)            GameUtils.getInstance().setVisible(obj, true)            this.pointNodeParent.addChild(obj)            obj.setPosition(new Vec3(data[0], data[1]))            let spr = obj.getComponent(GameMainPoint)            spr.resetData(index)            allPoint.push(spr)        }        let allLine: GameMainLine[] = []        let idList = pathList[1]        for (let index = 0; index < idList.length; index++) {            let rope = idList[index];            let pointOne = allPoint[rope[0]]            let pointTwe = allPoint[rope[1]]            let obj = instantiate(this.ropeNode)            GameUtils.getInstance().setVisible(obj, true)            this.ropeNodeParent.addChild(obj)            let spr = obj.getComponent(GameMainLine)            spr.resetData(pointOne, pointTwe)            allLine.push(spr)            pointOne.addRopeData({ rope: spr, linkPoint: pointTwe })            pointTwe.addRopeData({ rope: spr, linkPoint: pointOne })        }        // for (let index = 0; index < allPoint.length; index++) {        //     let line = allPoint[index];        //     line.resetPointLine()        // }        GameMainCtrl.getInstance().setAllPointList(allPoint)        GameMainCtrl.getInstance().setAllLineList(allLine)        GameMainCtrl.getInstance().resetLineIntersection()    }    onClickShowDes() {        GameUtils.getInstance().setVisible(this.gameDes, true)    }    onClickCloseDes() {        GameUtils.getInstance().setVisible(this.gameDes, false)    }    onDispathcGameEvent(eventId: GameEvent, eventData: any) {        switch (eventId) {            case GameEvent.MonkeyMove:                {                    this.movecount--;                    if (this.movecount > 0) {                        this.moveCountLabel.string = "剩余拖拽次数:" + this.movecount;                    } else {//游戏结束                        GameManager.getInstance().gameFail();                    }                }                break            default:                super.onDispathcGameEvent(eventId, eventData);                break;        }    }    InitLevelConfig() {        this.levelDatas = [];        let levelConfig = LevelCtrl.getInstance().getLevelConfig()        for (let index = 0; index < levelConfig.length; index++) {            let data = levelConfig[index];//每关的点信息            let levelData = { level: index + 1, pathList: data }            this.levelDatas.push(levelData);        }    }}
 |