进入游戏随机生成一张不能自消的地图

This commit is contained in:
meixiongfeng 2023-10-26 18:32:09 +08:00
parent adcd237cad
commit d684e12e93
3 changed files with 39 additions and 10 deletions

View File

@ -36,7 +36,6 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
}) })
configure.RegisterConfigure(game_block, cfg.NewGameBlock, this.LoadGameBlock) configure.RegisterConfigure(game_block, cfg.NewGameBlock, this.LoadGameBlock)
this.GetGameConsumeintegralReward(100)
return return
} }

View File

@ -61,7 +61,8 @@ func (this *MapData) InitMap(module *Entertainment) {
for i := 0; i < Width*Height; i++ { for i := 0; i < Width*Height; i++ {
this.Plat[i] = this.CreateGride(int32(i)) this.Plat[i] = this.CreateGride(int32(i))
} }
this.SetMap() // 方便测试固定地图 this.SetIndelibilityPlat()
//this.SetMap() // 方便测试固定地图
} }
// 交换2个元素(参数 oid ) // 交换2个元素(参数 oid )
@ -591,15 +592,13 @@ func (this *MapData) SetMap() {
pos++ pos++
} }
} }
this.SetIndelibilityPlat()
} }
// 校验当前地图 有没有能消除的 // 校验当前地图 有没有能消除的
func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) { func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
bEliminate = false bEliminate = false
for k, v := range this.Plat { for k, v := range this.Plat {
if k < 10 {
continue
}
if v.Color == 0 { if v.Color == 0 {
continue continue
} }
@ -612,7 +611,7 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
if k1 == k2 { // 校验k3 左边和右边 if k1 == k2 { // 校验k3 左边和右边
if true { if true {
pos := k + 2 pos := k + 2
if pos%Width-1 >= 0 { // 左 if pos/Width-1 >= 0 { // 左
p := this.Plat[pos-Width].Color p := this.Plat[pos-Width].Color
if p == k1 { if p == k1 {
bEliminate = true bEliminate = true
@ -658,7 +657,6 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
} }
} }
} }
} }
} }
@ -701,7 +699,6 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
bEliminate = true bEliminate = true
return return
} }
} }
if pos%Height+1 < Height { // 上 if pos%Height+1 < Height { // 上
p := this.Plat[pos+1].Color p := this.Plat[pos+1].Color
@ -718,7 +715,6 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
} }
} }
} }
} }
} }
@ -781,3 +777,34 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
} }
return return
} }
// 生成一个不能消除的地图
func (this *MapData) SetIndelibilityPlat() {
for k, v := range this.Plat {
if v.Color == 0 {
continue
}
x := int32(k % Height) // x
if x+2 < Height {
k1 := this.Plat[k].Color
k2 := this.Plat[k+1].Color
k3 := this.Plat[k+2].Color
if k1 == k2 && k2 == k3 {
this.Plat[k+2].Cid = (k3+1)%5 + 1
this.Plat[k+2].Color = (k3+1)%5 + 1
}
}
if k+2*Width < Total {
k1 := this.Plat[k].Color
k2 := this.Plat[k+Width].Color
k3 := this.Plat[k+2*Width].Color
if k1 == k2 && k2 == k3 {
this.Plat[k+2*Width].Cid = (k3+1)%5 + 1
this.Plat[k+2*Width].Color = (k3+1)%5 + 1
}
}
}
}

View File

@ -85,8 +85,11 @@ func Test_Main(t *testing.T) {
m := new(entertainment.MapData) m := new(entertainment.MapData)
m.InitMap(nil) m.InitMap(nil)
m.SetMap() m.SetMap()
m.SetIndelibilityPlat()
m.Debugf() m.Debugf()
m.CheckAndRefreshPlat() if m.CheckAndRefreshPlat() {
fmt.Println("xxxx")
}
//var szMap []*pb.MapData //var szMap []*pb.MapData
// if bSwap, m := m.AiSwapGirde(); bSwap { // if bSwap, m := m.AiSwapGirde(); bSwap {
// szMap = append(szMap, m...) // szMap = append(szMap, m...)