规则完善
This commit is contained in:
parent
d89e6b0898
commit
785b2f7881
@ -105,18 +105,15 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
|
|
||||||
// 交换元素
|
// 交换元素
|
||||||
this.chessboard.SwapGirde(req.Curid, req.Targetid) // 交换格子
|
this.chessboard.SwapGirde(req.Curid, req.Targetid) // 交换格子
|
||||||
for {
|
szMap = append(szMap, &pb.MapData{
|
||||||
if b, score := this.chessboard.CheckMap(); b {
|
Data: this.chessboard.Data,
|
||||||
break
|
})
|
||||||
} else {
|
this.chessboard.CheckMap()
|
||||||
curScore += score // 统计积分
|
if score, m := this.chessboard.DropGirde(); score > 0 {
|
||||||
}
|
curScore += score
|
||||||
|
szMap = append(szMap, m...)
|
||||||
this.chessboard.DropGirde()
|
|
||||||
szMap = append(szMap, &pb.MapData{
|
|
||||||
Data: this.chessboard.Data,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 操作消息返回
|
// 操作消息返回
|
||||||
session.SendMsg(string(this.module.GetType()), "operator", &pb.EntertainOperatorResp{
|
session.SendMsg(string(this.module.GetType()), "operator", &pb.EntertainOperatorResp{
|
||||||
Success: true,
|
Success: true,
|
||||||
|
@ -72,8 +72,11 @@ func Test_Main(t *testing.T) {
|
|||||||
m := new(entertainment.MapData)
|
m := new(entertainment.MapData)
|
||||||
m.InitMap()
|
m.InitMap()
|
||||||
|
|
||||||
m.SwapGirde(0, 1)
|
m.SwapGirde(1, 11)
|
||||||
|
fmt.Printf("得分:%d\n", m.CheckMap())
|
||||||
|
m.DropGirde()
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
s := NewService(
|
s := NewService(
|
||||||
rpcx.SetConfPath(*conf),
|
rpcx.SetConfPath(*conf),
|
||||||
rpcx.SetVersion("1.0.0.0"),
|
rpcx.SetVersion("1.0.0.0"),
|
||||||
|
@ -100,7 +100,7 @@ func (this *MapData) InitMap() {
|
|||||||
4, 4, 1, 5, 6, 4, 1,
|
4, 4, 1, 5, 6, 4, 1,
|
||||||
6, 3, 1, 1, 3, 6, 3,
|
6, 3, 1, 1, 3, 6, 3,
|
||||||
6, 3, 5, 2, 4, 6, 1,
|
6, 3, 5, 2, 4, 6, 1,
|
||||||
5, 2, 4, 2, 1, 3, 1,
|
5, 6, 5, 5, 1, 3, 1,
|
||||||
6, 5, 5, 1, 2, 1, 4,
|
6, 5, 5, 1, 2, 1, 4,
|
||||||
}
|
}
|
||||||
var index = 0
|
var index = 0
|
||||||
@ -111,7 +111,7 @@ func (this *MapData) InitMap() {
|
|||||||
index++
|
index++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//this.Debugf()
|
this.Debugf()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 交换2个元素(参数 id )
|
// 交换2个元素(参数 id )
|
||||||
@ -139,13 +139,13 @@ func (this *MapData) SwapGirde(i, j int32) bool {
|
|||||||
}
|
}
|
||||||
this.Data[i] = g2
|
this.Data[i] = g2
|
||||||
this.Data[j] = tmp
|
this.Data[j] = tmp
|
||||||
if !this.CheckSwape() { // 交换后不能消除
|
if !this.CheckSwape(i, j) { // 交换后不能消除
|
||||||
this.Data[i] = tmp
|
this.Data[i] = tmp
|
||||||
this.Data[j] = g2
|
this.Data[j] = g2
|
||||||
bSwap = false
|
bSwap = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.Debugf()
|
||||||
return bSwap
|
return bSwap
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,20 +162,23 @@ func (this *MapData) Debugf() {
|
|||||||
|
|
||||||
// 检查5消
|
// 检查5消
|
||||||
func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
||||||
m := make(map[int32]struct{}, 0)
|
m := make(map[int32]struct{}, 5)
|
||||||
|
|
||||||
bEliminate = true
|
bEliminate = true
|
||||||
del := make(map[int32]int32)
|
del := make(map[int32]int32)
|
||||||
for i := 0; i < Width; i++ {
|
for i := 0; i < Width; i++ {
|
||||||
for j := 0; j < Height; j++ {
|
for j := 0; j < Height; j++ {
|
||||||
|
m = make(map[int32]struct{}, 0)
|
||||||
key := int32(i*10 + j)
|
key := int32(i*10 + j)
|
||||||
iType := this.GetKeyType(key)
|
iType := this.GetKeyType(key)
|
||||||
if iType == 0 {
|
if iType == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
curKey := this.Data[key].Itype
|
curKey := this.Data[key].Itype
|
||||||
|
if curKey == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
m[curKey] = struct{}{}
|
m[curKey] = struct{}{}
|
||||||
if j+4 < Height {
|
if i+4 < Width {
|
||||||
i1 := this.Data[int32((i+1)*10+j)]
|
i1 := this.Data[int32((i+1)*10+j)]
|
||||||
i2 := this.Data[int32((i+2)*10+j)]
|
i2 := this.Data[int32((i+2)*10+j)]
|
||||||
i3 := this.Data[int32((i+3)*10+j)]
|
i3 := this.Data[int32((i+3)*10+j)]
|
||||||
@ -186,7 +189,7 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
|||||||
m[i3.Itype] = struct{}{}
|
m[i3.Itype] = struct{}{}
|
||||||
m[i4.Itype] = struct{}{}
|
m[i4.Itype] = struct{}{}
|
||||||
|
|
||||||
if len(m) == 5 {
|
if len(m) == 1 {
|
||||||
del[int32((i+1)*10+j)] = i1.Score
|
del[int32((i+1)*10+j)] = i1.Score
|
||||||
del[int32((i+2)*10+j)] = i2.Score
|
del[int32((i+2)*10+j)] = i2.Score
|
||||||
del[int32((i+3)*10+j)] = i3.Score
|
del[int32((i+3)*10+j)] = i3.Score
|
||||||
@ -194,7 +197,8 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
|||||||
del[key] = this.Data[key].Score
|
del[key] = this.Data[key].Score
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i+4 < Width {
|
m = map[int32]struct{}{}
|
||||||
|
if j+4 < Height {
|
||||||
i1 := this.Data[int32(i*10+j+1)]
|
i1 := this.Data[int32(i*10+j+1)]
|
||||||
i2 := this.Data[int32(i*10+j+2)]
|
i2 := this.Data[int32(i*10+j+2)]
|
||||||
i3 := this.Data[int32(i*10+j+3)]
|
i3 := this.Data[int32(i*10+j+3)]
|
||||||
@ -203,7 +207,7 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
|||||||
m[i2.Itype] = struct{}{}
|
m[i2.Itype] = struct{}{}
|
||||||
m[i3.Itype] = struct{}{}
|
m[i3.Itype] = struct{}{}
|
||||||
m[i4.Itype] = struct{}{}
|
m[i4.Itype] = struct{}{}
|
||||||
if len(m) == 5 {
|
if len(m) == 1 { // 1 2 3 4 5
|
||||||
del[int32(i*10+j+1)] = i1.Score
|
del[int32(i*10+j+1)] = i1.Score
|
||||||
del[int32(i*10+j+2)] = i2.Score
|
del[int32(i*10+j+2)] = i2.Score
|
||||||
del[int32(i*10+j+3)] = i3.Score
|
del[int32(i*10+j+3)] = i3.Score
|
||||||
@ -220,12 +224,13 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
|
|||||||
}
|
}
|
||||||
if len(del) > 0 {
|
if len(del) > 0 {
|
||||||
bEliminate = false
|
bEliminate = false
|
||||||
|
fmt.Printf("5x消除格子===del:%v\n", del)
|
||||||
}
|
}
|
||||||
fmt.Printf("===del:%v", del)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
||||||
bEliminate = false
|
bEliminate = true
|
||||||
del := make(map[int32]int32)
|
del := make(map[int32]int32)
|
||||||
for i := 0; i < Width; i++ {
|
for i := 0; i < Width; i++ {
|
||||||
for j := 0; j < Height; j++ {
|
for j := 0; j < Height; j++ {
|
||||||
@ -234,7 +239,7 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
|||||||
if iType == 0 {
|
if iType == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if j+3 < Height {
|
if i+3 < Width {
|
||||||
i1 := this.Data[int32((i+1)*10+j)]
|
i1 := this.Data[int32((i+1)*10+j)]
|
||||||
i2 := this.Data[int32((i+2)*10+j)]
|
i2 := this.Data[int32((i+2)*10+j)]
|
||||||
i3 := this.Data[int32((i+3)*10+j)]
|
i3 := this.Data[int32((i+3)*10+j)]
|
||||||
@ -243,9 +248,10 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
|||||||
del[int32((i+2)*10+j)] = i2.Score
|
del[int32((i+2)*10+j)] = i2.Score
|
||||||
del[int32((i+3)*10+j)] = i3.Score
|
del[int32((i+3)*10+j)] = i3.Score
|
||||||
del[key] = this.Data[key].Score
|
del[key] = this.Data[key].Score
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i+3 < Width {
|
if j+3 < Height {
|
||||||
i1 := this.Data[int32(i*10+j+1)]
|
i1 := this.Data[int32(i*10+j+1)]
|
||||||
i2 := this.Data[int32(i*10+j+2)]
|
i2 := this.Data[int32(i*10+j+2)]
|
||||||
i3 := this.Data[int32(i*10+j+3)]
|
i3 := this.Data[int32(i*10+j+3)]
|
||||||
@ -254,6 +260,7 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
|||||||
del[int32(i*10+j+2)] = i2.Score
|
del[int32(i*10+j+2)] = i2.Score
|
||||||
del[int32(i*10+j+3)] = i3.Score
|
del[int32(i*10+j+3)] = i3.Score
|
||||||
del[key] = this.Data[key].Score
|
del[key] = this.Data[key].Score
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,9 +271,10 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
|
|||||||
score += v
|
score += v
|
||||||
}
|
}
|
||||||
if len(del) > 0 {
|
if len(del) > 0 {
|
||||||
bEliminate = true
|
bEliminate = false
|
||||||
|
fmt.Printf("4x消除格子===del:%v\n", del)
|
||||||
}
|
}
|
||||||
fmt.Printf("===del:%v", del)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +288,8 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
|
|||||||
if iType == 0 {
|
if iType == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if j+2 < Height {
|
|
||||||
|
if i+2 < Width {
|
||||||
i1 := this.Data[int32((i+1)*10+j)]
|
i1 := this.Data[int32((i+1)*10+j)]
|
||||||
i2 := this.Data[int32((i+2)*10+j)]
|
i2 := this.Data[int32((i+2)*10+j)]
|
||||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||||
@ -289,7 +298,7 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
|
|||||||
del[key] = i1.Score
|
del[key] = i1.Score
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i+2 < Width {
|
if j+2 < Height {
|
||||||
i1 := this.Data[int32(i*10+j+1)]
|
i1 := this.Data[int32(i*10+j+1)]
|
||||||
i2 := this.Data[int32(i*10+j+2)]
|
i2 := this.Data[int32(i*10+j+2)]
|
||||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||||
@ -307,12 +316,12 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
|
|||||||
}
|
}
|
||||||
if len(del) > 0 {
|
if len(del) > 0 {
|
||||||
bEliminate = false
|
bEliminate = false
|
||||||
|
fmt.Printf("3x消除格子===del:%v\n", del)
|
||||||
}
|
}
|
||||||
fmt.Printf("===del:%v", del)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MapData) CheckSwape() (bEliminate bool) {
|
func (this *MapData) CheckSwape(g1, g2 int32) (bEliminate bool) {
|
||||||
|
|
||||||
for i := 0; i < Width; i++ {
|
for i := 0; i < Width; i++ {
|
||||||
for j := 0; j < Height; j++ {
|
for j := 0; j < Height; j++ {
|
||||||
@ -322,17 +331,27 @@ func (this *MapData) CheckSwape() (bEliminate bool) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if j+2 < Height {
|
if j+2 < Height {
|
||||||
i1 := this.Data[int32((i+1)*10+j)]
|
k1 := int32((i+1)*10 + j)
|
||||||
i2 := this.Data[int32((i+2)*10+j)]
|
k2 := int32((i+2)*10 + j)
|
||||||
|
i1 := this.Data[k1]
|
||||||
|
i2 := this.Data[k2]
|
||||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||||
return true
|
if g1 == key || k1 == g1 || k2 == g1 ||
|
||||||
|
g2 == key || k1 == g2 || k2 == g2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i+2 < Width {
|
if i+2 < Width {
|
||||||
i1 := this.Data[int32(i*10+j+1)]
|
k1 := int32(i*10 + j + 1)
|
||||||
i2 := this.Data[int32(i*10+j+2)]
|
k2 := int32(i*10 + j + 2)
|
||||||
|
i1 := this.Data[k1]
|
||||||
|
i2 := this.Data[k2]
|
||||||
if i1.Itype == i2.Itype && i1.Itype == iType {
|
if i1.Itype == i2.Itype && i1.Itype == iType {
|
||||||
return true
|
if g1 == key || k1 == g1 || k2 == g1 ||
|
||||||
|
g2 == key || k1 == g2 || k2 == g2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,54 +361,78 @@ func (this *MapData) CheckSwape() (bEliminate bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 校验地图可消除的 判断各组上面2个和右边两个是否三个相等
|
// 校验地图可消除的 判断各组上面2个和右边两个是否三个相等
|
||||||
func (this *MapData) CheckMap() (bEliminate bool, score int32) {
|
func (this *MapData) CheckMap() (score int32) {
|
||||||
|
score = 0
|
||||||
if bRet, s := this.Check5X(); !bRet {
|
if bRet, s := this.Check5X(); !bRet {
|
||||||
|
fmt.Printf("=====检测消除5x===========\n")
|
||||||
score += s
|
score += s
|
||||||
}
|
}
|
||||||
if bRet, s := this.Check4X(); !bRet {
|
if bRet, s := this.Check4X(); !bRet {
|
||||||
|
fmt.Printf("=====检测消除4x===========\n")
|
||||||
score += s
|
score += s
|
||||||
}
|
}
|
||||||
if bRet, s := this.Check3X(); !bRet {
|
if bRet, s := this.Check3X(); !bRet {
|
||||||
|
fmt.Printf("=====检测消除3x===========\n")
|
||||||
score += s
|
score += s
|
||||||
}
|
}
|
||||||
if score > 0 {
|
|
||||||
bEliminate = true
|
this.Debugf()
|
||||||
}
|
|
||||||
//this.Debugf()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下落 生成新的格子
|
// 下落 生成新的格子 (返回掉落所获得的分数)
|
||||||
func (this *MapData) DropGirde() {
|
func (this *MapData) DropGirde() (score int32, szMap []*pb.MapData) {
|
||||||
for i := 0; i < Width; i++ {
|
var bDrop bool
|
||||||
for j := 0; j < Height; j++ {
|
for {
|
||||||
key := int32(i*10 + j)
|
bDrop = false
|
||||||
var sz []int32
|
for _, v := range this.Data { // 校验是否有下落
|
||||||
var l int // 落下多少个
|
if v.Itype == 0 {
|
||||||
if this.GetKeyType(key) == 0 { // 找上面的
|
fmt.Printf("检测有掉落\n")
|
||||||
for m := j; m < Height; m++ {
|
bDrop = true // 有空位置 说明可以掉落
|
||||||
key1 := int32(i*10 + m)
|
break
|
||||||
t := this.GetKeyData(key1)
|
|
||||||
if t.Itype != 0 {
|
|
||||||
sz = append(sz, t.Itype)
|
|
||||||
l++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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].Itype = tmp
|
|
||||||
}
|
|
||||||
break // 完成该列
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !bDrop {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for i := 0; i < Width; i++ {
|
||||||
|
for j := 0; j < Height; j++ {
|
||||||
|
key := int32(i*10 + j)
|
||||||
|
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.Itype)
|
||||||
|
l++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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].Itype = tmp
|
||||||
|
}
|
||||||
|
break // 完成该列
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if s := this.CheckMap(); s > 0 {
|
||||||
|
fmt.Printf("本次掉落得分:%d\n", s)
|
||||||
|
score += s
|
||||||
|
szMap = append(szMap, &pb.MapData{
|
||||||
|
Data: this.Data,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//this.Debugf()
|
|
||||||
|
this.Debugf()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user