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] 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 } }