34 lines
654 B
Go
34 lines
654 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"gitlab.wow.st/gmp/tile/state"
|
||
|
)
|
||
|
|
||
|
type Thing struct {
|
||
|
*state.StateMachine
|
||
|
val int
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
fmt.Println("Creating state machine.")
|
||
|
s := state.NewStateMachine("Start")
|
||
|
|
||
|
s.Arc("Start", "Thinking", func() {fmt.Println("Starting to Think")})
|
||
|
s.Arc("Thinking", "Start")
|
||
|
s.Arc("Thinking", "Done", func() {fmt.Println("Going to Done")})
|
||
|
|
||
|
fmt.Println("Sending Done")
|
||
|
s.State <-"Thinking"
|
||
|
s.State <-"Start"
|
||
|
s.State <-"Thinking"
|
||
|
s.State <-"Done"
|
||
|
fmt.Println("Finished.")
|
||
|
|
||
|
t := &Thing{}
|
||
|
t.StateMachine = state.NewStateMachine("Start")
|
||
|
t.Arc("Start","End",func() {fmt.Println("Hi!")})
|
||
|
t.State <- "End"
|
||
|
}
|
||
|
|