Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
dc424c9cbc
101
modules/entertainment/xxl_test.go
Normal file
101
modules/entertainment/xxl_test.go
Normal file
@ -0,0 +1,101 @@
|
||||
package entertainment_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego"
|
||||
"go_dreamfactory/lego/base/rpcx"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules/equipment"
|
||||
"go_dreamfactory/modules/hero"
|
||||
"go_dreamfactory/modules/items"
|
||||
"go_dreamfactory/modules/user"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/configure"
|
||||
"go_dreamfactory/sys/db"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
var service core.IService
|
||||
var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp()
|
||||
|
||||
var module = new(hero.Hero)
|
||||
|
||||
type TestService struct {
|
||||
rpcx.RPCXService
|
||||
}
|
||||
|
||||
func newService(ops ...rpcx.Option) core.IService {
|
||||
s := new(TestService)
|
||||
s.Configure(ops...)
|
||||
return s
|
||||
}
|
||||
|
||||
//初始化相关系统
|
||||
func (this *TestService) InitSys() {
|
||||
this.RPCXService.InitSys()
|
||||
// if err := log.OnInit(); err != nil {
|
||||
// panic(fmt.Sprintf("Sys log Init err:%v", err))
|
||||
// } else {
|
||||
// log.Infof("Sys log Init success !")
|
||||
// }
|
||||
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.db success!")
|
||||
}
|
||||
if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil {
|
||||
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.configure success!")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Main(t *testing.T) {
|
||||
|
||||
service = newService(
|
||||
rpcx.SetConfPath("../../bin/conf/worker_1.yaml"),
|
||||
)
|
||||
service.OnInstallComp( //装备组件
|
||||
s_gateComp, //此服务需要接受用户的消息 需要装备网关组件
|
||||
)
|
||||
go func() {
|
||||
lego.Run(service, //运行模块
|
||||
module,
|
||||
items.NewModule(),
|
||||
user.NewModule(),
|
||||
equipment.NewModule(),
|
||||
)
|
||||
}()
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
}
|
||||
|
||||
func GetMap() map[int32]int32 {
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyPoint(m *pb.DBHero) *pb.DBHero {
|
||||
vt := reflect.TypeOf(m).Elem()
|
||||
fmt.Println(vt)
|
||||
newoby := reflect.New(vt)
|
||||
newoby.Elem().Set(reflect.ValueOf(m).Elem())
|
||||
newoby.Interface().(*pb.DBHero).Lv = 1111
|
||||
return newoby.Interface().(*pb.DBHero)
|
||||
}
|
||||
|
||||
func wordSepNormalizeFunc(f *flag.FlagSet, name string) flag.NormalizedName {
|
||||
from := []string{"-", "_"}
|
||||
to := "."
|
||||
for _, sep := range from {
|
||||
name = strings.Replace(name, sep, to, -1)
|
||||
}
|
||||
return flag.NormalizedName(name)
|
||||
}
|
203
modules/entertainment/xxlmap.go
Normal file
203
modules/entertainment/xxlmap.go
Normal file
@ -0,0 +1,203 @@
|
||||
package entertainment
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
const (
|
||||
Width = 6
|
||||
Height = 8
|
||||
)
|
||||
|
||||
type Girde struct {
|
||||
X int32 // x
|
||||
Y int32
|
||||
ID int32
|
||||
Itype int32
|
||||
}
|
||||
|
||||
//地图数据
|
||||
type MapData struct {
|
||||
Data map[int32]*Girde // 地图数据
|
||||
}
|
||||
|
||||
// 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))
|
||||
return int32(n.Int64() + 1)
|
||||
}
|
||||
func (this *MapData) GetKeyType(key int32) int32 {
|
||||
var itype int32
|
||||
if v, ok := this.Data[key]; ok {
|
||||
itype = v.Itype
|
||||
}
|
||||
return itype
|
||||
}
|
||||
|
||||
func (this *MapData) GetKeyData(key int32) (data *Girde) {
|
||||
if v, ok := this.Data[key]; ok {
|
||||
return v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化地图数据
|
||||
func (this *MapData) InitMap() {
|
||||
this.Data = make(map[int32]*Girde, Width*Height)
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
tmp := GetRandType()
|
||||
key := int32(i*10 + j)
|
||||
bOk := true // OK 的
|
||||
this.Data[key] = &Girde{
|
||||
X: int32(i),
|
||||
Y: int32(j),
|
||||
ID: key,
|
||||
Itype: tmp,
|
||||
}
|
||||
// 校验 检查格子的左边的左边 和下边和下下边
|
||||
if j-2 > 0 {
|
||||
i1 := this.GetKeyType(int32(i*10 + j - 1))
|
||||
i2 := this.GetKeyType(int32(i*10 + j - 2))
|
||||
if i1 == i2 && tmp == i1 {
|
||||
bOk = false
|
||||
}
|
||||
}
|
||||
if i-2 > 0 {
|
||||
i1 := this.GetKeyType(int32((i-1)*10 + j))
|
||||
i2 := this.GetKeyType(int32((i-2)*10 + j))
|
||||
if i1 == i2 && tmp == i1 {
|
||||
bOk = false
|
||||
}
|
||||
}
|
||||
if !bOk {
|
||||
for i := 0; i < Width*Height; i++ {
|
||||
itype := GetRandType()
|
||||
if tmp != itype {
|
||||
tmp = itype
|
||||
break
|
||||
}
|
||||
}
|
||||
this.Data[key].Itype = tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 交换2个元素
|
||||
func (this *MapData) SwapGirde(i, j int32) bool {
|
||||
var (
|
||||
bSwap bool // 能否交换
|
||||
tmp *Girde
|
||||
)
|
||||
g1 := this.GetKeyData(i)
|
||||
g2 := this.GetKeyData(j)
|
||||
if g1 == nil || g2 == nil {
|
||||
return bSwap
|
||||
}
|
||||
// 校验是不是挨着的
|
||||
|
||||
if g1.X+1 == g2.X {
|
||||
bSwap = true
|
||||
}
|
||||
if g1.X+1 == g2.X {
|
||||
bSwap = true
|
||||
}
|
||||
if g1.Y+1 == g2.Y {
|
||||
bSwap = true
|
||||
}
|
||||
if g1.Y+1 == g2.Y {
|
||||
bSwap = true
|
||||
}
|
||||
// 更新地图数据
|
||||
tmp = new(Girde)
|
||||
*tmp = *g1
|
||||
this.Data[i] = g2
|
||||
this.Data[j] = tmp
|
||||
return bSwap
|
||||
}
|
||||
|
||||
// 校验地图可消除的 判断各组上面2个和右边两个是否三个相等
|
||||
func (this *MapData) CheckMap() {
|
||||
var (
|
||||
del map[int32]struct{}
|
||||
)
|
||||
|
||||
del = map[int32]struct{}{}
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
key := int32(i*10 + j)
|
||||
iType := this.GetKeyType(key)
|
||||
if iType == 0 {
|
||||
continue
|
||||
}
|
||||
if j+2 < Height {
|
||||
i1 := this.GetKeyType(int32((i+1)*10 + j))
|
||||
i2 := this.GetKeyType(int32((i+2)*10 + j))
|
||||
if i1 == i2 && i1 == iType {
|
||||
del[int32((i+1)*10+j)] = struct{}{}
|
||||
del[int32((i+2)*10+j)] = struct{}{}
|
||||
del[key] = struct{}{}
|
||||
}
|
||||
}
|
||||
if i+2 < Width {
|
||||
i1 := this.GetKeyType(int32(i*10 + j + 1))
|
||||
i2 := this.GetKeyType(int32(i*10 + j + 2))
|
||||
if i1 == i2 && i1 == iType {
|
||||
del[int32(i*10+j+1)] = struct{}{}
|
||||
del[int32(i*10+j+2)] = struct{}{}
|
||||
del[key] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 顺着删除列表删除各组
|
||||
for k := range del {
|
||||
this.Data[k] = &Girde{}
|
||||
}
|
||||
fmt.Printf("%v", del)
|
||||
return
|
||||
}
|
||||
|
||||
// 下落 生成新的格子
|
||||
func (this *MapData) DropGirde() (Data map[int32]*Girde) {
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
key := int32(i*10 + j)
|
||||
var sz []*Girde
|
||||
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)
|
||||
l++
|
||||
}
|
||||
}
|
||||
for i, v := range sz {
|
||||
key := int32(i*10 + j + i)
|
||||
this.Data[key] = 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,
|
||||
}
|
||||
}
|
||||
break // 完成该列
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.Data
|
||||
}
|
Loading…
Reference in New Issue
Block a user