觉醒时刻
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.
 
 
 

450 lines
16 KiB

import User from "../../../FrameWork/User/User"
import Common5 from "../../../Platform/th/Common5"
// import MeiNvZhaoMuManager, { ZhaoMuGameType } from "../../MeiNvZhaoMu/MeiNvZhaoMuManager"
enum MaJiangType{
// CaiNiaoJu=0,//菜鸟局
// RuMenJu,//入门局
GaoShouJu,//高手局
}
//1~9万 11~19筒 21~29条 51~57东南西北中发白
let MaJiangInitConfig = [
// {gameType:MaJiangType.CaiNiaoJu,shouYi:8000,jiangLi:80000,zhuangXiuFei:2000000,line:8,col:6,contentScale:1,typeData:[1,2,3,4,5,6,7,8,9,11,12,13]},
// {gameType:MaJiangType.RuMenJu,shouYi:12000,jiangLi:500000,zhuangXiuFei:6000000,line:10,col:8,contentScale:1,typeData:[1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,55,56]},
{gameType:MaJiangType.GaoShouJu,shouYi:16000,jiangLi:1000000,zhuangXiuFei:30000000,line:12,col:10,contentScale:0.8,typeData:[1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,21,22,23,24,25,26,27,28,29,55,56,57]},
]
export enum MoveDir{
None=0,
Up,
Down,
Left,
Right
}
export default class YiMaJiangManager{
public static initAllData(){
this.maJiangDataArr = []
this.moveTempMjDataArr = []
this.curMoveStep = -1
}
public static singleMjWidth = 74
public static singleMjHeight = 82
public static maJiangDataArr = []//全部麻将数据
public static moveTempMjDataArr = []//移动时临时的全部麻将数据
public static curMoveStep = -1//记录当前移动步骤(移动时有变动才刷新data)
public static curGameType = 0
public static setCurGameType(type){
this.curGameType = type
}
public static getCurGameType(){
return this.curGameType
}
public static touchStartInitData(){
this.moveTempMjDataArr = []
this.curMoveStep = -1
}
public static getCurMoveStep(){
return this.curMoveStep
}
public static getMjConfig(){
return MaJiangInitConfig[this.curGameType]
}
public static getAllMjConfig(){
return MaJiangInitConfig
}
public static setMaJiangInitData(){
this.initAllData()
let typeData = MaJiangInitConfig[this.curGameType].typeData
let tempDataArr = []
for(let i=0;i<typeData.length;i++){
for(let j=0;j<4;j++){
tempDataArr.push(typeData[i])
}
}
tempDataArr = Common5.shuffle(tempDataArr)
let line = MaJiangInitConfig[this.curGameType].line
let col = MaJiangInitConfig[this.curGameType].col
for(let i=0;i<line;i++){
this.maJiangDataArr[i] = []
for(let j=0;j<col;j++){
let num = tempDataArr.pop()
if(num){
this.maJiangDataArr[i].push(num)
}else{
this.maJiangDataArr[i].push(0)
}
}
}
console.log('获取麻将数据',this.maJiangDataArr)
}
public static getMaJiangData(){
return this.maJiangDataArr
}
public static getMoveEndTempMJData(){
return this.moveTempMjDataArr
}
public static setMjDataToTempData(){
this.maJiangDataArr = this.moveTempMjDataArr
this.moveTempMjDataArr = []
}
//检测点击是否可以直接消除
public static checkClickIsCanClearUp(posX,posY){
let mjData = this.maJiangDataArr[posX][posY]
if(mjData == 0){
return null
}
return this.checkIsCanXiaoChu(posX,posY,mjData,this.maJiangDataArr)
}
//检测是否可以直接消除
public static checkIsCanXiaoChu(posX,posY,mjData,maJiangDataArr){
let line = MaJiangInitConfig[this.curGameType].line
let col = MaJiangInitConfig[this.curGameType].col
/*****同行检测*****/
//向左找
for(let j=posY-1;j>=0;j--){
if(maJiangDataArr[posX][j] == 0 ){
continue
}else if(maJiangDataArr[posX][j] == mjData){
return {posX:posX,posY:j}
}else{
break
}
}
//向右找
for(let j=posY+1;j<col;j++){
if(maJiangDataArr[posX][j] == 0 ){
continue
}else if(maJiangDataArr[posX][j] == mjData){
return {posX:posX,posY:j}
}else{
break
}
}
/*****同列检测*****/
//向上找
for(let i=posX-1;i>=0;i--){
if(maJiangDataArr[i][posY] == 0 ){
continue
}else if(maJiangDataArr[i][posY] == mjData){
return {posX:i,posY:posY}
}else{
break
}
}
//向下找
for(let i=posX+1;i<line;i++){
if(maJiangDataArr[i][posY] == 0 ){
continue
}else if(maJiangDataArr[i][posY] == mjData){
return {posX:i,posY:posY}
}else{
break
}
}
return null
}
//消除两个麻将
public static clearUpTwoMJ(mj1,mj2){
this.maJiangDataArr[mj1.posX][mj1.posY] = 0
this.maJiangDataArr[mj2.posX][mj2.posY] = 0
console.log('消除后最新麻将数据==',this.maJiangDataArr)
}
//检测成功
public static checkIsSuccess(){
let line = MaJiangInitConfig[this.curGameType].line
let col = MaJiangInitConfig[this.curGameType].col
for(let i=0;i<line;i++){
for(let j=0;j<col;j++){
//有未消除的即为未结束
if(this.maJiangDataArr[i][j] != 0){
return false
}
}
}
return true
}
//根据选择的麻将和方向获取可以移动的麻将数据
public static getCanMoveMJByDir(dir,mjPosData){
let posX = mjPosData.posX
let posY = mjPosData.posY
// console.log('移动的麻将==',mjPosData)
let line = MaJiangInitConfig[this.curGameType].line
let col = MaJiangInitConfig[this.curGameType].col
let canMoveMjData = []//可移动的麻将数据
let maxMoveStep = 0//最大可移动步数
let isFindKongGe = false//是否发现空格这时候可移动麻将数量停止运算
let isReFindMj = false//是否重新发现麻将这时候空格数计算中断
//往上
if(dir == MoveDir.Up){
for(let i=posX;i>=0;i--){
if(this.maJiangDataArr[i][posY] != 0 ){
if(!isFindKongGe){
canMoveMjData.push({posX:i,posY:posY})
}else{
isReFindMj = true
}
}else{
isFindKongGe = true
if(!isReFindMj){
maxMoveStep++
}
}
}
//往下
}else if(dir == MoveDir.Down){
for(let i=posX;i<line;i++){
if(this.maJiangDataArr[i][posY] != 0 ){
if(!isFindKongGe){
canMoveMjData.push({posX:i,posY:posY})
}else{
isReFindMj = true
}
}else{
isFindKongGe = true
if(!isReFindMj){
maxMoveStep++
}
}
}
//往左
}else if(dir == MoveDir.Left){
for(let j=posY;j>=0;j--){
if(this.maJiangDataArr[posX][j] != 0 ){
if(!isFindKongGe){
canMoveMjData.push({posX:posX,posY:j})
}else{
isReFindMj = true
}
}else{
isFindKongGe = true
if(!isReFindMj){
maxMoveStep++
}
}
}
//往右
}else if(dir == MoveDir.Right){
for(let j=posY;j<col;j++){
if(this.maJiangDataArr[posX][j] != 0 ){
if(!isFindKongGe){
canMoveMjData.push({posX:posX,posY:j})
}else{
isReFindMj = true
}
}else{
isFindKongGe = true
if(!isReFindMj){
maxMoveStep++
}
}
}
}
let result = {canMoveMjData:canMoveMjData,maxMoveStep:maxMoveStep}
// console.log('可以移动的麻将数据==',result)
return result
}
//设置移动时临时的麻将数据
public static setMoveTempMjData(dir,canMoveMjData,moveStep,isNeedCheckStep){
if(isNeedCheckStep && moveStep == this.curMoveStep){
return
}
this.curMoveStep = moveStep
//先将麻将数据都拷贝给临时数据
this.moveTempMjDataArr = Common5.deepClone(this.maJiangDataArr)
//先将需要移动的部分全部置空
for(let i=0;i<canMoveMjData.length;i++){
this.moveTempMjDataArr[canMoveMjData[i].posX][canMoveMjData[i].posY] = 0
}
//移动麻将
for(let i=0;i<canMoveMjData.length;i++){
let posX = 0
let posY = 0
if(dir == MoveDir.Up){
posX = canMoveMjData[i].posX - moveStep
posY = canMoveMjData[i].posY
}else if(dir == MoveDir.Down){
posX = canMoveMjData[i].posX + moveStep
posY = canMoveMjData[i].posY
}else if(dir == MoveDir.Left){
posX = canMoveMjData[i].posX
posY = canMoveMjData[i].posY - moveStep
}else if(dir == MoveDir.Right){
posX = canMoveMjData[i].posX
posY = canMoveMjData[i].posY + moveStep
}
this.moveTempMjDataArr[posX][posY] = this.maJiangDataArr[canMoveMjData[i].posX][canMoveMjData[i].posY]
}
console.log('当前临时麻将数据==',this.moveTempMjDataArr)
}
//移动停止检测可消除麻将
public static moveEndCheckXiaoChu(dir,canMoveMjData,moveStep,mjPosData){
if(moveStep == 0){
return null
}
let myPosData = this.getCurClickCardPosData(dir,mjPosData,moveStep)
let mjData = this.moveTempMjDataArr[myPosData.posX][myPosData.posY]
let mj2 = this.checkIsCanXiaoChu(myPosData.posX,myPosData.posY,mjData,this.moveTempMjDataArr)
return {mj1:myPosData,mj2:mj2}
}
public static getCurClickCardPosData(dir,mjPosData,moveStep){
let myPosData = {posX:mjPosData.posX,posY:mjPosData.posY}
if(dir == MoveDir.Up){
myPosData.posX = mjPosData.posX - moveStep
}else if(dir == MoveDir.Down){
myPosData.posX = mjPosData.posX + moveStep
}else if(dir == MoveDir.Left){
myPosData.posY = mjPosData.posY - moveStep
}else if(dir == MoveDir.Right){
myPosData.posY = mjPosData.posY + moveStep
}
return myPosData
}
//比较临时牌与正常牌差异差异的即为需要移动的牌
public static compareTempMjData(){
let tab = []
let line = MaJiangInitConfig[this.curGameType].line
let col = MaJiangInitConfig[this.curGameType].col
for(let i=0;i<line;i++){
for(let j=0;j<col;j++){
if(this.maJiangDataArr[i][j] != this.moveTempMjDataArr[i][j] && this.maJiangDataArr[i][j] == 0 ){
let posData = {posX:i,posY:j}
tab.push(posData)
}
}
}
return tab
}
//重新洗牌
public static chongXinXiPai(){
let tempArr = []
let line = MaJiangInitConfig[this.curGameType].line
let col = MaJiangInitConfig[this.curGameType].col
//先取出不为空的数据
for(let i=0;i<line;i++){
for(let j=0;j<col;j++){
if(this.maJiangDataArr[i][j] != 0){
tempArr.push(this.maJiangDataArr[i][j])
}
}
}
tempArr = Common5.shuffle(tempArr)
//重新打乱顺序赋值
for(let i=0;i<line;i++){
for(let j=0;j<col;j++){
if(this.maJiangDataArr[i][j] != 0){
this.maJiangDataArr[i][j] = tempArr.pop()
}
}
}
console.log('重新洗牌后数据==',this.maJiangDataArr)
}
//获取提示数据
public static getTiShiMjData(){
/********首先检测直接点击是否可以消除********/
let line = MaJiangInitConfig[this.curGameType].line
let col = MaJiangInitConfig[this.curGameType].col
for(let i=0;i<line;i++){
for(let j=0;j<col;j++){
if(this.maJiangDataArr[i][j] != 0){
let mj2 = this.checkClickIsCanClearUp(i,j)
if(mj2){
let mj1 = {posX:i,posY:j}
console.log('11111提示麻将数据==',mj1,mj2)
return {mj1:mj1,mj2:mj2}
}
}
}
}
/********检测每个麻将上下左右移动n步数可否消除********/
for(let i=0;i<line;i++){
for(let j=0;j<col;j++){
if(this.maJiangDataArr[i][j] != 0){
let mjPosData = {posX:i,posY:j}
let startDir = MoveDir.Up
let endDir = MoveDir.Right
//遍历上下左右四个方向
for(let dir=startDir;dir<=endDir;dir++){
let canMoveMJInfo = YiMaJiangManager.getCanMoveMJByDir(dir,mjPosData)
if(!canMoveMJInfo){
continue
}
let canMoveMjData = canMoveMJInfo.canMoveMjData
let maxMoveStep = canMoveMJInfo.maxMoveStep
if(maxMoveStep <= 0){
continue
}
//遍历每移动步数
for(let moveStep =1;moveStep<=maxMoveStep;moveStep++){
YiMaJiangManager.setMoveTempMjData(dir,canMoveMjData,moveStep,false)
let result = YiMaJiangManager.moveEndCheckXiaoChu(dir,canMoveMjData,moveStep,mjPosData)
//可消除直接停在当前位置
if(result && result.mj2){
result.mj1 = mjPosData
console.log('22222提示麻将数据==',result)
return result
}
}
}
}
}
}
return null
}
public static setYiMaJiangLockArray(id,isUnLock){
User.setYiMaJiangLockArray(MaJiangInitConfig.length,id,isUnLock)
}
public static getYiMaJiangLockArray(){
return User.getYiMaJiangLockArray(MaJiangInitConfig.length)
}
// //每秒收益
// public static getYiMaJiangPerSecondMoney(){
// let zongShouYi = 0
// let localZhaoMuData = MeiNvZhaoMuManager.getMeiNvZhaoMuData()
// let zhaoMuBeiShu = localZhaoMuData[ZhaoMuGameType.YiMaJiang].zhaoMuBeiShu
// let localInfo = this.getYiMaJiangLockArray()
// let mjConfig = this.getAllMjConfig()
// for(let i=0;i<mjConfig.length;i++){
// //已解锁
// if(localInfo[i]){
// let shouYi = mjConfig[i].shouYi * zhaoMuBeiShu
// zongShouYi += shouYi
// //未解锁
// }else{
// }
// }
// return zongShouYi
// }
}