技能+消除校验
This commit is contained in:
parent
6d83897951
commit
54a8f103b6
@ -164,7 +164,21 @@ func (this *Room) AiOperator() {
|
|||||||
this.player1.Ps = MaxPs
|
this.player1.Ps = MaxPs
|
||||||
this.round++
|
this.round++
|
||||||
}
|
}
|
||||||
|
// 校验下次是不是消除
|
||||||
|
if this.chessboard.CheckAndRefreshPlat() {
|
||||||
|
this.chessboard.RedsetPlatData()
|
||||||
|
szMap = append(szMap, &pb.MapData{
|
||||||
|
Data: this.chessboard.GetPalatData(),
|
||||||
|
ChangeType: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for _, v := range szMap { //
|
||||||
|
curScore += v.CurSocre
|
||||||
|
this.player2.Score += v.CurSocre
|
||||||
|
v.CurSocre = this.player2.Score
|
||||||
|
this.player2.Energy += v.CurEnergy
|
||||||
|
v.CurEnergy = this.player2.Energy
|
||||||
|
}
|
||||||
// 广播消息
|
// 广播消息
|
||||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||||
Mpadata: szMap,
|
Mpadata: szMap,
|
||||||
@ -233,7 +247,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
}
|
}
|
||||||
if this.player1.Energy >= conf.Skillload {
|
if this.player1.Energy >= conf.Skillload {
|
||||||
this.player1.Energy = 0 // 清零
|
this.player1.Energy = 0 // 清零
|
||||||
if m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue); len(m) > 0 {
|
if _, m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 {
|
||||||
szMap = append(szMap, m...)
|
szMap = append(szMap, m...)
|
||||||
} else {
|
} else {
|
||||||
szMap = append(szMap, &pb.MapData{
|
szMap = append(szMap, &pb.MapData{
|
||||||
@ -265,7 +279,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
}
|
}
|
||||||
if this.player2.Energy >= conf.Skillload {
|
if this.player2.Energy >= conf.Skillload {
|
||||||
this.player2.Energy = 0 // 清零
|
this.player2.Energy = 0 // 清零
|
||||||
if m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue); len(m) > 0 {
|
if _, m := this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 {
|
||||||
szMap = append(szMap, m...)
|
szMap = append(szMap, m...)
|
||||||
} else {
|
} else {
|
||||||
szMap = append(szMap, &pb.MapData{
|
szMap = append(szMap, &pb.MapData{
|
||||||
@ -327,6 +341,14 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 校验下次是不是消除
|
||||||
|
if this.chessboard.CheckAndRefreshPlat() {
|
||||||
|
this.chessboard.RedsetPlatData()
|
||||||
|
szMap = append(szMap, &pb.MapData{
|
||||||
|
Data: this.chessboard.GetPalatData(),
|
||||||
|
ChangeType: 1,
|
||||||
|
})
|
||||||
|
}
|
||||||
if this.curPower == this.player1.Userinfo.Uid { //权限校验
|
if this.curPower == this.player1.Userinfo.Uid { //权限校验
|
||||||
this.player1.Score += curScore
|
this.player1.Score += curScore
|
||||||
this.player1.Ps--
|
this.player1.Ps--
|
||||||
|
@ -3,6 +3,7 @@ package entertainment
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
"math/big"
|
"math/big"
|
||||||
@ -16,6 +17,7 @@ const (
|
|||||||
FiveType = 3 // 5消类型
|
FiveType = 3 // 5消类型
|
||||||
FourUType = 1 // 4消上下类型
|
FourUType = 1 // 4消上下类型
|
||||||
FourLType = 2 // 4消左右类型
|
FourLType = 2 // 4消左右类型
|
||||||
|
BoomType = 4 // 炸弹类型
|
||||||
)
|
)
|
||||||
|
|
||||||
type Girde struct {
|
type Girde struct {
|
||||||
@ -56,6 +58,7 @@ func (this *MapData) CreateGride(index int32) *pb.GirdeData {
|
|||||||
// 初始化地图数据
|
// 初始化地图数据
|
||||||
func (this *MapData) InitMap(module *Entertainment) {
|
func (this *MapData) InitMap(module *Entertainment) {
|
||||||
this.module = module
|
this.module = module
|
||||||
|
|
||||||
this.oid = 1000 // 方便观察 从1000开始
|
this.oid = 1000 // 方便观察 从1000开始
|
||||||
this.Plat = make([]*pb.GirdeData, Width*Height)
|
this.Plat = make([]*pb.GirdeData, Width*Height)
|
||||||
for i := 0; i < Width*Height; i++ {
|
for i := 0; i < Width*Height; i++ {
|
||||||
@ -86,11 +89,11 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
|
|||||||
|
|
||||||
func (this *MapData) Debugf() {
|
func (this *MapData) Debugf() {
|
||||||
fmt.Printf("================\n")
|
fmt.Printf("================\n")
|
||||||
//var v int
|
var v int
|
||||||
for index := Width - 1; index >= 0; index-- {
|
for index := Width - 1; index >= 0; index-- {
|
||||||
for j := 0; j < Height; j++ {
|
for j := 0; j < Height; j++ {
|
||||||
//v = index + j*7
|
v = index + j*7
|
||||||
fmt.Printf("%d:%d ", this.Plat[index+j*Height].Cid, this.Plat[index+j*Height].Color)
|
fmt.Printf("%d:%d ", v, this.Plat[index+j*Height].Cid)
|
||||||
|
|
||||||
}
|
}
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
@ -313,14 +316,24 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
|
|||||||
energy++
|
energy++
|
||||||
}
|
}
|
||||||
curScore += this.Plat[id].Score
|
curScore += this.Plat[id].Score
|
||||||
if conf, err := this.module.configure.GetGameBlock(this.Plat[id].Color, int32(new[id])); err == nil {
|
this.oid++ // 生成一个新的类型元素
|
||||||
this.oid++ // 生成一个新的类型元素
|
if this.module == nil { // 稍后删掉 方便测试
|
||||||
this.Plat[id] = &pb.GirdeData{
|
this.Plat[id] = &pb.GirdeData{
|
||||||
Oid: this.oid,
|
Oid: this.oid,
|
||||||
Color: this.Plat[id].Color,
|
Color: this.Plat[id].Color,
|
||||||
Cid: conf.Key,
|
Cid: 2*(this.Plat[id].Color-1) + 6 + int32(new[id]),
|
||||||
Score: conf.Score,
|
Score: 1,
|
||||||
Special: conf.Type,
|
Special: int32(new[id]),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if conf, err := this.module.configure.GetGameBlock(this.Plat[id].Color, int32(new[id])); err == nil {
|
||||||
|
this.Plat[id] = &pb.GirdeData{
|
||||||
|
Oid: this.oid,
|
||||||
|
Color: this.Plat[id].Color,
|
||||||
|
Cid: conf.Key,
|
||||||
|
Score: conf.Score,
|
||||||
|
Special: conf.Type,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@ -336,7 +349,15 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
|
|||||||
x[id%Height+i*Width] = struct{}{}
|
x[id%Height+i*Width] = struct{}{}
|
||||||
}
|
}
|
||||||
} else if s == FiveType { // 随机消除
|
} else if s == FiveType { // 随机消除
|
||||||
|
// 获取配置
|
||||||
|
if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil {
|
||||||
|
if xc, _ := this.SkillUp(1, c.Value, false); len(xc) > 0 {
|
||||||
|
//szMap = append(szMap, sz...)
|
||||||
|
for key := range xc {
|
||||||
|
x[key] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x[id] = struct{}{}
|
x[id] = struct{}{}
|
||||||
@ -398,6 +419,8 @@ func (this *MapData) DropGirde() bool {
|
|||||||
//this.Debugf()
|
//this.Debugf()
|
||||||
return bDrop
|
return bDrop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 深拷贝
|
||||||
func (this *MapData) GetPalatData() (data []*pb.GirdeData) {
|
func (this *MapData) GetPalatData() (data []*pb.GirdeData) {
|
||||||
for _, v := range this.Plat {
|
for _, v := range this.Plat {
|
||||||
data = append(data, &pb.GirdeData{
|
data = append(data, &pb.GirdeData{
|
||||||
@ -455,15 +478,41 @@ func (this *MapData) AiSwapGirde() (szMap []*pb.MapData, oid1 int32, oid2 int32,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 释放技能 技能id 和参数
|
// 释放技能 技能id 和参数
|
||||||
func (this *MapData) SkillUp(skillid int32, value int32) (szMap []*pb.MapData) {
|
func (this *MapData) SkillUp(skillid int32, value int32, bDrop bool) (x map[int]struct{}, szMap []*pb.MapData) {
|
||||||
if skillid == 1 { // 随机消除盘面上X个方块
|
if skillid == 1 { // 随机消除盘面上X个方块
|
||||||
|
x = make(map[int]struct{})
|
||||||
ids := utils.RandomNumbers(0, Total-1, int(value))
|
ids := utils.RandomNumbers(0, Total-1, int(value))
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
this.Plat[id] = &pb.GirdeData{}
|
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(1, c.Value, false); len(xc) > 0 { // 递归调用
|
||||||
|
for key := range xc {
|
||||||
|
x[key] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x[id] = struct{}{}
|
||||||
}
|
}
|
||||||
if this.DropGirde() {
|
if bDrop {
|
||||||
szMap, _ = this.CheckMap(1, false)
|
for key := range x {
|
||||||
|
this.Plat[key] = &pb.GirdeData{}
|
||||||
|
}
|
||||||
|
if this.DropGirde() {
|
||||||
|
szMap, _ = this.CheckMap(1, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -497,6 +546,7 @@ func (this *MapData) SetMap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.SetIndelibilityPlat()
|
this.SetIndelibilityPlat()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验当前地图 有没有能消除的
|
// 校验当前地图 有没有能消除的
|
||||||
@ -630,3 +680,21 @@ func (this *MapData) SetIndelibilityPlat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重新洗牌
|
||||||
|
func (this *MapData) RedsetPlatData() {
|
||||||
|
|
||||||
|
for i := 0; i < Total-1; i++ {
|
||||||
|
targetId := comm.GetRandNum(0, Total-1)
|
||||||
|
if i == int(targetId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tmp := new(pb.GirdeData)
|
||||||
|
*tmp = *this.Plat[i]
|
||||||
|
this.Plat[i] = this.Plat[targetId]
|
||||||
|
this.Plat[targetId] = tmp
|
||||||
|
}
|
||||||
|
this.Debugf()
|
||||||
|
|
||||||
|
this.SetIndelibilityPlat()
|
||||||
|
}
|
||||||
|
@ -85,6 +85,9 @@ func Test_Main(t *testing.T) {
|
|||||||
m := new(entertainment.MapData)
|
m := new(entertainment.MapData)
|
||||||
m.InitMap(nil)
|
m.InitMap(nil)
|
||||||
m.SetMap()
|
m.SetMap()
|
||||||
|
b := m.CheckAndRefreshPlat()
|
||||||
|
fmt.Printf("xxxx%v", b)
|
||||||
|
m.RedsetPlatData()
|
||||||
m.SwapGirde(1, 8)
|
m.SwapGirde(1, 8)
|
||||||
m.CheckMap(1, false)
|
m.CheckMap(1, false)
|
||||||
m.Debugf()
|
m.Debugf()
|
||||||
@ -109,7 +112,7 @@ func Test_Main(t *testing.T) {
|
|||||||
// if bSwap, m := m.AiSwapGirde(); bSwap {
|
// if bSwap, m := m.AiSwapGirde(); bSwap {
|
||||||
// szMap = append(szMap, m...)
|
// szMap = append(szMap, m...)
|
||||||
// }
|
// }
|
||||||
m.SkillUp(1, 7)
|
m.SkillUp(1, 7, true)
|
||||||
m.SwapGirde(1, 8)
|
m.SwapGirde(1, 8)
|
||||||
//m.CheckMap(1)
|
//m.CheckMap(1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user