操作结果返回操作动作
This commit is contained in:
parent
c55161fb6c
commit
9057112fda
@ -69,6 +69,9 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
Round: this.round,
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
Itype: 0,
|
||||
Curid: 0,
|
||||
Targetid: 0,
|
||||
}, this.szSession...); err != nil {
|
||||
this.Errorln(err)
|
||||
}
|
||||
@ -107,6 +110,10 @@ func (this *Room) AiOperator() {
|
||||
var (
|
||||
curScore int32
|
||||
szMap []*pb.MapData
|
||||
curid int32
|
||||
targetid int32
|
||||
oid1 int32
|
||||
oid2 int32
|
||||
)
|
||||
|
||||
this.module.Debugf("AI 操作\n")
|
||||
@ -117,12 +124,12 @@ func (this *Room) AiOperator() {
|
||||
this.player1.Ps = MaxPs
|
||||
|
||||
// 交换元素
|
||||
if bSwap, m := this.chessboard.AiSwapGirde(); bSwap {
|
||||
szMap = append(szMap, m...)
|
||||
}
|
||||
_, szMap, curid, targetid = this.chessboard.AiSwapGirde()
|
||||
if this.NexPower != this.curPower {
|
||||
this.round++
|
||||
}
|
||||
oid1 = this.chessboard.Plat[targetid].Oid
|
||||
oid2 = this.chessboard.Plat[curid].Oid
|
||||
this.player2.Score += curScore
|
||||
// 广播消息
|
||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
@ -133,6 +140,9 @@ func (this *Room) AiOperator() {
|
||||
Round: this.round,
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
Itype: 0,
|
||||
Curid: oid1,
|
||||
Targetid: oid2,
|
||||
}, this.szSession...); err != nil {
|
||||
this.Errorln(err)
|
||||
}
|
||||
@ -152,6 +162,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
var (
|
||||
curScore int32
|
||||
AIOperator bool
|
||||
oid1 int32 // 唯一id
|
||||
oid2 int32
|
||||
)
|
||||
var szMap []*pb.MapData
|
||||
req := msg.(*pb.EntertainOperatorReq)
|
||||
@ -163,7 +175,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
oid1 = this.chessboard.Plat[req.Curid].Oid
|
||||
oid2 = this.chessboard.Plat[req.Targetid].Oid
|
||||
// 交换元素
|
||||
if b := this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子
|
||||
errdata = &pb.ErrorData{
|
||||
@ -223,6 +236,9 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
Round: this.round,
|
||||
User1: this.player1,
|
||||
User2: this.player2,
|
||||
Itype: req.Itype,
|
||||
Curid: oid1,
|
||||
Targetid: oid2,
|
||||
}, this.szSession...); err != nil {
|
||||
this.Errorln(err)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func (this *MapData) CreateGride(index int32) *pb.GirdeData {
|
||||
return &pb.GirdeData{
|
||||
Oid: this.oid,
|
||||
Color: t,
|
||||
Cid: GetRandType(),
|
||||
Cid: t,
|
||||
Score: 1,
|
||||
Special: 0,
|
||||
}
|
||||
@ -69,7 +69,7 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
|
||||
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) {
|
||||
(oldId-Width >= 0 && oldId-Width == newId) {
|
||||
bSwap = true
|
||||
tmp := new(pb.GirdeData)
|
||||
*tmp = *this.Plat[newId]
|
||||
@ -78,6 +78,7 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
|
||||
this.operElem = append(this.operElem, newId)
|
||||
this.operElem = append(this.operElem, oldId)
|
||||
}
|
||||
this.Debugf()
|
||||
//this.CheckMap(color)
|
||||
return
|
||||
}
|
||||
@ -222,26 +223,37 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
|
||||
var (
|
||||
newElem int // 生成的一个新的元素CID
|
||||
)
|
||||
|
||||
fmt.Printf("=====开始检测消除4x===========\n")
|
||||
this.Debugf()
|
||||
var xiaochu []int // 即将消除的key
|
||||
for k, v := range this.Plat {
|
||||
if v.Color == 0 {
|
||||
continue
|
||||
}
|
||||
x := int32(k % Height) // x
|
||||
|
||||
newElem = 0
|
||||
if x+3 < Height {
|
||||
k1 := this.Plat[k].Color
|
||||
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
|
||||
for i := 0; i <= 3; i++ {
|
||||
if int(v1) == k+i {
|
||||
newElem = int(v1)
|
||||
break
|
||||
}
|
||||
}
|
||||
if newElem != 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if newElem == 0 {
|
||||
newElem = k + 2 // 给个默认值
|
||||
}
|
||||
this.oid++
|
||||
// 生成一个新的类型元素
|
||||
if this.module != nil {
|
||||
@ -277,41 +289,47 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
|
||||
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
|
||||
for _, v1 := range this.operElem {
|
||||
for i := 0; i <= 3; i++ {
|
||||
if int(v1) == k+i*Width {
|
||||
newElem = int(v1) // 创建一个特殊的元素
|
||||
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)
|
||||
if newElem != 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if newElem != 0 {
|
||||
newElem = k + 2*Width // 给个默认值
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
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
|
||||
} 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -460,7 +478,7 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData, co
|
||||
break
|
||||
}
|
||||
}
|
||||
//this.Debugf()
|
||||
this.Debugf()
|
||||
return
|
||||
}
|
||||
|
||||
@ -494,7 +512,7 @@ func (this *MapData) DropGirde() {
|
||||
}
|
||||
|
||||
// ai操作
|
||||
func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData) {
|
||||
func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, pre int32, aft int32) {
|
||||
|
||||
for pos := 0; pos < Total; pos++ {
|
||||
y := pos % Height
|
||||
@ -503,11 +521,12 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData) {
|
||||
if s, m, _ := this.CheckMap(2); s == 0 {
|
||||
this.operElem = []int32{}
|
||||
} else {
|
||||
pre = int32(pos)
|
||||
aft = int32(pos + 1)
|
||||
szMap = append(szMap, m...)
|
||||
bSwap = true
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if pos/Width+1 < Width {
|
||||
@ -516,6 +535,8 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData) {
|
||||
this.SwapGirde(int32(pos+Width), int32(pos))
|
||||
this.operElem = []int32{}
|
||||
} else {
|
||||
pre = int32(pos)
|
||||
aft = int32(pos + Width)
|
||||
szMap = append(szMap, m...)
|
||||
bSwap = true
|
||||
break
|
||||
|
@ -87,10 +87,11 @@ func Test_Main(t *testing.T) {
|
||||
m.SetMap()
|
||||
|
||||
var szMap []*pb.MapData
|
||||
if bSwap, m := m.AiSwapGirde(); bSwap {
|
||||
szMap = append(szMap, m...)
|
||||
}
|
||||
// if bSwap, m := m.AiSwapGirde(); bSwap {
|
||||
// szMap = append(szMap, m...)
|
||||
// }
|
||||
m.SwapGirde(1, 8)
|
||||
m.CheckMap(1)
|
||||
|
||||
m.DropGirde()
|
||||
|
||||
|
@ -448,6 +448,9 @@ type EntertainOperatorRstPush struct {
|
||||
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"`
|
||||
Itype int32 `protobuf:"varint,8,opt,name=itype,proto3" json:"itype"` // 操作类型 0 默认交换元素
|
||||
Curid int32 `protobuf:"varint,9,opt,name=curid,proto3" json:"curid"` // 当前key
|
||||
Targetid int32 `protobuf:"varint,10,opt,name=targetid,proto3" json:"targetid"` // 目标key
|
||||
}
|
||||
|
||||
func (x *EntertainOperatorRstPush) Reset() {
|
||||
@ -531,6 +534,27 @@ func (x *EntertainOperatorRstPush) GetUser2() *PlayerData {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *EntertainOperatorRstPush) GetItype() int32 {
|
||||
if x != nil {
|
||||
return x.Itype
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *EntertainOperatorRstPush) GetCurid() int32 {
|
||||
if x != nil {
|
||||
return x.Curid
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *EntertainOperatorRstPush) GetTargetid() int32 {
|
||||
if x != nil {
|
||||
return x.Targetid
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// 游戏结束推送
|
||||
type EntertainGameOverPush struct {
|
||||
state protoimpl.MessageState
|
||||
@ -656,7 +680,7 @@ 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, 0xe2, 0x01, 0x0a, 0x18, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70,
|
||||
0x22, 0xaa, 0x02, 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,
|
||||
@ -670,19 +694,23 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{
|
||||
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,
|
||||
0x75, 0x73, 0x65, 0x72, 0x32, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x79, 0x70, 0x65, 0x18, 0x08,
|
||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x69, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63,
|
||||
0x75, 0x72, 0x69, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x75, 0x72, 0x69,
|
||||
0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x69, 0x64, 0x18, 0x0a, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x69, 0x64, 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