Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
f7ac90a153
@ -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,69 @@ 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对战的话直接开始游戏
|
||||
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,
|
||||
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.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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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...)
|
||||
|
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user