From 88dd4aea0e68b69e4542f7bdb3792a2747de2182 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 24 Oct 2023 17:39:14 +0800 Subject: [PATCH 1/2] update --- modules/entertainment/room.go | 13 ++++++++-- modules/entertainment/xxlPlat.go | 41 +++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 7d1ad172d..2d4938012 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -124,7 +124,7 @@ func (this *Room) AiOperator() { this.player1.Ps = MaxPs // 交换元素 - _, szMap, oid1, oid2 = this.chessboard.AiSwapGirde() + curScore, szMap, oid1, oid2 = this.chessboard.AiSwapGirde() if this.NexPower != this.curPower { this.round++ } @@ -279,6 +279,15 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } } + // for _, v := range szMap { + // fmt.Printf("======szMap=======\n") + // for index := Width - 1; index >= 0; index-- { + // for j := 0; j < Height; j++ { + // fmt.Printf("%d:%d ", v.Data[index+j*Height].Oid, v.Data[index+j*Height].Color) + // } + // fmt.Printf("\n") + // } + // } // 广播消息 if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ Mpadata: szMap, @@ -294,7 +303,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr }, this.szSession...); err != nil { this.Errorln(err) } - if this.round > this.MaxRound { // 游戏结束 + if this.round > this.MaxRound && this.NexPower == this.player1.Uid { // 游戏结束 this.GameOver() return } diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index d17b85461..a3aaa51e0 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -85,12 +85,12 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) { func (this *MapData) SetMap() { sz2 := []int32{ - 5, 1, 2, 5, 1, 5, 2, - 5, 2, 3, 1, 2, 4, 4, - 4, 1, 1, 3, 6, 4, 1, + 1, 1, 2, 5, 1, 5, 2, + 3, 2, 3, 1, 2, 4, 4, + 2, 1, 1, 3, 6, 4, 1, 1, 3, 1, 4, 3, 6, 3, 1, 3, 3, 5, 1, 6, 1, - 5, 1, 5, 5, 1, 3, 1, + 5, 1, 2, 5, 1, 3, 1, 1, 1, 5, 1, 2, 1, 4, } var pos int @@ -461,15 +461,14 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData) { } score += curScore // 总分 - this.DropGirde() - if curScore > 0 { - this.Debugf() + if this.DropGirde() { szMap = append(szMap, &pb.MapData{ - Data: this.Plat, + Data: this.GetPalat(), CurSocre: curScore, Xgrid: count, }) } + // 检查掉落 this.operElem = []int32{} // 初始化操作元素 if curScore == 0 { @@ -481,12 +480,13 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData) { } // 下落 生成新的格子 (返回掉落所获得的分数) -func (this *MapData) DropGirde() { - +func (this *MapData) DropGirde() bool { + bDrop := false for i := 0; i < Width; i++ { for j := 0; j < Height; j++ { index := i*Width + j if this.Plat[index].Color == 0 { // 说明这列有空 + bDrop = true var add int for m := j + 1; m < Height; m++ { k1 := i*Width + m @@ -505,11 +505,23 @@ func (this *MapData) DropGirde() { } } - return + return bDrop +} +func (this *MapData) GetPalat() (data []*pb.GirdeData) { + for _, v := range this.Plat { + data = append(data, &pb.GirdeData{ + Oid: v.Oid, + Color: v.Color, + Cid: v.Cid, + Score: v.Score, + Special: v.Special, + }) + } + return data } // ai操作 -func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32, oid2 int32) { +func (this *MapData) AiSwapGirde() (score int32, szMap []*pb.MapData, oid1 int32, oid2 int32) { for pos := 0; pos < Total; pos++ { y := pos % Height @@ -523,8 +535,9 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32, oid1 = 0 oid2 = 0 } else { + score += s szMap = append(szMap, m...) - bSwap = true + break } } @@ -540,7 +553,7 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32, oid2 = 0 } else { szMap = append(szMap, m...) - bSwap = true + score += s break } } From a640c50d22263074d3b5c72e6b238515a23b4c4a Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 24 Oct 2023 18:09:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E6=8A=80=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 2 +- modules/entertainment/xxlPlat.go | 18 ++++++++++++------ modules/entertainment/xxl_test.go | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 2d4938012..fb10b9df4 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -190,7 +190,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } if this.player1.Energy >= conf.Skillload { this.player1.Energy = conf.Skillload // 清零 - this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue) + curScore, szMap = this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue) } } if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index a3aaa51e0..f265e6dd2 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -4,6 +4,7 @@ import ( "crypto/rand" "fmt" "go_dreamfactory/pb" + "go_dreamfactory/utils" "math/big" ) @@ -463,7 +464,7 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData) { score += curScore // 总分 if this.DropGirde() { szMap = append(szMap, &pb.MapData{ - Data: this.GetPalat(), + Data: this.GetPalatData(), CurSocre: curScore, Xgrid: count, }) @@ -507,7 +508,7 @@ func (this *MapData) DropGirde() bool { return bDrop } -func (this *MapData) GetPalat() (data []*pb.GirdeData) { +func (this *MapData) GetPalatData() (data []*pb.GirdeData) { for _, v := range this.Plat { data = append(data, &pb.GirdeData{ Oid: v.Oid, @@ -563,11 +564,16 @@ func (this *MapData) AiSwapGirde() (score int32, szMap []*pb.MapData, oid1 int32 } // 释放技能 技能id 和参数 -func (this *MapData) SkillUp(skillid int32, value int32) (plat *pb.MapData) { +func (this *MapData) SkillUp(skillid int32, value int32) (score int32, szMap []*pb.MapData) { if skillid == 1 { // 随机消除盘面上X个方块 + ids := utils.RandomNumbers(0, Total-1, int(value)) + for _, id := range ids { + this.Plat[id] = &pb.GirdeData{} + } + if this.DropGirde() { + score, szMap = this.CheckMap(1) + } } - return &pb.MapData{ - Data: this.Plat, - } + return } diff --git a/modules/entertainment/xxl_test.go b/modules/entertainment/xxl_test.go index d53cbb2c5..ae1fa316f 100644 --- a/modules/entertainment/xxl_test.go +++ b/modules/entertainment/xxl_test.go @@ -90,6 +90,7 @@ func Test_Main(t *testing.T) { // if bSwap, m := m.AiSwapGirde(); bSwap { // szMap = append(szMap, m...) // } + m.SkillUp(1, 7) m.SwapGirde(1, 8) m.CheckMap(1)