三消地图检测是否有交换不能消除的情况
This commit is contained in:
parent
1ce5b473eb
commit
0dd61aabb4
@ -7,7 +7,12 @@ import (
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) RewardCheck(session comm.IUserSession, req *pb.EntertainRewardReq) (errdata *pb.ErrorData) {
|
||||
|
||||
if req.Key == 0 {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -30,14 +35,13 @@ func (this *apiComp) Reward(session comm.IUserSession, req *pb.EntertainRewardRe
|
||||
|
||||
user, err := this.module.ModuleUser.GetUser(session.GetUserId())
|
||||
if err == nil {
|
||||
if user.Consumeexp == 0 { // 0 不让领
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_UserRepeadReward,
|
||||
Title: pb.ErrorCode_UserRepeadReward.ToString(),
|
||||
if conf, err := this.module.configure.GetGameConsumeintegralReward(req.Key); err == nil {
|
||||
if user.Consumeexp < conf.Key {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_UserRepeadReward,
|
||||
Title: pb.ErrorCode_UserRepeadReward.ToString(),
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if conf, err := this.module.configure.GetGameConsumeintegral(user.Consumeexp); err == nil {
|
||||
if _, ok := list.Reward[conf.Key]; !ok {
|
||||
if errdata, atno = this.module.DispenseAtno(session, conf.Rewards, true); errdata != nil {
|
||||
return
|
||||
|
@ -36,6 +36,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
||||
})
|
||||
configure.RegisterConfigure(game_block, cfg.NewGameBlock, this.LoadGameBlock)
|
||||
|
||||
this.GetGameConsumeintegralReward(100)
|
||||
return
|
||||
}
|
||||
|
||||
@ -128,3 +129,18 @@ func (this *configureComp) GetRobotGameConsumeHero() (cardid string) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *configureComp) GetGameConsumeintegralReward(key int32) (conf *cfg.GameIntegralData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
)
|
||||
if v, err = this.GetConfigure(game_integral); err == nil {
|
||||
if configure, ok := v.(*cfg.GameIntegral); ok {
|
||||
if conf = configure.Get(key); conf != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
err = comm.NewNotFoundConfErr(moduleName, game_integral, key)
|
||||
return
|
||||
}
|
||||
|
@ -83,30 +83,14 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *MapData) SetMap() {
|
||||
sz2 := []int32{
|
||||
1, 1, 2, 5, 1, 5, 2,
|
||||
3, 2, 3, 1, 2, 4, 4,
|
||||
2, 1, 1, 3, 6, 4, 1,
|
||||
4, 1, 1, 4, 3, 6, 3,
|
||||
4, 3, 4, 5, 1, 6, 1,
|
||||
5, 4, 2, 5, 3, 3, 1,
|
||||
4, 1, 5, 3, 2, 3, 4,
|
||||
}
|
||||
var pos int
|
||||
for index := Width - 1; index >= 0; index-- {
|
||||
for j := 0; j < Height; j++ {
|
||||
this.Plat[index+j*Height].Color = sz2[pos]
|
||||
this.Plat[index+j*Height].Cid = sz2[pos]
|
||||
pos++
|
||||
}
|
||||
}
|
||||
}
|
||||
func (this *MapData) Debugf() {
|
||||
fmt.Printf("================\n")
|
||||
var v int
|
||||
for index := Width - 1; index >= 0; index-- {
|
||||
for j := 0; j < Height; j++ {
|
||||
fmt.Printf("%d:%d ", this.Plat[index+j*Height].Oid, this.Plat[index+j*Height].Color)
|
||||
v = index + j*7
|
||||
fmt.Printf("%d:%d ", v, this.Plat[index+j*Height].Color)
|
||||
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
@ -589,18 +573,33 @@ func (this *MapData) CheckInitPlat() {
|
||||
}
|
||||
}
|
||||
|
||||
// 1, 1, 2, 5, 1, 5, 2,
|
||||
// 3, 2, 3, 1, 2, 4, 4,
|
||||
// 2, 1, 1, 3, 6, 4, 1,
|
||||
// 4, 1, 1, 4, 3, 6, 3,
|
||||
// 4, 3, 4, 5, 1, 6, 1,
|
||||
// 5, 4, 2, 5, 3, 3, 1,
|
||||
// 4, 1, 5, 3, 2, 3, 4,
|
||||
func (this *MapData) SetMap() {
|
||||
sz2 := []int32{
|
||||
1, 1, 2, 5, 1, 5, 2,
|
||||
3, 2, 3, 1, 2, 4, 4,
|
||||
2, 1, 1, 3, 6, 4, 1,
|
||||
4, 1, 1, 4, 3, 6, 3,
|
||||
4, 3, 4, 5, 1, 6, 1,
|
||||
5, 4, 2, 5, 3, 3, 1,
|
||||
4, 1, 5, 3, 2, 3, 4,
|
||||
}
|
||||
var pos int
|
||||
for index := Width - 1; index >= 0; index-- {
|
||||
for j := 0; j < Height; j++ {
|
||||
this.Plat[index+j*Height].Color = sz2[pos]
|
||||
this.Plat[index+j*Height].Cid = sz2[pos]
|
||||
pos++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 校验当前地图 有没有能消除的
|
||||
func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
|
||||
bEliminate = false
|
||||
for k, v := range this.Plat {
|
||||
if k < 10 {
|
||||
continue
|
||||
}
|
||||
if v.Color == 0 {
|
||||
continue
|
||||
}
|
||||
@ -609,47 +608,174 @@ func (this *MapData) CheckAndRefreshPlat() (bEliminate bool) {
|
||||
if x+2 < Height {
|
||||
k1 := this.Plat[k].Color
|
||||
k2 := this.Plat[k+1].Color
|
||||
pos := k + 2
|
||||
// k3 := this.Plat[k+2].Color
|
||||
|
||||
if k1 == k2 { // 校验k3 左边和右边
|
||||
if y-1 >= 0 { // 左
|
||||
if this.Plat[pos-Width].Color == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
if true {
|
||||
pos := k + 2
|
||||
if pos%Width-1 >= 0 { // 左
|
||||
p := this.Plat[pos-Width].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if y+1 < Width { // 右
|
||||
if this.Plat[pos+Width].Color == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
if pos/Width+1 < Width { // 右
|
||||
p := this.Plat[pos+Width].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if x+3 < Height { // 上
|
||||
if this.Plat[pos+1].Color == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
if pos%Height+1 < Height { // 上
|
||||
p := this.Plat[pos+1].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if true { // 下左右
|
||||
pos := k - 1
|
||||
if pos-1 >= 0 { // 下
|
||||
if this.Plat[k-2].Color == k1 {
|
||||
if this.Plat[pos-1].Color == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
// 左
|
||||
|
||||
if pos/Width-1 >= 0 {
|
||||
p := this.Plat[pos-Width].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
if pos/Width+1 < Width {
|
||||
p := this.Plat[pos+Width].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// 左右检测
|
||||
if y+1 < Width {
|
||||
|
||||
if y+2 < Height {
|
||||
k1 := this.Plat[k].Color
|
||||
k2 := this.Plat[k+Width].Color
|
||||
if k1 == k2 {
|
||||
//
|
||||
|
||||
if k1 == k2 { // 校验k3 左边和右边
|
||||
if true {
|
||||
pos := k + 2*Width
|
||||
if pos/Width+1 < Width { // 右
|
||||
p := this.Plat[pos+Width].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
if pos%Height+1 < Width { // 上
|
||||
p := this.Plat[pos+1].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
if pos%Height-1 >= 0 { // 下
|
||||
p := this.Plat[pos-1].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if true { // 下左右
|
||||
pos := k - Width
|
||||
if pos < 0 {
|
||||
break
|
||||
}
|
||||
if pos%Height-1 >= 0 { // 下
|
||||
if this.Plat[pos-1].Color == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
if pos%Height+1 < Height { // 上
|
||||
p := this.Plat[pos+1].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
if pos/Width-1 >= 0 { // 右
|
||||
p := this.Plat[pos-Width].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for index := Width - 1; index >= 0; index-- {
|
||||
for j := 0; j < Height; j++ {
|
||||
k := index + j*7
|
||||
if j+3 < Width {
|
||||
k1 := this.Plat[k].Color
|
||||
k2 := this.Plat[k+2*Width].Color
|
||||
pos := index + (j+1)*7
|
||||
if k1 == k2 {
|
||||
// 下 上
|
||||
if pos%Height+1 < Height {
|
||||
p := this.Plat[pos+1].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
if pos%Height-1 >= 0 {
|
||||
p := this.Plat[pos-1].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 上下检测中间元素左右互换
|
||||
for i := 0; i < Height; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
k := j + i*7
|
||||
if k%Height-3 >= 0 {
|
||||
k1 := this.Plat[k].Color
|
||||
k2 := this.Plat[k+2].Color
|
||||
pos := k + 1
|
||||
if k1 == k2 {
|
||||
// 左右
|
||||
if pos%Height-1 >= Width {
|
||||
p := this.Plat[pos-Height].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
if pos%Height+1 < Width {
|
||||
p := this.Plat[pos+Width].Color
|
||||
if p == k1 {
|
||||
bEliminate = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ func Test_Main(t *testing.T) {
|
||||
m := new(entertainment.MapData)
|
||||
m.InitMap(nil)
|
||||
m.SetMap()
|
||||
m.Debugf()
|
||||
m.CheckAndRefreshPlat()
|
||||
//var szMap []*pb.MapData
|
||||
// if bSwap, m := m.AiSwapGirde(); bSwap {
|
||||
|
Loading…
Reference in New Issue
Block a user