新增特殊元素炸弹烟花相关消除规则
This commit is contained in:
parent
bfdf47f87f
commit
15da64c7cd
@ -61,7 +61,7 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
|
||||
Data: this.chessboard.GetPalatData(),
|
||||
})
|
||||
fmt.Printf("===超时棋盘=============\n")
|
||||
this.chessboard.Debugf()
|
||||
//this.chessboard.Debugf()
|
||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
//Mpadata: szMap,
|
||||
Power: this.NexPower,
|
||||
@ -222,11 +222,10 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
case "operator": // 操作消息
|
||||
var (
|
||||
curScore int32 // 该次操作的得分
|
||||
//AIOperator bool
|
||||
oid1 int32 // 唯一id
|
||||
oid2 int32
|
||||
color int32 // 校验消除的颜色
|
||||
bAddPs bool
|
||||
oid1 int32 // 唯一id
|
||||
oid2 int32
|
||||
color int32 // 校验消除的颜色
|
||||
bAddPs bool
|
||||
)
|
||||
var szMap []*pb.MapData
|
||||
req := msg.(*pb.EntertainOperatorReq)
|
||||
@ -381,9 +380,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
|
||||
if this.player1.Ps <= 0 {
|
||||
this.NexPower = this.player2.Userinfo.Uid
|
||||
// if len(this.szSession) == 1 { // 校验2号玩家是不是AI
|
||||
// AIOperator = true
|
||||
// }
|
||||
this.player2.Ps = MaxPs
|
||||
}
|
||||
} else { // this.curPower == this.player2.Uid
|
||||
@ -398,8 +394,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
if this.player2.Ps <= 0 {
|
||||
this.NexPower = this.player1.Userinfo.Uid
|
||||
this.player1.Ps = MaxPs
|
||||
// this.round++
|
||||
|
||||
}
|
||||
}
|
||||
for _, v := range szMap { //
|
||||
@ -454,9 +448,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
// 变更权限
|
||||
this.curPower = this.NexPower
|
||||
// if AIOperator { // AI操作
|
||||
// this.AiOperator()
|
||||
// }
|
||||
|
||||
case "ready":
|
||||
var bStartGame bool // 可以开始游戏
|
||||
this.NexPower = this.player1.Userinfo.Uid
|
||||
@ -582,7 +574,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
}
|
||||
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -18,6 +18,11 @@ const (
|
||||
FourUType = 1 // 4消上下类型
|
||||
FourLType = 2 // 4消左右类型
|
||||
BoomType = 4 // 炸弹类型
|
||||
|
||||
FireUp = 5 //上烟火
|
||||
FireDown = 6 //下烟火
|
||||
FireLeft = 7 //左烟火
|
||||
FireRight = 8 //右烟火
|
||||
)
|
||||
|
||||
type Girde struct {
|
||||
@ -88,11 +93,11 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
|
||||
|
||||
func (this *MapData) Debugf() {
|
||||
fmt.Printf("================\n")
|
||||
var v int
|
||||
//var v int
|
||||
for index := Width - 1; index >= 0; index-- {
|
||||
for j := 0; j < Height; j++ {
|
||||
v = index + j*7
|
||||
fmt.Printf("%d:%d ", v, this.Plat[index+j*Height].Cid)
|
||||
// v = index + j*7
|
||||
fmt.Printf("%d:%d ", this.Plat[index+j*Height].Oid, this.Plat[index+j*Height].Cid)
|
||||
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
@ -360,25 +365,10 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
|
||||
}
|
||||
|
||||
if s := this.Plat[id].Special; s != 0 {
|
||||
if s == FourUType { // 4消上下类型
|
||||
for i := 0; i < Height; i++ { // id 的一条线位置
|
||||
x[(id/Width)*Height+i] = struct{}{}
|
||||
}
|
||||
} else if s == FourLType { // 左右类型
|
||||
for i := 0; i < Width; i++ { // id 的一条线位置
|
||||
x[id%Height+i*Width] = struct{}{}
|
||||
}
|
||||
} else if s == FiveType { // 随机消除
|
||||
// 获取配置
|
||||
if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil {
|
||||
if xc, _ := this.SkillUp(0, color, 1, c.Value, false); len(xc) > 0 {
|
||||
//szMap = append(szMap, sz...)
|
||||
for key := range xc {
|
||||
x[key] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
for k := range this.SpecialElem(id, s) {
|
||||
x[k] = struct{}{}
|
||||
}
|
||||
|
||||
}
|
||||
x[id] = struct{}{}
|
||||
}
|
||||
@ -399,6 +389,7 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
|
||||
CurSocre: curScore,
|
||||
CurEnergy: energy,
|
||||
})
|
||||
this.Debugf()
|
||||
|
||||
}
|
||||
|
||||
@ -507,7 +498,6 @@ func (this *MapData) SkillUp(pos int32, color int32, skillid int32, value int32,
|
||||
x = make(map[int]struct{})
|
||||
if skillid == 1 { // 随机消除盘面上X个方块
|
||||
ids = utils.RandomNumbers(0, Total-1, int(value))
|
||||
|
||||
} else if skillid == 4 { // 找到pos 位置的所有方块
|
||||
x := int(pos / Width)
|
||||
y := int(pos % Height)
|
||||
@ -527,8 +517,7 @@ func (this *MapData) SkillUp(pos int32, color int32, skillid int32, value int32,
|
||||
ids = append(ids, (x+i)*Width+(y-i))
|
||||
}
|
||||
}
|
||||
|
||||
} else if skillid == 3 || skillid == 5 { //选中一个方块,消除周围一圈
|
||||
} else if skillid == 5 { //选中一个方块,消除周围一圈
|
||||
ids = append(ids, int(pos)) // 包含自己
|
||||
x := int(pos / Width)
|
||||
y := int(pos % Height)
|
||||
@ -557,32 +546,29 @@ func (this *MapData) SkillUp(pos int32, color int32, skillid int32, value int32,
|
||||
if x+1 < Width && y-1 >= 0 { // 右下
|
||||
ids = append(ids, (x+1)*Width+(y-1))
|
||||
}
|
||||
|
||||
} else if skillid == 2 { // 消除中间的一列宝石
|
||||
for i := 0; i < Height; i++ {
|
||||
ids = append(ids, 3*Width+i)
|
||||
}
|
||||
} else if skillid == 3 { // 四周蔓延 第一次100% 第二次 60% 第三次 30% 第四次 10% 最多4次
|
||||
var mids map[int]struct{}
|
||||
mids = make(map[int]struct{}, 0)
|
||||
for i := 0; i < 4; i++ {
|
||||
dd := this.Skill3(pos, int32(i))
|
||||
for k := range dd {
|
||||
for s := range this.Skill3(int32(k), int32(i)) {
|
||||
mids[s] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
for k := range mids {
|
||||
ids = append(ids, k) // 转换成最终消除的坐标
|
||||
}
|
||||
}
|
||||
for _, id := range ids {
|
||||
s := this.Plat[id].Special
|
||||
if s != 0 {
|
||||
if s == FourUType { // 4消上下类型
|
||||
for i := 0; i < Height; i++ { // id 的一条线位置
|
||||
x[(id/Width)*Height+i] = struct{}{}
|
||||
}
|
||||
} else if s == FourLType { // 左右类型
|
||||
for i := 0; i < Width; i++ { // id 的一条线位置
|
||||
x[id%Height+i*Width] = struct{}{}
|
||||
}
|
||||
} else if s == FiveType { // 随机消除
|
||||
// 获取配置
|
||||
if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil {
|
||||
if xc, _ := this.SkillUp(pos, color, 1, c.Value, false); len(xc) > 0 { // 递归调用
|
||||
for key := range xc {
|
||||
x[key] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
if s := this.Plat[id].Special; s != 0 {
|
||||
for k := range this.SpecialElem(id, s) {
|
||||
x[k] = struct{}{}
|
||||
}
|
||||
}
|
||||
x[id] = struct{}{}
|
||||
@ -623,10 +609,10 @@ func (this *MapData) SetMap() {
|
||||
3, 3, 2, 2, 1, 3, 1,
|
||||
5, 1, 2, 3, 1, 2, 2,
|
||||
3, 4, 3, 5, 6, 1, 6,
|
||||
1, 4, 6, 4, 2, 3, 6,
|
||||
1, 5, 6, 5, 6, 1, 4,
|
||||
1, 4, 1, 4, 2, 3, 6,
|
||||
1, 5, 1, 5, 6, 1, 4,
|
||||
6, 6, 4, 6, 4, 3, 3,
|
||||
3, 3, 6, 1, 1, 2, 5,
|
||||
3, 3, 1, 2, 1, 2, 5,
|
||||
// 1, 4, 2, 5, 4, 5, 2,
|
||||
// 3, 2, 3, 5, 2, 1, 4,
|
||||
// 2, 5, 5, 4, 5, 4, 1,
|
||||
@ -916,5 +902,161 @@ func (this *MapData) RedsetPlatData() {
|
||||
}
|
||||
|
||||
this.SetIndelibilityPlat()
|
||||
//this.Debugf()
|
||||
}
|
||||
|
||||
//四周蔓延 第一次100% 第二次 60% 第三次 30% 第四次 10% 最多4次
|
||||
func (this *MapData) Skill3(pos int32, count int32) (m map[int]struct{}) {
|
||||
m = make(map[int]struct{}, 0)
|
||||
var sz []int
|
||||
var percent int32
|
||||
// 先找出可以蔓延的方向
|
||||
x := int(pos / Width)
|
||||
y := int(pos % Height)
|
||||
if x-1 >= 0 { // 左
|
||||
sz = append(sz, (x-1)*Width+(y))
|
||||
}
|
||||
if y-1 >= 0 { // 下
|
||||
sz = append(sz, (x)*Width+(y-1))
|
||||
}
|
||||
if y+1 < Height { // 上
|
||||
sz = append(sz, (x)*Width+(y+1))
|
||||
}
|
||||
if x+1 < Width { // 右
|
||||
sz = append(sz, (x+1)*Width+(y))
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
percent = 100
|
||||
} else if count == 1 {
|
||||
percent = 100
|
||||
} else if count == 2 || count == 3 {
|
||||
percent = 100
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
szid := utils.RandomNumbers(0, len(sz), 2)
|
||||
for _, v := range szid {
|
||||
if percent >= comm.GetRandNum(0, 100) {
|
||||
m[sz[v]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 获取BoomType 类型周围的所有元素(pos 四周+ 四周的上下左右)
|
||||
func (this *MapData) GetBoomElem(pos int) (elem []int) {
|
||||
|
||||
x := int(pos / Width)
|
||||
y := int(pos % Height)
|
||||
if x-1 >= 0 { // 左
|
||||
elem = append(elem, (x-1)*Width+(y))
|
||||
}
|
||||
if y-1 >= 0 { // 下
|
||||
elem = append(elem, (x)*Width+(y-1))
|
||||
}
|
||||
if y+1 < Height { // 上
|
||||
elem = append(elem, (x)*Width+(y+1))
|
||||
}
|
||||
if x+1 < Width { // 右
|
||||
elem = append(elem, (x+1)*Width+(y))
|
||||
}
|
||||
if x-1 >= 0 && y+1 < Height { // 左上
|
||||
elem = append(elem, (x-1)*Width+(y+1))
|
||||
}
|
||||
if x-1 >= 0 && y-1 >= 0 { // 左下
|
||||
elem = append(elem, (x-1)*Width+(y-1))
|
||||
}
|
||||
|
||||
if x+1 < Width && y+1 < Height { // 右上
|
||||
elem = append(elem, (x+1)*Width+(y+1))
|
||||
}
|
||||
if x+1 < Width && y-1 >= 0 { // 右下
|
||||
elem = append(elem, (x+1)*Width+(y-1))
|
||||
}
|
||||
///
|
||||
if x-2 >= 0 { // 左左
|
||||
elem = append(elem, (x-2)*Width+(y))
|
||||
}
|
||||
if y-2 >= 0 { // 下下
|
||||
elem = append(elem, (x)*Width+(y-2))
|
||||
}
|
||||
if y+2 < Height { // 上上
|
||||
elem = append(elem, (x)*Width+(y+2))
|
||||
}
|
||||
if x+2 < Width { // 右右
|
||||
elem = append(elem, (x+2)*Width+(y))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *MapData) GetFireBoom(pos int, itype int32) (elem []int) {
|
||||
x := int(pos / Width)
|
||||
y := int(pos % Height)
|
||||
|
||||
switch itype {
|
||||
case FireUp: //上烟火
|
||||
for i := 0; i < Height; i++ {
|
||||
if y+1 < Height { // 上上
|
||||
elem = append(elem, (x)*Width+(y+1))
|
||||
y += 1
|
||||
}
|
||||
}
|
||||
case FireDown: //下烟火
|
||||
for i := 0; i < Height; i++ {
|
||||
if y-1 >= 0 { // 下下
|
||||
elem = append(elem, (x)*Width+(y-1))
|
||||
y -= 1
|
||||
}
|
||||
}
|
||||
case FireLeft: //左烟火
|
||||
for i := 0; i < Height; i++ {
|
||||
if x-1 >= 0 { // 左左
|
||||
elem = append(elem, (x-1)*Width+(y))
|
||||
x -= 1
|
||||
}
|
||||
}
|
||||
case FireRight: //右烟火
|
||||
for i := 0; i < Height; i++ {
|
||||
if x+1 < Width { // 右右
|
||||
elem = append(elem, (x+1)*Width+(y))
|
||||
x += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 特殊类型元素 统一处理
|
||||
func (this *MapData) SpecialElem(id int, s int32) (x map[int]struct{}) {
|
||||
|
||||
x = make(map[int]struct{})
|
||||
if s == FourUType { // 4消上下类型
|
||||
for i := 0; i < Height; i++ { // id 的一条线位置
|
||||
x[(id/Width)*Height+i] = struct{}{}
|
||||
}
|
||||
} else if s == FourLType { // 左右类型
|
||||
for i := 0; i < Width; i++ { // id 的一条线位置
|
||||
x[id%Height+i*Width] = struct{}{}
|
||||
}
|
||||
} else if s == FiveType { // 随机消除
|
||||
// 获取配置
|
||||
if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil {
|
||||
ids := utils.RandomNumbers(0, Total-1, int(c.Value))
|
||||
for key := range ids {
|
||||
x[key] = struct{}{}
|
||||
}
|
||||
}
|
||||
} else if s == BoomType { // 炸弹类型 带走周围一圈+ 上下左右
|
||||
for key := range this.GetBoomElem(id) {
|
||||
x[key] = struct{}{}
|
||||
}
|
||||
} else if s == FireUp || s == FireDown || s == FireLeft || s == FireRight { // 烟花技能
|
||||
for key := range this.GetFireBoom(id, s) {
|
||||
x[key] = struct{}{}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -82,16 +82,50 @@ func Test_Main(t *testing.T) {
|
||||
entertainment.NewModule(),
|
||||
)
|
||||
}()
|
||||
|
||||
// sz := utils.RandomNumbers(0, 2, 2)
|
||||
// fmt.Printf("xxxx%v", sz)
|
||||
m := new(entertainment.MapData)
|
||||
m.InitMap(nil)
|
||||
|
||||
//m.SkillUp(24, 1, 3, 7, true)
|
||||
m.SetMap()
|
||||
var vids int
|
||||
for index := 7 - 1; index >= 0; index-- {
|
||||
for j := 0; j < 7; j++ {
|
||||
vids = index + j*7
|
||||
fmt.Printf("%d ", vids)
|
||||
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
for i := 0; i < 4; i++ {
|
||||
b := m.GetFireBoom(30, int32(i)+5)
|
||||
fmt.Printf("xxxx %d\n", b)
|
||||
}
|
||||
var mids map[int]struct{}
|
||||
mids = make(map[int]struct{}, 0)
|
||||
// k := m.Skill3(24, 0)
|
||||
for i := 0; i < 4; i++ {
|
||||
|
||||
dd := m.Skill3(24, int32(i))
|
||||
for k := range dd {
|
||||
for s := range m.Skill3(int32(k), int32(i)) {
|
||||
mids[s] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
for b := range mids {
|
||||
fmt.Printf("xxxx %d\n", b)
|
||||
}
|
||||
|
||||
fmt.Printf("xxxx %v\n", m.GetBoomElem(46))
|
||||
m.Debugf()
|
||||
// b := m.CheckAndRefreshPlat()
|
||||
// fmt.Printf("xxxx%v", b)
|
||||
//m.RedsetPlatData()
|
||||
m.SwapGirde(15, 22)
|
||||
m.Debugf()
|
||||
b := m.CheckAndRefreshPlat()
|
||||
fmt.Printf("xxxx%v", b)
|
||||
m.RedsetPlatData()
|
||||
m.SwapGirde(1, 8)
|
||||
m.CheckMap(1, false)
|
||||
m.Debugf()
|
||||
// for i := 0; i < 100; i++ {
|
||||
|
Loading…
Reference in New Issue
Block a user