Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
821367a9e7
@ -124,7 +124,7 @@ func (this *Room) AiOperator() {
|
||||
this.player1.Ps = MaxPs
|
||||
|
||||
// 交换元素
|
||||
_, szMap, oid1, oid2 = this.chessboard.AiSwapGirde()
|
||||
curScore, szMap, oid1, oid2 = this.chessboard.AiSwapGirde()
|
||||
if this.NexPower != this.curPower {
|
||||
this.round++
|
||||
}
|
||||
@ -190,7 +190,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
if this.player1.Energy >= conf.Skillload {
|
||||
this.player1.Energy = conf.Skillload // 清零
|
||||
this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue)
|
||||
curScore, szMap = this.chessboard.SkillUp(conf.Skilleffect, conf.Skillvalue)
|
||||
}
|
||||
}
|
||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
@ -279,6 +279,15 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}
|
||||
}
|
||||
|
||||
// for _, v := range szMap {
|
||||
// fmt.Printf("======szMap=======\n")
|
||||
// for index := Width - 1; index >= 0; index-- {
|
||||
// for j := 0; j < Height; j++ {
|
||||
// fmt.Printf("%d:%d ", v.Data[index+j*Height].Oid, v.Data[index+j*Height].Color)
|
||||
// }
|
||||
// fmt.Printf("\n")
|
||||
// }
|
||||
// }
|
||||
// 广播消息
|
||||
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
|
||||
Mpadata: szMap,
|
||||
@ -294,7 +303,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
|
||||
}, this.szSession...); err != nil {
|
||||
this.Errorln(err)
|
||||
}
|
||||
if this.round > this.MaxRound { // 游戏结束
|
||||
if this.round > this.MaxRound && this.NexPower == this.player1.Uid { // 游戏结束
|
||||
this.GameOver()
|
||||
return
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/utils"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
@ -85,12 +86,12 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
|
||||
|
||||
func (this *MapData) SetMap() {
|
||||
sz2 := []int32{
|
||||
5, 1, 2, 5, 1, 5, 2,
|
||||
5, 2, 3, 1, 2, 4, 4,
|
||||
4, 1, 1, 3, 6, 4, 1,
|
||||
1, 1, 2, 5, 1, 5, 2,
|
||||
3, 2, 3, 1, 2, 4, 4,
|
||||
2, 1, 1, 3, 6, 4, 1,
|
||||
1, 3, 1, 4, 3, 6, 3,
|
||||
1, 3, 3, 5, 1, 6, 1,
|
||||
5, 1, 5, 5, 1, 3, 1,
|
||||
5, 1, 2, 5, 1, 3, 1,
|
||||
1, 1, 5, 1, 2, 1, 4,
|
||||
}
|
||||
var pos int
|
||||
@ -461,15 +462,14 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData) {
|
||||
}
|
||||
|
||||
score += curScore // 总分
|
||||
this.DropGirde()
|
||||
if curScore > 0 {
|
||||
this.Debugf()
|
||||
if this.DropGirde() {
|
||||
szMap = append(szMap, &pb.MapData{
|
||||
Data: this.Plat,
|
||||
Data: this.GetPalatData(),
|
||||
CurSocre: curScore,
|
||||
Xgrid: count,
|
||||
})
|
||||
}
|
||||
|
||||
// 检查掉落
|
||||
this.operElem = []int32{} // 初始化操作元素
|
||||
if curScore == 0 {
|
||||
@ -481,12 +481,13 @@ func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData) {
|
||||
}
|
||||
|
||||
// 下落 生成新的格子 (返回掉落所获得的分数)
|
||||
func (this *MapData) DropGirde() {
|
||||
|
||||
func (this *MapData) DropGirde() bool {
|
||||
bDrop := false
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
index := i*Width + j
|
||||
if this.Plat[index].Color == 0 { // 说明这列有空
|
||||
bDrop = true
|
||||
var add int
|
||||
for m := j + 1; m < Height; m++ {
|
||||
k1 := i*Width + m
|
||||
@ -505,11 +506,23 @@ func (this *MapData) DropGirde() {
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
return bDrop
|
||||
}
|
||||
func (this *MapData) GetPalatData() (data []*pb.GirdeData) {
|
||||
for _, v := range this.Plat {
|
||||
data = append(data, &pb.GirdeData{
|
||||
Oid: v.Oid,
|
||||
Color: v.Color,
|
||||
Cid: v.Cid,
|
||||
Score: v.Score,
|
||||
Special: v.Special,
|
||||
})
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// ai操作
|
||||
func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32, oid2 int32) {
|
||||
func (this *MapData) AiSwapGirde() (score int32, szMap []*pb.MapData, oid1 int32, oid2 int32) {
|
||||
|
||||
for pos := 0; pos < Total; pos++ {
|
||||
y := pos % Height
|
||||
@ -523,8 +536,9 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32,
|
||||
oid1 = 0
|
||||
oid2 = 0
|
||||
} else {
|
||||
score += s
|
||||
szMap = append(szMap, m...)
|
||||
bSwap = true
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -540,7 +554,7 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32,
|
||||
oid2 = 0
|
||||
} else {
|
||||
szMap = append(szMap, m...)
|
||||
bSwap = true
|
||||
score += s
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -550,11 +564,16 @@ func (this *MapData) AiSwapGirde() (bSwap bool, szMap []*pb.MapData, oid1 int32,
|
||||
}
|
||||
|
||||
// 释放技能 技能id 和参数
|
||||
func (this *MapData) SkillUp(skillid int32, value int32) (plat *pb.MapData) {
|
||||
func (this *MapData) SkillUp(skillid int32, value int32) (score int32, szMap []*pb.MapData) {
|
||||
if skillid == 1 { // 随机消除盘面上X个方块
|
||||
ids := utils.RandomNumbers(0, Total-1, int(value))
|
||||
for _, id := range ids {
|
||||
this.Plat[id] = &pb.GirdeData{}
|
||||
}
|
||||
if this.DropGirde() {
|
||||
score, szMap = this.CheckMap(1)
|
||||
}
|
||||
|
||||
}
|
||||
return &pb.MapData{
|
||||
Data: this.Plat,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ func Test_Main(t *testing.T) {
|
||||
// if bSwap, m := m.AiSwapGirde(); bSwap {
|
||||
// szMap = append(szMap, m...)
|
||||
// }
|
||||
m.SkillUp(1, 7)
|
||||
m.SwapGirde(1, 8)
|
||||
m.CheckMap(1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user