From 8c3fe6c9e2b3dafe7b2134a80cd7aa78c8a03877 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 18 Oct 2023 09:40:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?xxl=20=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/gamemgr.go | 9 +++-- modules/entertainment/module.go | 8 +++-- modules/entertainment/player.go | 9 +++++ modules/entertainment/room.go | 32 ++++++++++++++++-- modules/entertainment/xxlmap.go | 58 +++++++++++++++++++------------- 5 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 modules/entertainment/player.go diff --git a/modules/entertainment/gamemgr.go b/modules/entertainment/gamemgr.go index f0b7cd215..a2cb5886a 100644 --- a/modules/entertainment/gamemgr.go +++ b/modules/entertainment/gamemgr.go @@ -28,7 +28,10 @@ func (this *gameMgrComp) Init(service core.IService, module core.IModule, comp c return } -func (this *gameMgrComp) CreateRoom(room *Room) { +func (this *gameMgrComp) CreateRoom(session [2]comm.IUserSession) { + room := new(Room) //初始化房间 + room.InitRoom(session) + this.lock.Lock() this.rooms[room.Id] = room this.lock.Unlock() @@ -40,7 +43,7 @@ func (this *gameMgrComp) CloseRoom(id string) { this.lock.Unlock() } -func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, req proto.Message) (errdata *pb.ErrorData) { +func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, stype string, req proto.Message) (errdata *pb.ErrorData) { var ( room *Room ok bool @@ -49,7 +52,7 @@ func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, r room, ok = this.rooms[rid] this.lock.RUnlock() if ok { - errdata = room.ReceiveMessage(session, req) + errdata = room.ReceiveMessage(session, stype, req) } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index e45ec6733..8ca9174b4 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -50,8 +50,10 @@ func (this *Entertainment) Start() (err error) { return } - this.xxl = new(MapData) - this.xxl.InitMap() - this.xxl.SwapGirde(1, 0) + // this.xxl = new(MapData) + // this.xxl.InitMap() + // this.xxl.SwapGirde(1, 0) + // this.xxl.CheckMap() + // this.xxl.DropGirde() return } diff --git a/modules/entertainment/player.go b/modules/entertainment/player.go new file mode 100644 index 000000000..f4de16761 --- /dev/null +++ b/modules/entertainment/player.go @@ -0,0 +1,9 @@ +package entertainment + +type Player struct { + uid string + operate int32 // 该谁操作 + score int32 // 玩家积分 + step int32 // 操作步骤 + status int32 // 状态 +} diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 7dfa41df8..afb826392 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -4,15 +4,43 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) //游戏房间 type Room struct { - Id string + Id string + player1 *Player // 玩家1 + player2 *Player // 玩家2 + chessboard *MapData } -func (this *Room) ReceiveMessage(session comm.IUserSession, req proto.Message) (errdata *pb.ErrorData) { +func (this *Room) InitRoom(session [2]comm.IUserSession) *Room { + this.chessboard = new(MapData) + this.chessboard.InitMap() // 初始化棋盘 + return &Room{ + Id: primitive.NewObjectID().Hex(), + player1: &Player{}, + player2: &Player{}, + chessboard: this.chessboard, + } +} + +func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, req proto.Message) (errdata *pb.ErrorData) { + switch stype { + case "opertor": // 操作消息 + //req1 := req.(*pb.BattleCmd) + } + + return +} + +// 玩家操作 +func (this *Room) Opertor(set int32, iType int32, old int32, new int32) (errdata *pb.ErrorData) { + if iType == 1 { + this.chessboard.SwapGirde(old, new) // 交换格子 + } return } diff --git a/modules/entertainment/xxlmap.go b/modules/entertainment/xxlmap.go index bbea75346..6f968597e 100644 --- a/modules/entertainment/xxlmap.go +++ b/modules/entertainment/xxlmap.go @@ -29,10 +29,6 @@ func (this *MapData) Init(service core.IService, module core.IModule, comp core. return } -// func (this *MapData) init() { -// this.Data = make(map[int32]*Girde, Width*Height) -// } - // 1~6随机一个数 func GetRandType() int32 { n, _ := rand.Int(rand.Reader, big.NewInt(6)) @@ -56,7 +52,7 @@ func (this *MapData) GetKeyData(key int32) (data *Girde) { // 初始化地图数据 func (this *MapData) InitMap() { this.Data = make(map[int32]*Girde, Width*Height) - for i := Width - 1; i >= 0; i-- { + for i := 0; i < Width; i++ { for j := 0; j < Height; j++ { tmp := GetRandType() key := int32(i*10 + j) @@ -92,10 +88,26 @@ func (this *MapData) InitMap() { } this.Data[key].Itype = tmp } - fmt.Printf("key:%d,x:%d,y:%d,type:%d \n", key, i, j, tmp) } } + sz2 := []int32{ + 5, 1, 3, 5, 1, 5, 2, + 3, 1, 5, 4, 2, 4, 4, + 4, 4, 1, 5, 6, 4, 1, + 6, 3, 1, 1, 3, 6, 3, + 6, 3, 5, 2, 4, 6, 1, + 5, 2, 4, 2, 1, 3, 1, + 6, 5, 5, 1, 2, 1, 4, + } + var index = 0 + for j := Height - 1; j >= 0; j-- { + for i := 0; i < Width; i++ { + key := int32(i*10 + j) + this.Data[key].Itype = sz2[index] + index++ + } + } this.Debugf() } @@ -139,10 +151,10 @@ func (this *MapData) SwapGirde(i, j int32) bool { func (this *MapData) Debugf() { fmt.Printf("================\n") - for i := Width - 1; i >= 0; i-- { - for j := 0; j < Height; j++ { + for j := Height - 1; j >= 0; j-- { + for i := 0; i < Width; i++ { key := int32(i*10 + j) - fmt.Printf("%d-%d-%d ", i, j, this.Data[key].Itype) + fmt.Printf("%d ", this.Data[key].Itype) } fmt.Printf("\n") } @@ -155,7 +167,7 @@ func (this *MapData) CheckMap() { ) del = map[int32]struct{}{} - for i := Width - 1; i >= 0; i-- { + for i := 0; i < Width; i++ { for j := 0; j < Height; j++ { key := int32(i*10 + j) iType := this.GetKeyType(key) @@ -184,45 +196,43 @@ func (this *MapData) CheckMap() { } // 顺着删除列表删除各组 for k := range del { - this.Data[k] = &Girde{} + this.Data[k].Itype = 0 } - fmt.Printf("%v", del) + fmt.Printf("===del:%v", del) + this.Debugf() return } // 下落 生成新的格子 func (this *MapData) DropGirde() (Data map[int32]*Girde) { - for i := Width - 1; i >= 0; i-- { + for i := 0; i < Width; i++ { for j := 0; j < Height; j++ { key := int32(i*10 + j) - var sz []*Girde + var sz []int32 var l int // 落下多少个 if this.GetKeyType(key) == 0 { // 找上面的 for m := j; m < Height; m++ { key1 := int32(i*10 + m) t := this.GetKeyData(key1) if t.Itype != 0 { - sz = append(sz, t) + sz = append(sz, t.Itype) l++ } } - for i, v := range sz { - key := int32(i*10 + j + i) - this.Data[key] = v + for pos, v := range sz { + key := int32(i*10 + j + pos) + this.Data[key].Itype = v } + for n := j + l; n < Height; n++ { key := int32(i*10 + n) tmp := GetRandType() - this.Data[key] = &Girde{ - X: int32(i), - Y: int32(j), - ID: key, - Itype: tmp, - } + this.Data[key].Itype = tmp } break // 完成该列 } } } + this.Debugf() return this.Data } From 30970cb7d9e6823d84c01ecdf864e51cdc853386 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 18 Oct 2023 11:33:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?ui=E5=B0=8F=E6=B8=B8=E6=88=8F=E9=A2=9D?= =?UTF-8?q?=E5=A4=96=E5=A5=96=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/gamemgr.go | 4 ++-- modules/entertainment/module.go | 5 +++++ modules/entertainment/room.go | 2 +- modules/uigame/api_minergrid.go | 9 ++++++++- modules/uigame/api_puzzlegrid.go | 12 ++++++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/modules/entertainment/gamemgr.go b/modules/entertainment/gamemgr.go index a2cb5886a..b4a646cb6 100644 --- a/modules/entertainment/gamemgr.go +++ b/modules/entertainment/gamemgr.go @@ -28,9 +28,9 @@ func (this *gameMgrComp) Init(service core.IService, module core.IModule, comp c return } -func (this *gameMgrComp) CreateRoom(session [2]comm.IUserSession) { +func (this *gameMgrComp) CreateRoom(s1 comm.IUserSession, s2 comm.IUserSession) { room := new(Room) //初始化房间 - room.InitRoom(session) + room.InitRoom(s1, s2) this.lock.Lock() this.rooms[room.Id] = room diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index 8ca9174b4..062c44d16 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -57,3 +57,8 @@ func (this *Entertainment) Start() (err error) { // this.xxl.DropGirde() return } + +// 匹配完成 +func (this *Entertainment) MatchingComplete(s1 comm.IUserSession, s2 comm.IUserSession) { + this.gameMgr.CreateRoom(s1, s2) +} diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index afb826392..61c5b4939 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -16,7 +16,7 @@ type Room struct { chessboard *MapData } -func (this *Room) InitRoom(session [2]comm.IUserSession) *Room { +func (this *Room) InitRoom(s1 comm.IUserSession, s2 comm.IUserSession) *Room { this.chessboard = new(MapData) this.chessboard.InitMap() // 初始化棋盘 return &Room{ diff --git a/modules/uigame/api_minergrid.go b/modules/uigame/api_minergrid.go index 47ba40ab0..3cfe8e133 100644 --- a/modules/uigame/api_minergrid.go +++ b/modules/uigame/api_minergrid.go @@ -25,6 +25,7 @@ func (this *apiComp) MinerKey(session comm.IUserSession, req *pb.UiGameMinerKeyR } var ( atno []*pb.UserAtno + res []*cfg.Gameatn ) list, _ := this.module.modelMiner.getMinerList(session.GetUserId(), req.Hdid) if _, ok := list.Gotarr[req.Cid]; ok { // 重复拼图 @@ -39,7 +40,13 @@ func (this *apiComp) MinerKey(session comm.IUserSession, req *pb.UiGameMinerKeyR } } if len(conf.Costget) > 0 { - if errdata, atno = this.module.DispenseAtno(session, conf.Costget, true); errdata != nil { + res = append(res, conf.Costget...) + } + if c, err := this.module.configure.GetMinerConf(req.Cid); err == nil { + res = append(res, c.Itemid) + } + if len(res) > 0 { + if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil { return } } diff --git a/modules/uigame/api_puzzlegrid.go b/modules/uigame/api_puzzlegrid.go index 48946fba3..f4d5e02f2 100644 --- a/modules/uigame/api_puzzlegrid.go +++ b/modules/uigame/api_puzzlegrid.go @@ -25,6 +25,7 @@ func (this *apiComp) PuzzleGrid(session comm.IUserSession, req *pb.UiGamePuzzleG } var ( atno []*pb.UserAtno + res []*cfg.Gameatn ) list, _ := this.module.modelPuzzle.getPuzzleList(session.GetUserId(), req.Hdid) if _, ok := list.Puzzle[req.Grid]; ok { // 重复拼图 @@ -43,6 +44,17 @@ func (this *apiComp) PuzzleGrid(session comm.IUserSession, req *pb.UiGamePuzzleG return } } + if len(conf.Costget) > 0 { + res = append(res, conf.Costget...) + } + if c, err := this.module.configure.GetMinerConf(req.Grid); err == nil { + res = append(res, c.Itemid) + } + if len(res) > 0 { + if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil { + return + } + } } list.Puzzle[req.Grid] = 1