Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
fecd1df1c8
@ -28,7 +28,10 @@ func (this *gameMgrComp) Init(service core.IService, module core.IModule, comp c
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *gameMgrComp) CreateRoom(room *Room) {
|
func (this *gameMgrComp) CreateRoom(s1 comm.IUserSession, s2 comm.IUserSession) {
|
||||||
|
room := new(Room) //初始化房间
|
||||||
|
room.InitRoom(s1, s2)
|
||||||
|
|
||||||
this.lock.Lock()
|
this.lock.Lock()
|
||||||
this.rooms[room.Id] = room
|
this.rooms[room.Id] = room
|
||||||
this.lock.Unlock()
|
this.lock.Unlock()
|
||||||
@ -40,7 +43,7 @@ func (this *gameMgrComp) CloseRoom(id string) {
|
|||||||
this.lock.Unlock()
|
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 (
|
var (
|
||||||
room *Room
|
room *Room
|
||||||
ok bool
|
ok bool
|
||||||
@ -49,7 +52,7 @@ func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, r
|
|||||||
room, ok = this.rooms[rid]
|
room, ok = this.rooms[rid]
|
||||||
this.lock.RUnlock()
|
this.lock.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
errdata = room.ReceiveMessage(session, req)
|
errdata = room.ReceiveMessage(session, stype, req)
|
||||||
} else {
|
} else {
|
||||||
errdata = &pb.ErrorData{
|
errdata = &pb.ErrorData{
|
||||||
Code: pb.ErrorCode_ReqParameterError,
|
Code: pb.ErrorCode_ReqParameterError,
|
||||||
|
@ -50,8 +50,15 @@ func (this *Entertainment) Start() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.xxl = new(MapData)
|
// this.xxl = new(MapData)
|
||||||
this.xxl.InitMap()
|
// this.xxl.InitMap()
|
||||||
this.xxl.SwapGirde(1, 0)
|
// this.xxl.SwapGirde(1, 0)
|
||||||
|
// this.xxl.CheckMap()
|
||||||
|
// this.xxl.DropGirde()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 匹配完成
|
||||||
|
func (this *Entertainment) MatchingComplete(s1 comm.IUserSession, s2 comm.IUserSession) {
|
||||||
|
this.gameMgr.CreateRoom(s1, s2)
|
||||||
|
}
|
||||||
|
9
modules/entertainment/player.go
Normal file
9
modules/entertainment/player.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package entertainment
|
||||||
|
|
||||||
|
type Player struct {
|
||||||
|
uid string
|
||||||
|
operate int32 // 该谁操作
|
||||||
|
score int32 // 玩家积分
|
||||||
|
step int32 // 操作步骤
|
||||||
|
status int32 // 状态
|
||||||
|
}
|
@ -4,15 +4,43 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
//游戏房间
|
//游戏房间
|
||||||
type Room struct {
|
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(s1 comm.IUserSession, s2 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
|
return
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,6 @@ func (this *MapData) Init(service core.IService, module core.IModule, comp core.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (this *MapData) init() {
|
|
||||||
// this.Data = make(map[int32]*Girde, Width*Height)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 1~6随机一个数
|
// 1~6随机一个数
|
||||||
func GetRandType() int32 {
|
func GetRandType() int32 {
|
||||||
n, _ := rand.Int(rand.Reader, big.NewInt(6))
|
n, _ := rand.Int(rand.Reader, big.NewInt(6))
|
||||||
@ -56,7 +52,7 @@ func (this *MapData) GetKeyData(key int32) (data *Girde) {
|
|||||||
// 初始化地图数据
|
// 初始化地图数据
|
||||||
func (this *MapData) InitMap() {
|
func (this *MapData) InitMap() {
|
||||||
this.Data = make(map[int32]*Girde, Width*Height)
|
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++ {
|
for j := 0; j < Height; j++ {
|
||||||
tmp := GetRandType()
|
tmp := GetRandType()
|
||||||
key := int32(i*10 + j)
|
key := int32(i*10 + j)
|
||||||
@ -92,10 +88,26 @@ func (this *MapData) InitMap() {
|
|||||||
}
|
}
|
||||||
this.Data[key].Itype = tmp
|
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()
|
this.Debugf()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,10 +151,10 @@ func (this *MapData) SwapGirde(i, j int32) bool {
|
|||||||
|
|
||||||
func (this *MapData) Debugf() {
|
func (this *MapData) Debugf() {
|
||||||
fmt.Printf("================\n")
|
fmt.Printf("================\n")
|
||||||
for i := Width - 1; i >= 0; i-- {
|
for j := Height - 1; j >= 0; j-- {
|
||||||
for j := 0; j < Height; j++ {
|
for i := 0; i < Width; i++ {
|
||||||
key := int32(i*10 + j)
|
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")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
@ -155,7 +167,7 @@ func (this *MapData) CheckMap() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
del = map[int32]struct{}{}
|
del = map[int32]struct{}{}
|
||||||
for i := Width - 1; i >= 0; i-- {
|
for i := 0; i < Width; i++ {
|
||||||
for j := 0; j < Height; j++ {
|
for j := 0; j < Height; j++ {
|
||||||
key := int32(i*10 + j)
|
key := int32(i*10 + j)
|
||||||
iType := this.GetKeyType(key)
|
iType := this.GetKeyType(key)
|
||||||
@ -184,45 +196,43 @@ func (this *MapData) CheckMap() {
|
|||||||
}
|
}
|
||||||
// 顺着删除列表删除各组
|
// 顺着删除列表删除各组
|
||||||
for k := range del {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下落 生成新的格子
|
// 下落 生成新的格子
|
||||||
func (this *MapData) DropGirde() (Data map[int32]*Girde) {
|
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++ {
|
for j := 0; j < Height; j++ {
|
||||||
key := int32(i*10 + j)
|
key := int32(i*10 + j)
|
||||||
var sz []*Girde
|
var sz []int32
|
||||||
var l int // 落下多少个
|
var l int // 落下多少个
|
||||||
if this.GetKeyType(key) == 0 { // 找上面的
|
if this.GetKeyType(key) == 0 { // 找上面的
|
||||||
for m := j; m < Height; m++ {
|
for m := j; m < Height; m++ {
|
||||||
key1 := int32(i*10 + m)
|
key1 := int32(i*10 + m)
|
||||||
t := this.GetKeyData(key1)
|
t := this.GetKeyData(key1)
|
||||||
if t.Itype != 0 {
|
if t.Itype != 0 {
|
||||||
sz = append(sz, t)
|
sz = append(sz, t.Itype)
|
||||||
l++
|
l++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, v := range sz {
|
for pos, v := range sz {
|
||||||
key := int32(i*10 + j + i)
|
key := int32(i*10 + j + pos)
|
||||||
this.Data[key] = v
|
this.Data[key].Itype = v
|
||||||
}
|
}
|
||||||
|
|
||||||
for n := j + l; n < Height; n++ {
|
for n := j + l; n < Height; n++ {
|
||||||
key := int32(i*10 + n)
|
key := int32(i*10 + n)
|
||||||
tmp := GetRandType()
|
tmp := GetRandType()
|
||||||
this.Data[key] = &Girde{
|
this.Data[key].Itype = tmp
|
||||||
X: int32(i),
|
|
||||||
Y: int32(j),
|
|
||||||
ID: key,
|
|
||||||
Itype: tmp,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break // 完成该列
|
break // 完成该列
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.Debugf()
|
||||||
return this.Data
|
return this.Data
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ func (this *apiComp) MinerKey(session comm.IUserSession, req *pb.UiGameMinerKeyR
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
atno []*pb.UserAtno
|
atno []*pb.UserAtno
|
||||||
|
res []*cfg.Gameatn
|
||||||
)
|
)
|
||||||
list, _ := this.module.modelMiner.getMinerList(session.GetUserId(), req.Hdid)
|
list, _ := this.module.modelMiner.getMinerList(session.GetUserId(), req.Hdid)
|
||||||
if _, ok := list.Gotarr[req.Cid]; ok { // 重复拼图
|
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 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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ func (this *apiComp) PuzzleGrid(session comm.IUserSession, req *pb.UiGamePuzzleG
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
atno []*pb.UserAtno
|
atno []*pb.UserAtno
|
||||||
|
res []*cfg.Gameatn
|
||||||
)
|
)
|
||||||
list, _ := this.module.modelPuzzle.getPuzzleList(session.GetUserId(), req.Hdid)
|
list, _ := this.module.modelPuzzle.getPuzzleList(session.GetUserId(), req.Hdid)
|
||||||
if _, ok := list.Puzzle[req.Grid]; ok { // 重复拼图
|
if _, ok := list.Puzzle[req.Grid]; ok { // 重复拼图
|
||||||
@ -43,6 +44,17 @@ func (this *apiComp) PuzzleGrid(session comm.IUserSession, req *pb.UiGamePuzzleG
|
|||||||
return
|
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
|
list.Puzzle[req.Grid] = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user