From 54a8f103b6cd8d9a078110f7416c4056c8061dd3 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 1 Nov 2023 10:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=80=E8=83=BD+=E6=B6=88=E9=99=A4=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 28 ++++++++- modules/entertainment/xxlPlat.go | 96 ++++++++++++++++++++++++++----- modules/entertainment/xxl_test.go | 5 +- 3 files changed, 111 insertions(+), 18 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 76958e735..73116113e 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -164,7 +164,21 @@ func (this *Room) AiOperator() { this.player1.Ps = MaxPs this.round++ } - + // 校验下次是不是消除 + if this.chessboard.CheckAndRefreshPlat() { + this.chessboard.RedsetPlatData() + szMap = append(szMap, &pb.MapData{ + Data: this.chessboard.GetPalatData(), + ChangeType: 1, + }) + } + for _, v := range szMap { // + curScore += v.CurSocre + this.player2.Score += v.CurSocre + v.CurSocre = this.player2.Score + this.player2.Energy += v.CurEnergy + v.CurEnergy = this.player2.Energy + } // 广播消息 if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ Mpadata: szMap, @@ -233,7 +247,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } if this.player1.Energy >= conf.Skillload { this.player1.Energy = 0 // 清零 - if m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue); len(m) > 0 { + if _, m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { szMap = append(szMap, m...) } else { szMap = append(szMap, &pb.MapData{ @@ -265,7 +279,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } if this.player2.Energy >= conf.Skillload { this.player2.Energy = 0 // 清零 - if m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue); len(m) > 0 { + if _, m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { szMap = append(szMap, m...) } else { szMap = append(szMap, &pb.MapData{ @@ -327,6 +341,14 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr return } + // 校验下次是不是消除 + if this.chessboard.CheckAndRefreshPlat() { + this.chessboard.RedsetPlatData() + szMap = append(szMap, &pb.MapData{ + Data: this.chessboard.GetPalatData(), + ChangeType: 1, + }) + } if this.curPower == this.player1.Userinfo.Uid { //权限校验 this.player1.Score += curScore this.player1.Ps-- diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index d90321401..86649a9a8 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -3,6 +3,7 @@ package entertainment import ( "crypto/rand" "fmt" + "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" "math/big" @@ -16,6 +17,7 @@ const ( FiveType = 3 // 5消类型 FourUType = 1 // 4消上下类型 FourLType = 2 // 4消左右类型 + BoomType = 4 // 炸弹类型 ) type Girde struct { @@ -56,6 +58,7 @@ func (this *MapData) CreateGride(index int32) *pb.GirdeData { // 初始化地图数据 func (this *MapData) InitMap(module *Entertainment) { this.module = module + this.oid = 1000 // 方便观察 从1000开始 this.Plat = make([]*pb.GirdeData, Width*Height) for i := 0; i < Width*Height; i++ { @@ -86,11 +89,11 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) { func (this *MapData) Debugf() { fmt.Printf("================\n") - //var v int + var v int for index := Width - 1; index >= 0; index-- { for j := 0; j < Height; j++ { - //v = index + j*7 - fmt.Printf("%d:%d ", this.Plat[index+j*Height].Cid, this.Plat[index+j*Height].Color) + v = index + j*7 + fmt.Printf("%d:%d ", v, this.Plat[index+j*Height].Cid) } fmt.Printf("\n") @@ -313,14 +316,24 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc energy++ } curScore += this.Plat[id].Score - if conf, err := this.module.configure.GetGameBlock(this.Plat[id].Color, int32(new[id])); err == nil { - this.oid++ // 生成一个新的类型元素 + this.oid++ // 生成一个新的类型元素 + if this.module == nil { // 稍后删掉 方便测试 this.Plat[id] = &pb.GirdeData{ Oid: this.oid, Color: this.Plat[id].Color, - Cid: conf.Key, - Score: conf.Score, - Special: conf.Type, + Cid: 2*(this.Plat[id].Color-1) + 6 + int32(new[id]), + Score: 1, + Special: int32(new[id]), + } + } else { + if conf, err := this.module.configure.GetGameBlock(this.Plat[id].Color, int32(new[id])); err == nil { + this.Plat[id] = &pb.GirdeData{ + Oid: this.oid, + Color: this.Plat[id].Color, + Cid: conf.Key, + Score: conf.Score, + Special: conf.Type, + } } } continue @@ -336,7 +349,15 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc x[id%Height+i*Width] = struct{}{} } } else if s == FiveType { // 随机消除 - + // 获取配置 + if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { + if xc, _ := this.SkillUp(1, c.Value, false); len(xc) > 0 { + //szMap = append(szMap, sz...) + for key := range xc { + x[key] = struct{}{} + } + } + } } } x[id] = struct{}{} @@ -398,6 +419,8 @@ func (this *MapData) DropGirde() bool { //this.Debugf() return bDrop } + +// 深拷贝 func (this *MapData) GetPalatData() (data []*pb.GirdeData) { for _, v := range this.Plat { data = append(data, &pb.GirdeData{ @@ -455,15 +478,41 @@ func (this *MapData) AiSwapGirde() (szMap []*pb.MapData, oid1 int32, oid2 int32, } // 释放技能 技能id 和参数 -func (this *MapData) SkillUp(skillid int32, value int32) (szMap []*pb.MapData) { +func (this *MapData) SkillUp(skillid int32, value int32, bDrop bool) (x map[int]struct{}, szMap []*pb.MapData) { if skillid == 1 { // 随机消除盘面上X个方块 - + x = make(map[int]struct{}) ids := utils.RandomNumbers(0, Total-1, int(value)) for _, id := range ids { - this.Plat[id] = &pb.GirdeData{} + s := this.Plat[id].Special + if s != 0 { + if s == FourUType { // 4消上下类型 + for i := 0; i < Height; i++ { // id 的一条线位置 + x[(id/Width)*Height+i] = struct{}{} + } + } else if s == FourLType { // 左右类型 + for i := 0; i < Width; i++ { // id 的一条线位置 + x[id%Height+i*Width] = struct{}{} + } + } else if s == FiveType { // 随机消除 + // 获取配置 + if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { + if xc, _ := this.SkillUp(1, c.Value, false); len(xc) > 0 { // 递归调用 + for key := range xc { + x[key] = struct{}{} + } + } + } + } + } + x[id] = struct{}{} } - if this.DropGirde() { - szMap, _ = this.CheckMap(1, false) + if bDrop { + for key := range x { + this.Plat[key] = &pb.GirdeData{} + } + if this.DropGirde() { + szMap, _ = this.CheckMap(1, false) + } } } return @@ -497,6 +546,7 @@ func (this *MapData) SetMap() { } } this.SetIndelibilityPlat() + } // 校验当前地图 有没有能消除的 @@ -630,3 +680,21 @@ func (this *MapData) SetIndelibilityPlat() { } } } + +// 重新洗牌 +func (this *MapData) RedsetPlatData() { + + for i := 0; i < Total-1; i++ { + targetId := comm.GetRandNum(0, Total-1) + if i == int(targetId) { + continue + } + tmp := new(pb.GirdeData) + *tmp = *this.Plat[i] + this.Plat[i] = this.Plat[targetId] + this.Plat[targetId] = tmp + } + this.Debugf() + + this.SetIndelibilityPlat() +} diff --git a/modules/entertainment/xxl_test.go b/modules/entertainment/xxl_test.go index 674ddf864..3508d5d49 100644 --- a/modules/entertainment/xxl_test.go +++ b/modules/entertainment/xxl_test.go @@ -85,6 +85,9 @@ func Test_Main(t *testing.T) { m := new(entertainment.MapData) m.InitMap(nil) m.SetMap() + b := m.CheckAndRefreshPlat() + fmt.Printf("xxxx%v", b) + m.RedsetPlatData() m.SwapGirde(1, 8) m.CheckMap(1, false) m.Debugf() @@ -109,7 +112,7 @@ func Test_Main(t *testing.T) { // if bSwap, m := m.AiSwapGirde(); bSwap { // szMap = append(szMap, m...) // } - m.SkillUp(1, 7) + m.SkillUp(1, 7, true) m.SwapGirde(1, 8) //m.CheckMap(1)