xxl 规则
This commit is contained in:
parent
ccf7f6df92
commit
8c3fe6c9e2
@ -28,7 +28,10 @@ func (this *gameMgrComp) Init(service core.IService, module core.IModule, comp c
|
||||
return
|
||||
}
|
||||
|
||||
func (this *gameMgrComp) CreateRoom(room *Room) {
|
||||
func (this *gameMgrComp) CreateRoom(session [2]comm.IUserSession) {
|
||||
room := new(Room) //初始化房间
|
||||
room.InitRoom(session)
|
||||
|
||||
this.lock.Lock()
|
||||
this.rooms[room.Id] = room
|
||||
this.lock.Unlock()
|
||||
@ -40,7 +43,7 @@ func (this *gameMgrComp) CloseRoom(id string) {
|
||||
this.lock.Unlock()
|
||||
}
|
||||
|
||||
func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, req proto.Message) (errdata *pb.ErrorData) {
|
||||
func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, stype string, req proto.Message) (errdata *pb.ErrorData) {
|
||||
var (
|
||||
room *Room
|
||||
ok bool
|
||||
@ -49,7 +52,7 @@ func (this *gameMgrComp) RoomDistribute(rid string, session comm.IUserSession, r
|
||||
room, ok = this.rooms[rid]
|
||||
this.lock.RUnlock()
|
||||
if ok {
|
||||
errdata = room.ReceiveMessage(session, req)
|
||||
errdata = room.ReceiveMessage(session, stype, req)
|
||||
} else {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ReqParameterError,
|
||||
|
@ -50,8 +50,10 @@ func (this *Entertainment) Start() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
this.xxl = new(MapData)
|
||||
this.xxl.InitMap()
|
||||
this.xxl.SwapGirde(1, 0)
|
||||
// this.xxl = new(MapData)
|
||||
// this.xxl.InitMap()
|
||||
// this.xxl.SwapGirde(1, 0)
|
||||
// this.xxl.CheckMap()
|
||||
// this.xxl.DropGirde()
|
||||
return
|
||||
}
|
||||
|
9
modules/entertainment/player.go
Normal file
9
modules/entertainment/player.go
Normal file
@ -0,0 +1,9 @@
|
||||
package entertainment
|
||||
|
||||
type Player struct {
|
||||
uid string
|
||||
operate int32 // 该谁操作
|
||||
score int32 // 玩家积分
|
||||
step int32 // 操作步骤
|
||||
status int32 // 状态
|
||||
}
|
@ -4,15 +4,43 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//游戏房间
|
||||
type Room struct {
|
||||
Id string
|
||||
Id string
|
||||
player1 *Player // 玩家1
|
||||
player2 *Player // 玩家2
|
||||
chessboard *MapData
|
||||
}
|
||||
|
||||
func (this *Room) ReceiveMessage(session comm.IUserSession, req proto.Message) (errdata *pb.ErrorData) {
|
||||
func (this *Room) InitRoom(session [2]comm.IUserSession) *Room {
|
||||
this.chessboard = new(MapData)
|
||||
this.chessboard.InitMap() // 初始化棋盘
|
||||
return &Room{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
player1: &Player{},
|
||||
player2: &Player{},
|
||||
chessboard: this.chessboard,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, req proto.Message) (errdata *pb.ErrorData) {
|
||||
switch stype {
|
||||
case "opertor": // 操作消息
|
||||
//req1 := req.(*pb.BattleCmd)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 玩家操作
|
||||
func (this *Room) Opertor(set int32, iType int32, old int32, new int32) (errdata *pb.ErrorData) {
|
||||
if iType == 1 {
|
||||
this.chessboard.SwapGirde(old, new) // 交换格子
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -29,10 +29,6 @@ func (this *MapData) Init(service core.IService, module core.IModule, comp core.
|
||||
return
|
||||
}
|
||||
|
||||
// func (this *MapData) init() {
|
||||
// this.Data = make(map[int32]*Girde, Width*Height)
|
||||
// }
|
||||
|
||||
// 1~6随机一个数
|
||||
func GetRandType() int32 {
|
||||
n, _ := rand.Int(rand.Reader, big.NewInt(6))
|
||||
@ -56,7 +52,7 @@ func (this *MapData) GetKeyData(key int32) (data *Girde) {
|
||||
// 初始化地图数据
|
||||
func (this *MapData) InitMap() {
|
||||
this.Data = make(map[int32]*Girde, Width*Height)
|
||||
for i := Width - 1; i >= 0; i-- {
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
tmp := GetRandType()
|
||||
key := int32(i*10 + j)
|
||||
@ -92,10 +88,26 @@ func (this *MapData) InitMap() {
|
||||
}
|
||||
this.Data[key].Itype = tmp
|
||||
}
|
||||
fmt.Printf("key:%d,x:%d,y:%d,type:%d \n", key, i, j, tmp)
|
||||
}
|
||||
}
|
||||
|
||||
sz2 := []int32{
|
||||
5, 1, 3, 5, 1, 5, 2,
|
||||
3, 1, 5, 4, 2, 4, 4,
|
||||
4, 4, 1, 5, 6, 4, 1,
|
||||
6, 3, 1, 1, 3, 6, 3,
|
||||
6, 3, 5, 2, 4, 6, 1,
|
||||
5, 2, 4, 2, 1, 3, 1,
|
||||
6, 5, 5, 1, 2, 1, 4,
|
||||
}
|
||||
var index = 0
|
||||
for j := Height - 1; j >= 0; j-- {
|
||||
for i := 0; i < Width; i++ {
|
||||
key := int32(i*10 + j)
|
||||
this.Data[key].Itype = sz2[index]
|
||||
index++
|
||||
}
|
||||
}
|
||||
this.Debugf()
|
||||
}
|
||||
|
||||
@ -139,10 +151,10 @@ func (this *MapData) SwapGirde(i, j int32) bool {
|
||||
|
||||
func (this *MapData) Debugf() {
|
||||
fmt.Printf("================\n")
|
||||
for i := Width - 1; i >= 0; i-- {
|
||||
for j := 0; j < Height; j++ {
|
||||
for j := Height - 1; j >= 0; j-- {
|
||||
for i := 0; i < Width; i++ {
|
||||
key := int32(i*10 + j)
|
||||
fmt.Printf("%d-%d-%d ", i, j, this.Data[key].Itype)
|
||||
fmt.Printf("%d ", this.Data[key].Itype)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
@ -155,7 +167,7 @@ func (this *MapData) CheckMap() {
|
||||
)
|
||||
|
||||
del = map[int32]struct{}{}
|
||||
for i := Width - 1; i >= 0; i-- {
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
key := int32(i*10 + j)
|
||||
iType := this.GetKeyType(key)
|
||||
@ -184,45 +196,43 @@ func (this *MapData) CheckMap() {
|
||||
}
|
||||
// 顺着删除列表删除各组
|
||||
for k := range del {
|
||||
this.Data[k] = &Girde{}
|
||||
this.Data[k].Itype = 0
|
||||
}
|
||||
fmt.Printf("%v", del)
|
||||
fmt.Printf("===del:%v", del)
|
||||
this.Debugf()
|
||||
return
|
||||
}
|
||||
|
||||
// 下落 生成新的格子
|
||||
func (this *MapData) DropGirde() (Data map[int32]*Girde) {
|
||||
for i := Width - 1; i >= 0; i-- {
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
key := int32(i*10 + j)
|
||||
var sz []*Girde
|
||||
var sz []int32
|
||||
var l int // 落下多少个
|
||||
if this.GetKeyType(key) == 0 { // 找上面的
|
||||
for m := j; m < Height; m++ {
|
||||
key1 := int32(i*10 + m)
|
||||
t := this.GetKeyData(key1)
|
||||
if t.Itype != 0 {
|
||||
sz = append(sz, t)
|
||||
sz = append(sz, t.Itype)
|
||||
l++
|
||||
}
|
||||
}
|
||||
for i, v := range sz {
|
||||
key := int32(i*10 + j + i)
|
||||
this.Data[key] = v
|
||||
for pos, v := range sz {
|
||||
key := int32(i*10 + j + pos)
|
||||
this.Data[key].Itype = v
|
||||
}
|
||||
|
||||
for n := j + l; n < Height; n++ {
|
||||
key := int32(i*10 + n)
|
||||
tmp := GetRandType()
|
||||
this.Data[key] = &Girde{
|
||||
X: int32(i),
|
||||
Y: int32(j),
|
||||
ID: key,
|
||||
Itype: tmp,
|
||||
}
|
||||
this.Data[key].Itype = tmp
|
||||
}
|
||||
break // 完成该列
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Debugf()
|
||||
return this.Data
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user