You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
388 lines
14 KiB
388 lines
14 KiB
1 week ago
|
|
||
|
import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
|
||
|
import EventMgr from "../../../FrameWork/Event/EventMgr";
|
||
|
import AppPlatform from "../../../FrameWork/Util/AppPlatform";
|
||
|
import Common5 from "../../../Platform/th/Common5";
|
||
|
import TaskManager, { MainTaskIdEnum } from "../../JuQingChat/TaskManager";
|
||
|
import UserManager from "../../Manager/UserManager";
|
||
|
import PrefabManage, { GameType } from "../../PrefabManager/PrefabManage";
|
||
|
import SingleMaJiang from "./SingleMaJiang";
|
||
|
import YiMaJiangManager, { MoveDir } from "./YiMaJiangManager";
|
||
|
import YiMaJiangResult from "./YiMaJiangResult";
|
||
|
|
||
|
|
||
|
const { ccclass, property } = cc._decorator;
|
||
|
|
||
|
@ccclass
|
||
|
export default class YiMaJiang extends cc.Component {
|
||
|
|
||
|
@property(cc.Prefab)
|
||
|
singleMjPrefab: cc.Prefab = null;
|
||
|
|
||
|
@property(cc.Node)
|
||
|
contentNode: cc.Node = null;
|
||
|
|
||
|
@property(cc.Node)
|
||
|
tipBtn: cc.Node = null;
|
||
|
|
||
|
@property(cc.Node)
|
||
|
tipBtnAd: cc.Node = null;
|
||
|
|
||
|
@property(cc.Node)
|
||
|
wanFaYanShi: cc.Node = null;
|
||
|
|
||
|
cardNodeList = []
|
||
|
canMoveMJInfo = null
|
||
|
curMoveStep = -1
|
||
|
|
||
|
cardPositionList = []
|
||
|
isXiaoChuAction = false//正在消牌中,不能操作
|
||
|
// cardZIndex:number = 100
|
||
|
public static _instance = null
|
||
|
leftFreeTipNum:number = 2
|
||
|
onLoad() {
|
||
|
YiMaJiang._instance = this
|
||
|
|
||
|
EventMgr.onEvent_custom(ryw_Event.XiaoChuMJ, (mj1, mj2) => {
|
||
|
this.clearUpTwoMJ(mj1, mj2);
|
||
|
}, this);
|
||
|
|
||
|
EventMgr.onEvent_custom(ryw_Event.MoveMJ, (dir, moveStep, mjPosData, disData, canMoveMJInfo) => {
|
||
|
this.moveAllTiled(dir, moveStep, mjPosData, disData, canMoveMJInfo);
|
||
|
}, this);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
start() {
|
||
|
|
||
|
}
|
||
|
initView(type) {
|
||
|
YiMaJiangManager.setCurGameType(type)
|
||
|
YiMaJiangManager.setMaJiangInitData()
|
||
|
this.refreshView()
|
||
|
this.refreshTipNum()
|
||
|
}
|
||
|
refreshTipNum(){
|
||
|
if(this.leftFreeTipNum <= 0){
|
||
|
this.tipBtn.active = false
|
||
|
this.tipBtnAd.active = true
|
||
|
}else{
|
||
|
this.tipBtn.active = true
|
||
|
this.tipBtnAd.active = false
|
||
|
}
|
||
|
this.tipBtn.getChildByName('leftNum').getComponent(cc.Label).string = ''+this.leftFreeTipNum
|
||
|
}
|
||
|
public static getInstance() {
|
||
|
return YiMaJiang._instance
|
||
|
}
|
||
|
setIsXiaoChuAction(bTrue) {
|
||
|
this.isXiaoChuAction = bTrue
|
||
|
}
|
||
|
getIsXiaoChuAction() {
|
||
|
return this.isXiaoChuAction
|
||
|
}
|
||
|
setCanMoveMJInfo(tab) {
|
||
|
this.canMoveMJInfo = tab
|
||
|
}
|
||
|
getCanMoveMJInfo() {
|
||
|
return this.canMoveMJInfo
|
||
|
}
|
||
|
|
||
|
refreshView() {
|
||
|
this.contentNode.removeAllChildren()
|
||
|
let mjData = YiMaJiangManager.getMaJiangData()
|
||
|
for (let i = 0; i < mjData.length; i++) {
|
||
|
this.cardNodeList[i] = []
|
||
|
this.cardPositionList[i] = []
|
||
|
for (let j = 0; j < mjData[i].length; j++) {
|
||
|
let mj = cc.instantiate(this.singleMjPrefab)
|
||
|
mj.getComponent(SingleMaJiang).initCard(i, j, mjData[i][j])
|
||
|
mj.active = true
|
||
|
mj.parent = this.contentNode
|
||
|
this.cardNodeList[i][j] = mj
|
||
|
|
||
|
let _x = mj.getComponent(SingleMaJiang).getCardX()
|
||
|
let _y = mj.getComponent(SingleMaJiang).getCardY()
|
||
|
this.cardPositionList[i][j] = { x: _x, y: _y }
|
||
|
}
|
||
|
}
|
||
|
let mjConfig = YiMaJiangManager.getMjConfig()
|
||
|
this.contentNode.width = YiMaJiangManager.singleMjWidth * mjData[0].length + 30
|
||
|
this.contentNode.height = YiMaJiangManager.singleMjHeight * mjData.length + 30
|
||
|
this.contentNode.scale = mjConfig.contentScale
|
||
|
}
|
||
|
clearTipIcon() {
|
||
|
let mjData = YiMaJiangManager.getMaJiangData()
|
||
|
for (let i = 0; i < mjData.length; i++) {
|
||
|
|
||
|
for (let j = 0; j < mjData[i].length; j++) {
|
||
|
this.cardNodeList[i][j].getComponent(SingleMaJiang).showTipIcon(false)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//清除两个麻将
|
||
|
clearUpTwoMJ(mj1, mj2) {
|
||
|
YiMaJiangManager.clearUpTwoMJ(mj1, mj2)
|
||
|
this.cardNodeList[mj1.posX][mj1.posY].getComponent(SingleMaJiang).turnAroundCard(mj1.posX, mj1.posY, 0)
|
||
|
this.cardNodeList[mj2.posX][mj2.posY].getComponent(SingleMaJiang).turnAroundCard(mj2.posX, mj2.posY, 0)
|
||
|
this.clearTipIcon()
|
||
|
|
||
|
this.checkResult()
|
||
|
}
|
||
|
|
||
|
//移动麻将
|
||
|
moveAllTiled(dir, moveStep, mjPosData, disData, canMoveMJInfo) {
|
||
|
// console.log('移动麻将==',mjData,disData,canMoveMJInfo)
|
||
|
if (!canMoveMJInfo) {
|
||
|
return
|
||
|
}
|
||
|
let canMoveMjData = canMoveMJInfo.canMoveMjData
|
||
|
let maxMoveStep = canMoveMJInfo.maxMoveStep
|
||
|
if (maxMoveStep <= 0) {
|
||
|
return
|
||
|
}
|
||
|
for (let i = 0; i < canMoveMjData.length; i++) {
|
||
|
let _x = this.cardNodeList[canMoveMjData[i].posX][canMoveMjData[i].posY].getComponent(SingleMaJiang).getCardX()
|
||
|
let _y = this.cardNodeList[canMoveMjData[i].posX][canMoveMjData[i].posY].getComponent(SingleMaJiang).getCardY()
|
||
|
this.cardNodeList[canMoveMjData[i].posX][canMoveMjData[i].posY].x = _x + disData.disX
|
||
|
this.cardNodeList[canMoveMjData[i].posX][canMoveMjData[i].posY].y = _y + disData.disY
|
||
|
this.cardNodeList[canMoveMjData[i].posX][canMoveMjData[i].posY].zIndex = 200
|
||
|
}
|
||
|
|
||
|
if (moveStep == this.curMoveStep) {
|
||
|
return
|
||
|
}
|
||
|
// let trueDir = dir
|
||
|
// if(dir == MoveDir.Up){
|
||
|
// if(moveStep < this.curMoveStep){
|
||
|
// trueDir = MoveDir.Down
|
||
|
// }
|
||
|
// }else if(dir == MoveDir.Down){
|
||
|
// if(moveStep < this.curMoveStep){
|
||
|
// trueDir = MoveDir.Up
|
||
|
// }
|
||
|
// }else if(dir == MoveDir.Left){
|
||
|
// if(moveStep < this.curMoveStep){
|
||
|
// trueDir = MoveDir.Right
|
||
|
// }
|
||
|
|
||
|
// }else if(dir == MoveDir.Right){
|
||
|
// if(moveStep < this.curMoveStep){
|
||
|
// trueDir = MoveDir.Left
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
|
||
|
|
||
|
let clickCurPos = YiMaJiangManager.getCurClickCardPosData(dir, mjPosData, moveStep)
|
||
|
|
||
|
console.log('moveStep,clickCurPos==', moveStep, clickCurPos)
|
||
|
let moveStartPosX = clickCurPos.posX
|
||
|
let moveStartPosY = clickCurPos.posY
|
||
|
|
||
|
let moveEndPosX = clickCurPos.posX
|
||
|
let moveEndPosY = clickCurPos.posY
|
||
|
if (this.curMoveStep >= 0) {
|
||
|
if (dir == MoveDir.Up) {
|
||
|
moveStartPosX = clickCurPos.posX - canMoveMjData.length + 1
|
||
|
moveStartPosY = clickCurPos.posY
|
||
|
|
||
|
moveEndPosX = clickCurPos.posX + 1
|
||
|
moveEndPosY = clickCurPos.posY
|
||
|
|
||
|
} else if (dir == MoveDir.Down) {
|
||
|
moveStartPosX = clickCurPos.posX + canMoveMjData.length - 1
|
||
|
moveStartPosY = clickCurPos.posY
|
||
|
|
||
|
moveEndPosX = clickCurPos.posX - 1
|
||
|
moveEndPosY = clickCurPos.posY
|
||
|
} else if (dir == MoveDir.Left) {
|
||
|
moveStartPosX = clickCurPos.posX
|
||
|
moveStartPosY = clickCurPos.posY - canMoveMjData.length + 1
|
||
|
|
||
|
moveEndPosX = clickCurPos.posX
|
||
|
moveEndPosY = clickCurPos.posY + 1
|
||
|
|
||
|
} else if (dir == MoveDir.Right) {
|
||
|
moveStartPosX = clickCurPos.posX
|
||
|
moveStartPosY = clickCurPos.posY + canMoveMjData.length - 1
|
||
|
|
||
|
moveEndPosX = clickCurPos.posX
|
||
|
moveEndPosY = clickCurPos.posY - 1
|
||
|
}
|
||
|
|
||
|
if (moveStep < this.curMoveStep) {
|
||
|
if (dir == MoveDir.Up) {
|
||
|
moveStartPosX = clickCurPos.posX - canMoveMjData.length
|
||
|
moveStartPosY = clickCurPos.posY
|
||
|
|
||
|
} else if (dir == MoveDir.Down) {
|
||
|
moveStartPosX = clickCurPos.posX + canMoveMjData.length
|
||
|
moveStartPosY = clickCurPos.posY
|
||
|
} else if (dir == MoveDir.Left) {
|
||
|
moveStartPosX = clickCurPos.posX
|
||
|
moveStartPosY = clickCurPos.posY - canMoveMjData.length
|
||
|
|
||
|
} else if (dir == MoveDir.Right) {
|
||
|
moveStartPosX = clickCurPos.posX
|
||
|
moveStartPosY = clickCurPos.posY + canMoveMjData.length
|
||
|
}
|
||
|
|
||
|
let node = this.cardNodeList[moveStartPosX][moveStartPosY]
|
||
|
let _x = node.getComponent(SingleMaJiang).getCardX()
|
||
|
let _y = node.getComponent(SingleMaJiang).getCardY()
|
||
|
cc.tween(node)
|
||
|
.to(0.2, { x: _x, y: _y })
|
||
|
.start()
|
||
|
} else {
|
||
|
let node = this.cardNodeList[moveStartPosX][moveStartPosY]
|
||
|
// let positionX = this.cardNodeList[moveEndPosX][moveEndPosY].getComponent(SingleMaJiang).getCardX()
|
||
|
// let positionY = this.cardNodeList[moveEndPosX][moveEndPosY].getComponent(SingleMaJiang).getCardY()
|
||
|
node.stopAllActions()
|
||
|
cc.tween(node)
|
||
|
.to(0.2, { x: this.cardPositionList[moveEndPosX][moveEndPosY].x, y: this.cardPositionList[moveEndPosX][moveEndPosY].y })
|
||
|
.start()
|
||
|
}
|
||
|
|
||
|
// console.log('初始位置==',node.x,node.y)
|
||
|
// console.log('结束位置==',node.x,node.y)
|
||
|
}
|
||
|
this.curMoveStep = moveStep
|
||
|
|
||
|
console.log('moveStartPosX,moveStartPosY==', moveStartPosX, moveStartPosY)
|
||
|
console.log('moveEndPosX,moveEndPosY==', moveEndPosX, moveEndPosY)
|
||
|
}
|
||
|
|
||
|
//麻将回到初始位置
|
||
|
moveToOriginPos() {
|
||
|
this.curMoveStep = -1
|
||
|
let mjData = YiMaJiangManager.getMaJiangData()
|
||
|
for (let i = 0; i < mjData.length; i++) {
|
||
|
for (let j = 0; j < mjData[i].length; j++) {
|
||
|
this.cardNodeList[i][j].getComponent(SingleMaJiang).initCard(i, j, mjData[i][j])
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//麻将固定位置
|
||
|
moveToFixedPos(mj1, mj2) {
|
||
|
this.curMoveStep = -1
|
||
|
let tempData = YiMaJiangManager.getMoveEndTempMJData()
|
||
|
for (let i = 0; i < tempData.length; i++) {
|
||
|
for (let j = 0; j < tempData[i].length; j++) {
|
||
|
this.cardNodeList[i][j].getComponent(SingleMaJiang).initCard(i, j, tempData[i][j])
|
||
|
}
|
||
|
}
|
||
|
YiMaJiangManager.setMjDataToTempData()
|
||
|
this.clearUpTwoMJ(mj1, mj2);
|
||
|
// EventMgr.emitEvent_custom(ryw_Event.XiaoChuMJ,mj1,mj2 )
|
||
|
}
|
||
|
|
||
|
onBtnClickXiPai() {
|
||
|
let tab = {
|
||
|
onClose: (finish) => {
|
||
|
if (finish) {
|
||
|
Common5.ReportDY("inLevel", '移麻将-AD-洗牌');
|
||
|
|
||
|
YiMaJiangManager.chongXinXiPai()
|
||
|
this.refreshView()
|
||
|
}
|
||
|
else {
|
||
|
|
||
|
Common5.showTips_custom("广告未观看完");
|
||
|
}
|
||
|
},
|
||
|
onFailed: () => { }
|
||
|
}
|
||
|
AppPlatform.playVideo_custom(tab);
|
||
|
}
|
||
|
onBtnClickTiShi() {
|
||
|
this.leftFreeTipNum--
|
||
|
this.refreshTipNum()
|
||
|
this.tipCallFunc()
|
||
|
}
|
||
|
onBtnClickTiShiAD(){
|
||
|
let tab = {
|
||
|
onClose: (finish) => {
|
||
|
if (finish) {
|
||
|
Common5.ReportDY("inLevel", '移麻将-AD-提示');
|
||
|
this.tipCallFunc()
|
||
|
}
|
||
|
else {
|
||
|
|
||
|
Common5.showTips_custom("广告未观看完");
|
||
|
}
|
||
|
},
|
||
|
onFailed: () => { }
|
||
|
}
|
||
|
AppPlatform.playVideo_custom(tab);
|
||
|
}
|
||
|
tipCallFunc(){
|
||
|
let result = YiMaJiangManager.getTiShiMjData()
|
||
|
if (result) {
|
||
|
let mj1 = result.mj1
|
||
|
let mj2 = result.mj2
|
||
|
this.cardNodeList[mj1.posX][mj1.posY].getComponent(SingleMaJiang).showTipIcon(true)
|
||
|
this.cardNodeList[mj2.posX][mj2.posY].getComponent(SingleMaJiang).showTipIcon(true)
|
||
|
}
|
||
|
}
|
||
|
checkResult() {
|
||
|
if (YiMaJiangManager.checkIsSuccess()) {
|
||
|
this.showResultSuccess()
|
||
|
} else {
|
||
|
let result = YiMaJiangManager.getTiShiMjData()
|
||
|
if (result) {
|
||
|
|
||
|
} else {
|
||
|
this.showResultFail()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
showResultSuccess() {
|
||
|
this.scheduleOnce(() => {
|
||
|
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_2501);
|
||
|
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_2502);
|
||
|
EventMgr.emitEvent_custom(ryw_Event.RefreshJuQingDuiHua);
|
||
|
this.node.removeFromParent();
|
||
|
this.node.destroy();
|
||
|
}, 2);
|
||
|
return;
|
||
|
let mjConfig = YiMaJiangManager.getMjConfig()
|
||
|
let lingQuCallFunc = () => {
|
||
|
UserManager.addMoney(mjConfig.jiangLi)
|
||
|
this.node.removeFromParent()
|
||
|
}
|
||
|
let shuangBeiLingQuCallFunc = () => {
|
||
|
UserManager.addMoney(mjConfig.jiangLi * 2)
|
||
|
this.node.removeFromParent()
|
||
|
}
|
||
|
PrefabManage.loadPrefabByType(GameType.YiMaJiangResult, null, (prefabNode) => {
|
||
|
prefabNode.getComponent(YiMaJiangResult).initView('success', lingQuCallFunc, shuangBeiLingQuCallFunc)
|
||
|
})
|
||
|
}
|
||
|
showResultFail() {
|
||
|
let restartCallFunc = () => {
|
||
|
let type = YiMaJiangManager.getCurGameType()
|
||
|
this.initView(type)
|
||
|
}
|
||
|
let fuHuoCallFunc = () => {
|
||
|
YiMaJiangManager.chongXinXiPai()
|
||
|
let result = YiMaJiangManager.getTiShiMjData()
|
||
|
if (result) {
|
||
|
} else {
|
||
|
YiMaJiangManager.chongXinXiPai()
|
||
|
}
|
||
|
this.refreshView()
|
||
|
}
|
||
|
PrefabManage.loadPrefabByType(GameType.YiMaJiangResult, null, (prefabNode) => {
|
||
|
prefabNode.getComponent(YiMaJiangResult).initView('fail', restartCallFunc, fuHuoCallFunc)
|
||
|
})
|
||
|
}
|
||
|
onOpenWanFaYanShi(){
|
||
|
this.wanFaYanShi.active = true
|
||
|
}
|
||
|
onCloseWanFaYanShi(){
|
||
|
this.wanFaYanShi.active = false
|
||
|
}
|
||
|
}
|