Skip to content

Commit 45ca3f9

Browse files
committed
code
1 parent c7d06c1 commit 45ca3f9

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

SM/FSM.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package SM
2+
3+
import "log"
4+
5+
// 有限状态机
6+
type FSM struct {
7+
CurrentState int // 当前状态数组的索引数值
8+
State []int // 自定义状态
9+
// CallBcaks Callbacks // 回调函数
10+
}
11+
12+
type Callback func()
13+
14+
type Callbacks map[string]Callback
15+
16+
func NewFSM(data []int) *FSM {
17+
if len(data) == 0{
18+
log.Println("create new FSM is fail")
19+
return nil
20+
}
21+
return &FSM{
22+
CurrentState: 0,
23+
State:data,
24+
}
25+
}
26+
27+
func (this *FSM)NextTurn() {
28+
if this!=nil{
29+
if this.CurrentState <len(this.State)+1{
30+
this.CurrentState++
31+
}else {
32+
this.CurrentState = 0
33+
}
34+
}else {
35+
log.Println("FSM is nil")
36+
}
37+
}
38+
39+
func (this *FSM)GetFSMState() int {
40+
return this.State[this.CurrentState]
41+
}
42+
43+
func (this *FSM)InitFSM() {
44+
this = NewFSM(this.State)
45+
}

network/initNet.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const (
77
TCP = "tcp"
88
UDP = "udp"
99
KCP = "kcp"
10+
NCN = "ncn"
1011
)
1112

1213
func InitNet( netty string ) interface{} {
@@ -17,6 +18,7 @@ func InitNet( netty string ) interface{} {
1718
case KCP:
1819
case TCP:
1920
case UDP:
21+
case NCN:
2022
default:
2123
}
2224
return nil

0 commit comments

Comments
 (0)