From 48d84dc0bc747534da0258678103d7d55a9fe542 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 23 Oct 2023 15:32:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B6=88=E9=99=A4?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 171 +++++++++++++++--------------- modules/entertainment/xxlPlat.go | 147 ++++++++++++++++--------- modules/entertainment/xxl_test.go | 7 +- pb/entertain_msg.pb.go | 64 ++++++----- 4 files changed, 228 insertions(+), 161 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index d9768f08d..61a45ae5e 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -27,45 +27,57 @@ type Room struct { player2 *pb.PlayerData // 玩家2 chessboard *MapData module *Entertainment - power string // 谁的权限 round int32 // 轮数 operatetimer *timewheel.Task //操作倒计时定时器 aiTimer *timewheel.Task //AI操作随机做个延时 + curPower string // 当前操作的玩家 + NexPower string // 下一个操作的玩家 } func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - } - if this.player1.Uid == this.power { // 给玩家2 - this.power = this.player2.Uid - this.player2.Ps = MaxPs // 恢复体力 - } else { // 权限给1号玩家 - this.power = this.player1.Uid - this.player1.Ps = MaxPs // 恢复体力 - } - this.round++ // 回合+1 - if this.round > MaxRound*2 { // 游戏结束 + if this.player1.Uid == this.curPower { // 给玩家2 + this.player1.Ps-- + if this.player1.Ps <= 0 { // 体力消耗完权限给下一个人 + this.NexPower = this.player2.Uid + this.player2.Ps = MaxPs // 恢复体力 + } + } else { // 权限给1号玩家 + this.player2.Ps-- + if this.player2.Ps <= 0 { + this.curPower = this.player1.Uid + this.player1.Ps = MaxPs // 恢复体力 + } + } + if this.curPower != this.NexPower { // 变更权限的适合 + this.round++ + if this.operatetimer != nil { + timewheel.Remove(this.operatetimer) + } // 回合+1 + this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 + } + if this.round > MaxRound { // 游戏结束 this.GameOver() return } - this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 + var szMap []*pb.MapData szMap = append(szMap, &pb.MapData{ Data: this.chessboard.Plat, }) - //this.module.Debugf("超时%d", configure.Now().Unix()) if err := this.module.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ - Mpadata: szMap, - Power: this.power, - Score: 0, - Round: this.round, - User1: this.player1, - User2: this.player2, + Mpadata: szMap, + Power: this.NexPower, + Curpower: this.curPower, + Score: 0, + Round: this.round, + User1: this.player1, + User2: this.player2, }, this.szSession...); err != nil { this.Errorln(err) } + // 变更权限 + this.curPower = this.NexPower } func (this *Room) InitRoom(module *Entertainment, s1 comm.IUserSession, s2 comm.IUserSession, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room { @@ -84,7 +96,7 @@ func (this *Room) InitRoom(module *Entertainment, s1 comm.IUserSession, s2 comm. player2: p2, chessboard: this.chessboard, module: module, - power: s1.GetUserId(), + curPower: s1.GetUserId(), round: 1, szSession: this.szSession, } @@ -100,8 +112,7 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) { this.module.Debugf("AI 操作\n") this.player2.Ps-- if this.player2.Ps <= 0 { // 权限给下一个人 - this.power = this.player1.Uid - this.round++ + this.NexPower = this.player1.Uid } this.player1.Ps = MaxPs if this.aiTimer != nil { @@ -109,26 +120,30 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) { } // 交换元素 - bSwap := this.chessboard.AiSwapGirde() // 交换格子 - if !bSwap { - this.module.Errorf("AiSwapGirde fialed") - } - - if score, m, _ := this.chessboard.CheckMap(2); score > 0 { - curScore += score + if bSwap, m := this.chessboard.AiSwapGirde(); bSwap { szMap = append(szMap, m...) } + + if this.NexPower != this.curPower { + // 清理旧的计时器 开启一个新的 + if this.operatetimer != nil { + timewheel.Remove(this.operatetimer) + } + this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 + + this.round++ + if this.round > MaxRound { // 游戏结束 + this.GameOver() + return + } + } + this.player2.Score += curScore - // 清理旧的计时器 开启一个新的 - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - } - this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 // 广播消息 if err := this.module.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ Mpadata: szMap, - Power: this.power, + Power: this.curPower, Score: curScore, Round: this.round, User1: this.player1, @@ -147,16 +162,14 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr var szMap []*pb.MapData req := msg.(*pb.EntertainOperatorReq) - if session.GetUserId() != this.power { // 校验是不是你的权限 + if session.GetUserId() != this.curPower { // 校验是不是你的权限 errdata = &pb.ErrorData{ Code: pb.ErrorCode_EntertainNoPower, Title: pb.ErrorCode_EntertainNoPower.ToString(), } return } - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - } + // 交换元素 if b, _ := this.chessboard.SwapGirde(req.Curid, req.Targetid, 1); !b { // 交换格子 errdata = &pb.ErrorData{ @@ -173,17 +186,13 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr //this.player2.Score += curScore // 开启新的定时器 - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - } - this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 - if this.power == this.player1.Uid { //权限校验 + if this.NexPower == this.player1.Uid { //权限校验 this.player1.Score += curScore this.player1.Ps-- if this.player1.Ps <= 0 { // 权限给下一个人 - this.power = this.player2.Uid - + this.NexPower = this.player2.Uid + this.curPower = this.player1.Uid if len(this.szSession) == 1 { // 校验2号玩家是不是AI // 起一个定时器 if this.aiTimer != nil { @@ -191,70 +200,66 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } this.aiTimer = timewheel.Add(time.Second*AITime, this.AiTimeOut) } - this.round++ } this.player2.Ps = MaxPs - } else if this.power == this.player2.Uid { + } else if this.NexPower == this.player2.Uid { this.player2.Score += curScore this.player2.Ps-- if this.player2.Ps <= 0 { // 权限给下一个人 - this.power = this.player1.Uid - this.round++ + this.NexPower = this.player1.Uid + this.curPower = this.player2.Uid //当前操作的玩家 } this.player1.Ps = MaxPs } else { // err 未知权限 return } + if this.NexPower == this.curPower { + this.round++ + if this.operatetimer != nil { + timewheel.Remove(this.operatetimer) + this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 + } + } + if this.round > MaxRound { // 游戏结束 + this.GameOver() + return + } // 广播消息 if err := this.module.SendMsgToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ - Mpadata: szMap, - Power: this.power, - Score: curScore, - Round: this.round, - User1: this.player1, - User2: this.player2, + Mpadata: szMap, + Power: this.curPower, + Curpower: this.NexPower, + Score: curScore, + Round: this.round, + User1: this.player1, + User2: this.player2, }, this.szSession...); err != nil { this.Errorln(err) } + // 变更权限 + this.curPower = this.NexPower case "ready": if len(this.szSession) == 1 { // AI对战的话直接开始游戏 if err := this.module.SendMsgToSession(string(this.module.GetType()), "startgame", &pb.EntertainStartGamePush{ - User1: this.player1, - User2: this.player2, - Mpadata: &pb.MapData{ - Data: this.chessboard.Plat, - }, - Power: this.power, - Round: this.round, + User1: this.player1, + User2: this.player2, + Mpadata: &pb.MapData{Data: this.chessboard.Plat}, + Power: this.NexPower, + Round: this.round, + Roomid: "", }, this.szSession...); err != nil { this.Errorln(err) } - + this.NexPower = this.player1.Uid + this.curPower = this.player1.Uid this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) } - } return } -func (this *Room) StartGame() (errdata *pb.ErrorData) { - - if err := this.module.SendMsgToSession(string(this.module.GetType()), "startgame", &pb.EntertainStartGamePush{ - User1: this.player1, - User2: this.player2, - Mpadata: &pb.MapData{ - Data: this.chessboard.Plat, - }, - Power: this.power, - Round: this.round, - }, this.szSession...); err != nil { - this.Errorln(err) - } - return -} - // 游戏结束 func (this *Room) GameOver() (errdata *pb.ErrorData) { if this.aiTimer != nil { diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index 025b7e9f5..333bfae24 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -27,9 +27,10 @@ type Girde struct { //地图数据 type MapData struct { - Plat []*pb.GirdeData // 地图 - oid int32 // 唯一id - module *Entertainment + Plat []*pb.GirdeData // 地图 + oid int32 // 唯一id + module *Entertainment + operElem []int32 // 当前移动的元素 } // 1~6随机一个数 @@ -64,8 +65,8 @@ func (this *MapData) InitMap(module *Entertainment) { // 交换2个元素(参数 oid ) func (this *MapData) SwapGirde(oldId, newId int32, color int32) (bSwap bool, xCount int32) { - - if (oldId%Height-1 < Total && oldId+1 == newId) || + this.operElem = []int32{} // 初始化 + if (oldId%Height+1 < Total && oldId+1 == newId) || (oldId%Height > 0 && oldId-1 == newId) || (oldId+Width < Total && oldId+Width == newId) || (oldId-Width > 0 && oldId-Width == newId) { @@ -74,6 +75,8 @@ func (this *MapData) SwapGirde(oldId, newId int32, color int32) (bSwap bool, xCo *tmp = *this.Plat[newId] this.Plat[newId] = this.Plat[oldId] this.Plat[oldId] = tmp + this.operElem = append(this.operElem, newId) + this.operElem = append(this.operElem, oldId) } //this.CheckMap(color) return @@ -124,7 +127,9 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i k5 := this.Plat[k+4].Color if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 { - + if k1 == color { + count++ + } this.oid++ // 生成一个新的类型元素 if conf, err := this.module.configure.GetGameBlock(k1, FiveType); err != nil { @@ -150,7 +155,9 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i k5 := this.Plat[k+4*Width].Color if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 { - + if k1 == color { + count++ + } this.oid++ // 生成一个新的类型元素 if conf, err := this.module.configure.GetGameBlock(k1, FiveType); err != nil { @@ -196,6 +203,7 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i } score += this.Plat[id].Score this.Plat[id] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(id)) } } @@ -205,11 +213,15 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i } score += this.Plat[v].Score this.Plat[v] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(v)) } return } func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count int32) { + var ( + newElem int // 生成的一个新的元素CID + ) var xiaochu []int // 即将消除的key for k, v := range this.Plat { if v.Color == 0 { @@ -222,42 +234,19 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i k2 := this.Plat[k+1].Color k3 := this.Plat[k+2].Color k4 := this.Plat[k+3].Color - + newElem = k + 2 if k1 == k2 && k3 == k4 && k2 == k3 { - + for _, v1 := range this.operElem { + if v1 == k2 { + newElem = k + 1 + break + } + } this.oid++ // 生成一个新的类型元素 if this.module != nil { if conf, err := this.module.configure.GetGameBlock(k1, FourUType); err != nil { // 上下类型 - this.Plat[k+1] = &pb.GirdeData{ - Oid: this.oid, - Color: k1, - Cid: conf.Key, - Score: conf.Score, - Special: conf.Type, - } - } else { - xiaochu = append(xiaochu, k+1) - } - } - xiaochu = append(xiaochu, k+1) - xiaochu = append(xiaochu, []int{k, k + 2, k + 3}...) - - bEliminate = true - } - } - if k+3*Width < Total { - k1 := this.Plat[k].Color - k2 := this.Plat[k+Width].Color - k3 := this.Plat[k+2*Width].Color - k4 := this.Plat[k+3*Width].Color - - if k1 == k2 && k3 == k4 && k2 == k3 { - this.oid++ - if this.module != nil { - // 生成一个新的类型元素 - if conf, err := this.module.configure.GetGameBlock(k1, FourLType); err != nil { // 左右类型 - this.Plat[k+Width] = &pb.GirdeData{ + this.Plat[newElem] = &pb.GirdeData{ Oid: this.oid, Color: k1, Cid: conf.Key, @@ -267,14 +256,62 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i if k1 == color { count++ } + } else { + xiaochu = append(xiaochu, newElem) + } + } else { + xiaochu = append(xiaochu, newElem) + } + if newElem == k+1 { + xiaochu = append(xiaochu, []int{k, k + 2, k + 3}...) + } else { + xiaochu = append(xiaochu, []int{k, k + 1, k + 3}...) + } + bEliminate = true + } + } + if k+3*Width < Total { + k1 := this.Plat[k].Color + k2 := this.Plat[k+Width].Color + k3 := this.Plat[k+2*Width].Color + k4 := this.Plat[k+3*Width].Color + + if k1 == k2 && k3 == k4 && k2 == k3 { + newElem = k + 2*Width + if k1 == k2 && k3 == k4 && k2 == k3 { + for _, v1 := range this.operElem { + if v1 == k2 { + newElem = k + Width + break + } + } + this.oid++ + if this.module != nil { + // 生成一个新的类型元素 + if conf, err := this.module.configure.GetGameBlock(k1, FourLType); err != nil { // 左右类型 + this.Plat[newElem] = &pb.GirdeData{ + Oid: this.oid, + Color: k1, + Cid: conf.Key, + Score: conf.Score, + Special: conf.Type, + } + if k1 == color { + count++ + } + } else { + xiaochu = append(xiaochu, k+Width) + } } else { xiaochu = append(xiaochu, k+Width) } + if newElem == k+Width { + xiaochu = append(xiaochu, []int{k, k + 2*Width, k + 3*Width}...) + } else { + xiaochu = append(xiaochu, []int{k, k + Width, k + 3*Width}...) + } + bEliminate = true } - xiaochu = append(xiaochu, k+Width) - xiaochu = append(xiaochu, []int{k, k + 2*Width, k + 3*Width}...) - - bEliminate = true } } } @@ -304,6 +341,7 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i } score += this.Plat[id].Score this.Plat[id] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(id)) } } @@ -313,6 +351,7 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i } score += this.Plat[v].Score this.Plat[v] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(v)) } return } @@ -372,6 +411,7 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i } score += this.Plat[id].Score this.Plat[id] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(id)) } } @@ -381,6 +421,7 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i } score += this.Plat[v].Score this.Plat[v] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(v)) } return } @@ -390,7 +431,7 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData, co var curScore int32 for { curScore = 0 - this.DropGirde() // 先掉落 + if bRet, s, c := this.Check5X(color); bRet { fmt.Printf("=====检测消除5x===========\n") curScore += s @@ -406,11 +447,15 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData, co curScore += s count += c } + score += curScore // 总分 + this.DropGirde() szMap = append(szMap, &pb.MapData{ Data: this.Plat, CurSocre: curScore, }) + // 检查掉落 + this.operElem = []int32{} // 初始化操作元素 if curScore == 0 { break } @@ -449,17 +494,17 @@ func (this *MapData) DropGirde() { } // ai操作 -func (this *MapData) AiSwapGirde() bool { - var ( - bSwap bool // 能否交换 - ) +func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData) { + for pos := 0; pos < Total; pos++ { y := pos % Height if y < Height-1 { if b, _ := this.SwapGirde(int32(pos), int32(pos+1), 2); b { - if s, _, _ := this.CheckMap(2); s == 0 { + if s, m, _ := this.CheckMap(2); s == 0 { this.SwapGirde(int32(pos+1), int32(pos), 2) + this.operElem = []int32{} } else { + szMap = append(szMap, m...) bSwap = true break } @@ -468,14 +513,16 @@ func (this *MapData) AiSwapGirde() bool { } if pos/Width+1 < Width { if b, _ := this.SwapGirde(int32(pos), int32(pos+Width), 2); b { - if s, _, _ := this.CheckMap(2); s == 0 { + if s, m, _ := this.CheckMap(2); s == 0 { this.SwapGirde(int32(pos+Width), int32(pos), 2) + this.operElem = []int32{} } else { + szMap = append(szMap, m...) bSwap = true break } } } } - return bSwap + return } diff --git a/modules/entertainment/xxl_test.go b/modules/entertainment/xxl_test.go index 3fd4c95dd..26a543085 100644 --- a/modules/entertainment/xxl_test.go +++ b/modules/entertainment/xxl_test.go @@ -85,10 +85,15 @@ func Test_Main(t *testing.T) { m := new(entertainment.MapData) m.InitMap(nil) m.SetMap() + + var szMap []*pb.MapData + if bSwap, m := m.AiSwapGirde(); bSwap { + szMap = append(szMap, m...) + } m.SwapGirde(1, 8, 1) m.DropGirde() - var szMap []*pb.MapData + if score, m, _ := m.CheckMap(1); score > 0 { szMap = append(szMap, m...) diff --git a/pb/entertain_msg.pb.go b/pb/entertain_msg.pb.go index a07ffc2d3..6971b6220 100644 --- a/pb/entertain_msg.pb.go +++ b/pb/entertain_msg.pb.go @@ -441,12 +441,13 @@ type EntertainOperatorRstPush struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Mpadata []*MapData `protobuf:"bytes,1,rep,name=mpadata,proto3" json:"mpadata"` // 地图数据 - Power string `protobuf:"bytes,2,opt,name=power,proto3" json:"power"` // 该谁操作了 - Score int32 `protobuf:"varint,3,opt,name=score,proto3" json:"score"` // 获得积分 - Round int32 `protobuf:"varint,4,opt,name=round,proto3" json:"round"` // 轮数 - User1 *PlayerData `protobuf:"bytes,5,opt,name=user1,proto3" json:"user1"` // 玩家数据也需要同步 - User2 *PlayerData `protobuf:"bytes,6,opt,name=user2,proto3" json:"user2"` + Mpadata []*MapData `protobuf:"bytes,1,rep,name=mpadata,proto3" json:"mpadata"` // 地图数据 + Power string `protobuf:"bytes,2,opt,name=power,proto3" json:"power"` //下一个谁操作 + Curpower string `protobuf:"bytes,3,opt,name=curpower,proto3" json:"curpower"` //当前谁操作 + Score int32 `protobuf:"varint,4,opt,name=score,proto3" json:"score"` // 获得积分 + Round int32 `protobuf:"varint,5,opt,name=round,proto3" json:"round"` // 轮数 + User1 *PlayerData `protobuf:"bytes,6,opt,name=user1,proto3" json:"user1"` // 玩家数据也需要同步 + User2 *PlayerData `protobuf:"bytes,7,opt,name=user2,proto3" json:"user2"` } func (x *EntertainOperatorRstPush) Reset() { @@ -495,6 +496,13 @@ func (x *EntertainOperatorRstPush) GetPower() string { return "" } +func (x *EntertainOperatorRstPush) GetCurpower() string { + if x != nil { + return x.Curpower + } + return "" +} + func (x *EntertainOperatorRstPush) GetScore() int32 { if x != nil { return x.Score @@ -648,31 +656,33 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{ 0x15, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x22, 0xc6, 0x01, 0x0a, 0x18, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, + 0x22, 0xe2, 0x01, 0x0a, 0x18, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x52, 0x73, 0x74, 0x50, 0x75, 0x73, 0x68, 0x12, 0x22, 0x0a, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x14, 0x0a, - 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x6f, - 0x75, 0x6e, 0x64, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, - 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, - 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, - 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x22, 0xad, 0x01, 0x0a, 0x15, 0x45, 0x6e, - 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x47, 0x61, 0x6d, 0x65, 0x4f, 0x76, 0x65, 0x72, 0x50, - 0x75, 0x73, 0x68, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, - 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, - 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x12, 0x22, 0x0a, 0x07, 0x6d, 0x70, 0x61, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x4d, 0x61, 0x70, - 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, - 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x6f, - 0x77, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, - 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x75, 0x72, 0x70, 0x6f, + 0x77, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x75, 0x72, 0x70, 0x6f, + 0x77, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, + 0x6e, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x12, + 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, + 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, + 0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, + 0x75, 0x73, 0x65, 0x72, 0x32, 0x22, 0xad, 0x01, 0x0a, 0x15, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, + 0x61, 0x69, 0x6e, 0x47, 0x61, 0x6d, 0x65, 0x4f, 0x76, 0x65, 0x72, 0x50, 0x75, 0x73, 0x68, 0x12, + 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, + 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, + 0x72, 0x31, 0x12, 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, + 0x75, 0x73, 0x65, 0x72, 0x32, 0x12, 0x22, 0x0a, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, + 0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, + 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, + 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, + 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( From 90a1daf23af4ca7343c95f3667c8502b23656682 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 23 Oct 2023 15:58:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E7=8E=A9=E5=AE=B6?= =?UTF-8?q?=E4=BD=93=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 61a45ae5e..bbbec812b 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -241,6 +241,10 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr this.curPower = this.NexPower case "ready": if len(this.szSession) == 1 { // AI对战的话直接开始游戏 + this.NexPower = this.player1.Uid + this.curPower = this.player1.Uid + this.player1.Ps = MaxPs + this.player2.Ps = MaxPs if err := this.module.SendMsgToSession(string(this.module.GetType()), "startgame", &pb.EntertainStartGamePush{ User1: this.player1, User2: this.player2, @@ -251,8 +255,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr }, this.szSession...); err != nil { this.Errorln(err) } - this.NexPower = this.player1.Uid - this.curPower = this.player1.Uid + this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) } }